{ "info": { "author": "Alex Willmer", "author_email": "alex@moreati.org.uk", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Documentation", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Testing" ], "description": "pretext\n=======\n\n.. image:: https://travis-ci.org/moreati/b-prefix-all-the-doctests.svg\n :target: https://travis-ci.org/moreati/b-prefix-all-the-doctests\n\nThis package makes it easy to write doctests that involve strings, and\nstill have those doctests work with Python 2.6, 2.7, and 3.3+.\n\nJust `import pretext` and call `pretext.activate()`. By default Python 3.x\n`repr()` behaviour is used\n\n.. code:: python\n\n >>> import pretext; pretext.activate()\n >>> b'Now strings have a consistant repr on Python 2.x & 3.x'\n b'Now strings have a consistant repr on all Python versions'\n >>> u'Unicode strings & nested strings work too'.split()\n ['Unicode', 'strings', '&', 'nested', 'strings', 'work', 'too']\n\nThe problem\n-----------\n\nSuppose you have the following doctest, and you aren't using pretext\n\n.. code:: python\n\n >>> textfunc()\n u'I return a textual (unicode) string'\n\n >>> bytesfunc()\n b'I return a byte (binary) string'\n\nOn Python 2.x ``textfunc()`` will pass. On Python 3.x it will fail.\nThis is because doctest compares the expected value with ``repr(textfunc())``,\nand on Python 3.x the `repr()` will not include a ``u''`` prefix.\n\nOn Python 2.x ``bytesfunc()`` will fail. On Python 3.x it will pass.\nThis is because on Python 2.x ``repr(bytesfunc())`` won't include the ``b''``\nprefix.\n\nIf the tests cases are editted to remove the prefixes, i.e.\n\n.. code:: python\n\n >>> textfunc()\n 'I return a textual (unicode) string'\n\n >>> bytesfunc()\n 'I return a byte (binary) string'\n\nthen the failures will be reversed. ``textfunc()`` will now fail on Python 2.x,\n``bytesfunc()`` will fail on Python 3.x.\n\nThe hack\n--------\n\nReplace ``repr()`` and ``sys.displayhook`` with versions that always prefix\nstring literals, regardless of the Python version. Now the doctests can\n\n- directly show the string values returned by functions/methods,\n without resorting to ``print()``, or ``.encode()`` etc\n- successfully test the examples on all Python versions \n\nProof of concept:\n\n.. code:: python\n\n r\"\"\"\n >>> import sys\n >>> import pretext\n >>> myrepr = bar.PrefixRepr()\n >>> repr = myrepr.repr\n >>> def _displayhook(value):\n ... if value is not None:\n ... sys.stdout.write(myrepr.repr(value))\n >>> sys.displayhook = _displayhook\n >>> u''\n u''\n >>> b''\n b''\n >>> bytes()\n b''\n >>> b'\\0'\n b'\\x00'\n >>> b\"'\"\n b\"'\"\n \"\"\"\n\n\nAlternatives\n------------\n\nIf you're ready to run screaming at the above, there are alternatives e.g.\n\n- Wrap byte-string returns in ``bytearray()``.\n ``repr(bytearray(b'abc')) == \"bytearray(b'abc'))\"`` on all versions of\n python that have ``bytearray()`` (2.6 onward) e.g.\n\n .. code:: python\n\n >>> bytearray(bytesfunc())\n bytearray(b'I return a byte (binary) string')\n\n- Support Python 3.x exclusively\n- Use ``print(bytesfunc().decode('ascii'))`` and choose your input values carefully\n- Use ``#doctest: +SKIP``\n- Use ``#doctest: +ELLIPSIS``\n\nFor HTML or XML in a doctest `lxml`_ includes the modules\n`lxml.html.usedoctest`_ and `lxml.usedoctext`_.\n\n.. _lxml: https://pypi.python.org/pypi/lxml\n.. _lxml.html.usedoctest: http://lxml.de/api/lxml.html.usedoctest-module.html\n.. _lxml.usedoctest: http://lxml.de/api/lxml.usedoctest-module.html", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/moreati/b-prefix-all-the-doctests", "keywords": "doctest bytes unicode bytestring prefix literal string str", "license": "Apache Software License 2.0", "maintainer": null, "maintainer_email": null, "name": "pretext", "package_url": "https://pypi.org/project/pretext/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pretext/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/moreati/b-prefix-all-the-doctests" }, "release_url": "https://pypi.org/project/pretext/0.0.4/", "requires_dist": null, "requires_python": null, "summary": "Use doctest with bytes, str & unicode on Python 2.x and 3.x", "version": "0.0.4" }, "last_serial": 1952562, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "c09375325a78702cdcd3f36df5ef1fe2", "sha256": "593be0d3e16f363471349074ba86cd8986ff5e776bfcb80cddbe43050ef5795c" }, "downloads": -1, "filename": "pretext-0.0.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "c09375325a78702cdcd3f36df5ef1fe2", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 10201, "upload_time": "2015-09-22T17:48:40", "url": "https://files.pythonhosted.org/packages/6b/17/7de002331208b59bcafc579c6e32c53761e744c13d0c996072679781f116/pretext-0.0.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "14f3c736d7c1142c8918d345e7e453b8", "sha256": "3038100bfddf3a99a7f617decd59d562f9e93a2dd3cc2eae52e3a8901aacf2c6" }, "downloads": -1, "filename": "pretext-0.0.1.tar.gz", "has_sig": false, "md5_digest": "14f3c736d7c1142c8918d345e7e453b8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2935, "upload_time": "2015-09-22T17:48:35", "url": "https://files.pythonhosted.org/packages/0e/f4/e8dd68eede5823dbc9a09f892778063d7c35b1be618f05c2ea2710c8a755/pretext-0.0.1.tar.gz" } ], "0.0.2": [ { "comment_text": "", "digests": { "md5": "030688ad7cc247eb8f0e3d70bf800f68", "sha256": "be76bac3c4a659f29d78bed619a22a4d93b8743d764f2ac197d0f5343378d81c" }, "downloads": -1, "filename": "pretext-0.0.2-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "030688ad7cc247eb8f0e3d70bf800f68", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13054, "upload_time": "2015-09-24T18:21:25", "url": "https://files.pythonhosted.org/packages/31/fc/0b12ec6d512120871dcd6c0513eaf4e3afab9f89b79ec02d61c6e0121a30/pretext-0.0.2-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "5e12ce230d33f5bd8f9abbbd0c761fe7", "sha256": "ede47b012d89b2b8d068d53becb589689920afb6f2605ee66816d60243fb6cc2" }, "downloads": -1, "filename": "pretext-0.0.2.tar.gz", "has_sig": false, "md5_digest": "5e12ce230d33f5bd8f9abbbd0c761fe7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9502, "upload_time": "2015-09-24T18:21:18", "url": "https://files.pythonhosted.org/packages/59/7c/336e3137d922f427709af74919f8fd0394ee8c9b5a97d2bb6610aaf63d98/pretext-0.0.2.tar.gz" } ], "0.0.3": [ { "comment_text": "", "digests": { "md5": "e96c0f54e512e60cd395b20072017c3c", "sha256": "f1d0039537e06ecd6289ff79a2ff8e64585e4dbfdd53b96ebc4b62dd37557a23" }, "downloads": -1, "filename": "pretext-0.0.3-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "e96c0f54e512e60cd395b20072017c3c", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 15604, "upload_time": "2015-09-25T15:37:48", "url": "https://files.pythonhosted.org/packages/ff/97/eff67bd58c7e164da0147c0cc562fba35e16c627f946d0b5df2c103f6b68/pretext-0.0.3-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ff025ea3dc863ae30d96c7189fd7aa24", "sha256": "0e54e727e2bcb18b26403c376a9d15d48e21c035cfdcd10420478dc443e8c57d" }, "downloads": -1, "filename": "pretext-0.0.3.tar.gz", "has_sig": false, "md5_digest": "ff025ea3dc863ae30d96c7189fd7aa24", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10136, "upload_time": "2015-09-25T15:37:44", "url": "https://files.pythonhosted.org/packages/18/9d/71459e95ab0278f9f0a1118568af91f549b721b43bfad9055b4b90ae1084/pretext-0.0.3.tar.gz" } ], "0.0.4": [ { "comment_text": "", "digests": { "md5": "5f7ff813abdf605bb4fd15135b3ce861", "sha256": "21461c993359aa9946715ecbd8f7a0785e13e1cbe2142d2f5d1ae033f91d6264" }, "downloads": -1, "filename": "pretext-0.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5f7ff813abdf605bb4fd15135b3ce861", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 16290, "upload_time": "2016-02-12T08:43:47", "url": "https://files.pythonhosted.org/packages/f8/65/81fb591f4e4560cc65eb8c62255440d4830994eb32a6f57829b58292ed8f/pretext-0.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ff51a82d3f01c94f04544898522c9c35", "sha256": "754cce65bf9e1f245d2b2744f76e9128b41941ad174e8c5e8ec84613e99bc4c5" }, "downloads": -1, "filename": "pretext-0.0.4.tar.gz", "has_sig": false, "md5_digest": "ff51a82d3f01c94f04544898522c9c35", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11184, "upload_time": "2016-02-12T08:43:42", "url": "https://files.pythonhosted.org/packages/95/6c/e0a2fba63013ac38a086d438850d76e1a6f4fe8252a7da35ab61ec2e1c23/pretext-0.0.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5f7ff813abdf605bb4fd15135b3ce861", "sha256": "21461c993359aa9946715ecbd8f7a0785e13e1cbe2142d2f5d1ae033f91d6264" }, "downloads": -1, "filename": "pretext-0.0.4-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "5f7ff813abdf605bb4fd15135b3ce861", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 16290, "upload_time": "2016-02-12T08:43:47", "url": "https://files.pythonhosted.org/packages/f8/65/81fb591f4e4560cc65eb8c62255440d4830994eb32a6f57829b58292ed8f/pretext-0.0.4-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "ff51a82d3f01c94f04544898522c9c35", "sha256": "754cce65bf9e1f245d2b2744f76e9128b41941ad174e8c5e8ec84613e99bc4c5" }, "downloads": -1, "filename": "pretext-0.0.4.tar.gz", "has_sig": false, "md5_digest": "ff51a82d3f01c94f04544898522c9c35", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11184, "upload_time": "2016-02-12T08:43:42", "url": "https://files.pythonhosted.org/packages/95/6c/e0a2fba63013ac38a086d438850d76e1a6f4fe8252a7da35ab61ec2e1c23/pretext-0.0.4.tar.gz" } ] }