{ "info": { "author": "Danilo de Jesus da Silva Bellini", "author_email": "danilo.bellini@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Framework :: Pytest", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Operating System :: POSIX :: Linux", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: Jython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Software Development :: Testing" ], "description": "pytest-doctest-custom\r\n=====================\r\n\r\n.. list-table::\r\n :stub-columns: 1\r\n\r\n * - Development\r\n - |travis| |coveralls|\r\n * - Last release\r\n - |v| |pyversions| |implementation|\r\n * - PyPI status\r\n - |dm| |format| |status| |l|\r\n\r\nTested on CPython 2.6+/3.2+, PyPy (2, 4 and 5), PyPy3 (2 and 5), PyPy-STM\r\n2.5.1 and Jython 2.7.0, using py.test 2.1+ (2.8.5+ for the CI service; 2.2.4+\r\nfor Jython).\r\n\r\n\r\nWhat does it do?\r\n----------------\r\n\r\nChange the display hook used by doctest to render the object representations.\r\n\r\nFor a given code with doctests, you can run::\r\n\r\n py.test --doctest-modules --doctest-repr=IPython.lib.pretty:pretty\r\n\r\nThat will run the doctest examples as usual, but the results won't be printed\r\nby calling a ``__repr__`` method directly, but by calling the given function\r\nwith the resulting value as its single parameter.\r\n\r\nTo do that, it just needs a representation formatting callable that given an\r\nobject, returns a string with its representation. It should be passed as the\r\n``--doctest-repr`` command line option addressed as ``module:object``, with\r\ndots for nested modules/objects. For built-ins like the ``ascii`` function,\r\nyou can just remove the ``module:`` prefix.\r\n\r\nYou can also use a printer callable that always returns ``None`` but\r\nwrites its result to some stream/file. In this case you should use this\r\npackage ``stdout_proxy``:\r\n\r\n.. code-block:: python\r\n\r\n # mymodule.py\r\n from pytest_doctest_custom import stdout_proxy\r\n from pprint import PrettyPrinter\r\n pp = PrettyPrinter(width=72, stream=stdout_proxy).pprint\r\n\r\nSo you can run::\r\n\r\n py.test --doctest-modules --doctest-repr=mymodule:pp\r\n\r\n\r\nCommon representation formatters/printers\r\n-----------------------------------------\r\n\r\nBe careful with the default \"printers\", you should always use the formatting\r\nmethods/functions instead of printing ones, as printer objects commonly\r\nassigns themselves to ``sys.stdout`` on initialization and the doctest runner\r\ncollects printed data by shortly mocking such stream. This package temporarily\r\nchanges the ``sys`` output/error streams while it finds the addressed\r\ncallable, but that's not enough if the module had already been imported\r\n(like ``conftest.py``). When possible, use a representation formatter callable\r\nor be explicit about the output stream for the printer callable (it should be\r\n``pytest_doctest_custom.stdout_proxy``).\r\n\r\n* *IPython \"pretty\" module* (for output, without the \"Out[#]:\" prefix)\r\n\r\nTo use this one, you need to have IPython installed on the testing\r\nenvironment (e.g. including ``ipython`` in the tox deps list). A possible\r\ntox.ini file for running toctests on a project would be:\r\n\r\n.. code-block:: ini\r\n\r\n [tox]\r\n envlist = py{35,34,27}\r\n\r\n [testenv]\r\n deps = ipython\r\n commands = py.test {posargs}\r\n\r\n [pytest]\r\n addopts = --doctest-modules\r\n --doctest-glob=test_*.rst\r\n --doctest-repr=IPython.lib.pretty:pretty\r\n --ignore setup.py\r\n\r\nYou can customize its parameters such as the ``max_width`` and\r\n``max_seq_length`` by creating a custom function for your needs, e.g. by\r\nadding this to the ``conftest.py`` module and calling py.test with\r\n``--doctest-repr=conftest:doctest_pretty``:\r\n\r\n.. code-block:: python\r\n\r\n # conftest.py\r\n from IPython.lib.pretty import pretty\r\n def doctest_pretty(value):\r\n return pretty(value, max_width=72)\r\n\r\nThis pretty printer sorts sets, frozensets and dicts (by keys), breaks lines\r\nwith fixed indentation, and has a consistent set/frozenset printing result for\r\ntesting on both Python 2 and 3 (CPython 2.7 and 3.3+). But it's not a Python\r\nstandard library, such printer needs IPython as a requirement for running\r\ntests, which comes with much more stuff, not just the pretty printer.\r\nIn CPython 2.6/3.2 you need to ensure that the IPython version is compatible\r\n(e.g. with ``deps = ipython<2`` in your ``tox.ini``).\r\n\r\nIn PyPy that representation printer shows any dict as a dictproxy (tested with\r\nIPython 5.0.0, PyPy 5.3.1) because they're all the same and the dict printer\r\ngets replaced, so a hack is required to ensure a common behavior between\r\nCPython and PyPy. You can create a ``pytest_configure`` hook in the very same\r\n``conftest.py`` either to monkeypatch to ``types.DictProxyType`` a dict\r\nderivative like ``type(\"dictproxy\", (dict,), {})`` reloading the\r\n``IPython.lib.pretty`` module afterwards, or to rebuild the\r\n``IPython.lib.pretty`` dict representation printer by assigning back its\r\n``_dict_pprinter_factory(\"{\", \"}\", dict)`` to its ``_type_pprinters[dict]``.\r\nThe same can be said about PyPy3, and its v2.4.0 is a Python 3.2, therefore it\r\nrequires ``ipython<2``.\r\n\r\nIPython isn't compatible with Jython.\r\n\r\n* *Python \"pprint\" module* (Standard Library)\r\n\r\nYou can use the ``pprint.pformat`` function directly with\r\n``--doctest-repr=ppretty:pformat``. You shouldn't directly use the ``pprint``\r\nmethod from ``pprint.PrettyPrinter`` objects unless the stream was properly\r\nset to ``stdout_proxy``.\r\n\r\nTo customize its parameters such as ``width`` and ``indent``, you can put a\r\n``PrettyPrinter`` object in your code, for example:\r\n\r\n.. code-block:: python\r\n\r\n # conftest.py\r\n import pprint\r\n doctest_pp = pprint.PrettyPrinter(width=72)\r\n\r\nTo run py.test with the ``pformat`` attribute of that ``PrettyPrinter``\r\ninstance, giving with ``--doctest-repr=conftest:doctest_pp.pformat`` shall be\r\nenough.\r\n\r\nThe standard library pretty printer sorts dicts (by keys), breaks lines with a\r\ncustom indentation size, but several containers have a result that depends on\r\nthe Python version (e.g. empty set as ``\"set()\"`` in Python 2.6 and 3 but as\r\n``set([])`` in Python 2.7, single item set as ``{item}`` in Python 3 but as\r\n``set([item])`` in Python 2). On the other hand, this is a Python standard\r\nlibrary, there's no extra requirement for tests, and behaves in PyPy/PyPy3 and\r\nJython as it does in CPython.\r\n\r\n\r\nInstalling\r\n----------\r\n\r\nYou can either use pip::\r\n\r\n pip install pytest-doctest-custom\r\n\r\nOr setup.py directly::\r\n\r\n python setup.py install\r\n\r\n\r\n----\r\n\r\nCopyright (C) 2016 Danilo de Jesus da Silva Bellini\r\n\r\n.. |travis| image::\r\n https://img.shields.io/travis/danilobellini/pytest-doctest-custom/master.svg\r\n :target: https://travis-ci.org/danilobellini/pytest-doctest-custom\r\n :alt: Travis CI builds\r\n\r\n.. |coveralls| image::\r\n https://img.shields.io/coveralls/danilobellini/pytest-doctest-custom/master.svg\r\n :target: https://coveralls.io/r/danilobellini/pytest-doctest-custom\r\n :alt: Coveralls coverage report (pytest>=2.8.0)\r\n\r\n.. |v| image::\r\n https://img.shields.io/pypi/v/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: Last stable version (PyPI)\r\n\r\n.. |pyversions| image::\r\n https://img.shields.io/pypi/pyversions/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: Python versions (PyPI)\r\n\r\n.. |implementation| image::\r\n https://img.shields.io/pypi/implementation/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: Python implementations (PyPI)\r\n\r\n.. |dm| image::\r\n https://img.shields.io/pypi/dm/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: Downloads (PyPI)\r\n\r\n.. |format| image::\r\n https://img.shields.io/pypi/format/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: Distribution format (PyPI)\r\n\r\n.. |status| image::\r\n https://img.shields.io/pypi/status/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: Project status (PyPI)\r\n\r\n.. |l| image::\r\n https://img.shields.io/pypi/l/pytest-doctest-custom.svg\r\n :target: https://pypi.python.org/pypi/pytest-doctest-custom\r\n :alt: License (PyPI)", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/danilobellini/pytest-doctest-custom", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "pytest-doctest-custom", "package_url": "https://pypi.org/project/pytest-doctest-custom/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pytest-doctest-custom/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/danilobellini/pytest-doctest-custom" }, "release_url": "https://pypi.org/project/pytest-doctest-custom/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "A py.test plugin for customizing string representations of doctest results.", "version": "1.0.0" }, "last_serial": 2265755, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "c41e5188f5612ca6ba848953c1fcb1a4", "sha256": "16c1f50eb32ae25b37d9e59c7204ae982e015c436fa453b76b4885c1d56f4739" }, "downloads": -1, "filename": "pytest_doctest_custom-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c41e5188f5612ca6ba848953c1fcb1a4", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 10025, "upload_time": "2016-07-25T13:42:50", "url": "https://files.pythonhosted.org/packages/c5/58/34391a13faa8f671ec372175989a5ccff98cbd1aa106b0be05fec8b9db60/pytest_doctest_custom-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a4efe1169b7a21a9e84970b0c66f8ba4", "sha256": "37d2e3d9666e20c0485e8c88263f58853042a9f38b22c4661870b0844d6bb34f" }, "downloads": -1, "filename": "pytest-doctest-custom-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a4efe1169b7a21a9e84970b0c66f8ba4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13850, "upload_time": "2016-07-25T13:42:44", "url": "https://files.pythonhosted.org/packages/23/e9/a73b915cd4cae9e868a9b3ba8721f95ba4f74e93afcdc30439d7361fe0fc/pytest-doctest-custom-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "fbf3aaaf988edd54d81624d410971ee4", "sha256": "68966c93d194477205f48b587c3ea454e04e971d28d140a1f68543a2c9203411" }, "downloads": -1, "filename": "pytest-doctest-custom-1.0.0.zip", "has_sig": false, "md5_digest": "fbf3aaaf988edd54d81624d410971ee4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22673, "upload_time": "2016-07-25T13:42:47", "url": "https://files.pythonhosted.org/packages/12/c6/71079469615c526f0712a013bff1b07618cc0004be3b87996910a5122b8e/pytest-doctest-custom-1.0.0.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "c41e5188f5612ca6ba848953c1fcb1a4", "sha256": "16c1f50eb32ae25b37d9e59c7204ae982e015c436fa453b76b4885c1d56f4739" }, "downloads": -1, "filename": "pytest_doctest_custom-1.0.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c41e5188f5612ca6ba848953c1fcb1a4", "packagetype": "bdist_wheel", "python_version": "3.5", "requires_python": null, "size": 10025, "upload_time": "2016-07-25T13:42:50", "url": "https://files.pythonhosted.org/packages/c5/58/34391a13faa8f671ec372175989a5ccff98cbd1aa106b0be05fec8b9db60/pytest_doctest_custom-1.0.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a4efe1169b7a21a9e84970b0c66f8ba4", "sha256": "37d2e3d9666e20c0485e8c88263f58853042a9f38b22c4661870b0844d6bb34f" }, "downloads": -1, "filename": "pytest-doctest-custom-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a4efe1169b7a21a9e84970b0c66f8ba4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13850, "upload_time": "2016-07-25T13:42:44", "url": "https://files.pythonhosted.org/packages/23/e9/a73b915cd4cae9e868a9b3ba8721f95ba4f74e93afcdc30439d7361fe0fc/pytest-doctest-custom-1.0.0.tar.gz" }, { "comment_text": "", "digests": { "md5": "fbf3aaaf988edd54d81624d410971ee4", "sha256": "68966c93d194477205f48b587c3ea454e04e971d28d140a1f68543a2c9203411" }, "downloads": -1, "filename": "pytest-doctest-custom-1.0.0.zip", "has_sig": false, "md5_digest": "fbf3aaaf988edd54d81624d410971ee4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22673, "upload_time": "2016-07-25T13:42:47", "url": "https://files.pythonhosted.org/packages/12/c6/71079469615c526f0712a013bff1b07618cc0004be3b87996910a5122b8e/pytest-doctest-custom-1.0.0.zip" } ] }