{ "info": { "author": "Jim Fulton", "author_email": "jim@zope.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Natural Language :: English", "Operating System :: OS Independent", "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.3", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Software Development" ], "description": "=====================================================\r\nzc.customdoctests -- Use doctest with other languages\r\n=====================================================\r\n\r\ndoctest (and recently manuel) provide hooks for using custom doctest\r\nparsers. `zc.customdoctests` helps to leverage this to support other\r\nlanguages, such as JavaScript::\r\n\r\n js> function double (x) {\r\n ... return x*2;\r\n ... }\r\n js> double(2)\r\n 4\r\n\r\nAnd with `manuel `_, it\r\nfacilitates doctests that mix multiple languages, such as Python,\r\nJavaScript, and sh.\r\n\r\n.. contents::\r\n\r\n\r\nDetailed documentation\r\n======================\r\n\r\nCustom doctest parsers\r\n----------------------\r\n\r\nzc.customdoctests provides a little bit of help with creating custom\r\ndoctest parsers that work pretty muct like regular doctests, but that\r\nuse an alternate means of evaluating examples. To use it, you call\r\nzc.customdoctests.DocTestParser and pass any of the following options:\r\n\r\nps1\r\n The first-line prompt, which defaultd to ``'>>>'``.\r\n\r\n This must be a regular expression that matches exactly 3 characters.\r\n\r\n (Note that you can't override the second-line prompt.)\r\n\r\ncomment_prefix\r\n The comment prefix regular expression, which defaults to '#'.\r\n\r\ntransform\r\n A function used to transform example source, which defaults to a\r\n no-operation function.\r\n\r\nThe js module provides support for using JavaScript in doctests using\r\n`python-spidermonkey\r\n`_. It provides some\r\nexamples of defining custom doctest parsers.\r\n\r\n\r\nJavascript and Python-Spidermonkey support\r\n------------------------------------------\r\n\r\n.. This file shows some examples of using spidermonkey APIs in doctests.\r\n\r\nTo wire this up, you'd use something like::\r\n\r\n import doctest, zc.customdoctests.js\r\n\r\n test_suite = doctest.DocTestSuite(\r\n parser=zc.customdoctests.js.parser,\r\n setUp=zc.customdoctests.js.spidermonkeySetUp)\r\n\r\nOr, with manuel::\r\n\r\n test_suite = manuel.testing.TestSuite(\r\n manuel.doctest.Manuel(parser=zc.customdoctests.js.parser) +\r\n manuel.doctest.Manuel(parser=zc.customdoctests.js.eq_parser) +\r\n manuel.doctest.Manuel() +\r\n manuel.capture.Manuel(),\r\n 'spidermonkey.txt',\r\n setUp=zc.customdoctests.js.spidermonkeySetUp)\r\n\r\nNote that zc.customdoctests doesn't require spidermonkey, so you need\r\nto install spidermonkey seperately if you want to use it.\r\n\r\nAn advantage of using manuel is that you can use multiple parsers in\r\nthe same document. In the example, above, 2 javascript example\r\nsyntaxes (described below) as well as the standard doctest syntax are\r\nsupported. This document is run with manuel to allow all 3 syntaxes.\r\n\r\nFor the rest of this document, we'll show examples of JavaScript\r\ndoctests as well as helper APIs used to support JavaScript and to\r\nintegrate JavaScript and Python.\r\n\r\nJavascript doctests use a \"js>\" prompt (as used in rhino and the\r\nspidermonkey interpreter)::\r\n\r\n js> 2 +\r\n ... 'Hi world' // doctest: +ELLIPSIS\r\n u'2Hi...\r\n\r\nAssignments return values. This can generate annoying output\r\nin doctests::\r\n\r\n js> ob = {a: 1, b: 2}\r\n [object Object]\r\n\r\nIf you're using manuel, you can avoid this by using js!::\r\n\r\n js! x = 3\r\n\r\nwhich suppresses expression values.\r\n\r\nload and print functions (similar to those found in rhino) are\r\nprovided. For example, given a javascript file, double.js::\r\n\r\n function double (x) {\r\n return x*2;\r\n }\r\n\r\n.. -> src\r\n\r\n >>> with open('double.js', 'w') as f:\r\n ... f.write(src)\r\n\r\nWe can load the file::\r\n\r\n js> load('double.js')\r\n js> double(10)\r\n 20\r\n\r\nWe can print values::\r\n\r\n js> print('Hi')\r\n Hi\r\n\r\nA python object provides access to the open function and the os\r\nmodule::\r\n\r\n js> python.os.path.exists('double.js')\r\n True\r\n\r\n js! f = python.open('double.js')\r\n js> print(f.read())\r\n function double (x) {\r\n return x*2;\r\n }\r\n \r\n\r\n js> f.close()\r\n\r\n\r\nIf you're using manuel, you can intermix Python and and JavaScript\r\nexamples and there are a number of APIs to facilitate using Python and\r\nJavaScript together.\r\n\r\nThere's an add_js_global function to copy data from Python::\r\n\r\n >>> add_js_global('y', 1)\r\n\r\n js> y\r\n 1\r\n\r\nThere's also a js object that provides attribute access to js globals::\r\n\r\n >>> js.x\r\n 3\r\n\r\n >>> js.z = 4\r\n\r\n js> z\r\n 4\r\n\r\nYou can also call this to run JS code without returning the resulting value::\r\n\r\n >>> js('a = x + y')\r\n\r\n js> a\r\n 4\r\n\r\n\r\nChangelog\r\n=========\r\n\r\n1.0.1 (2013-02-14)\r\n------------------\r\n\r\n- Fixed ReStructuredText errors on the PyPI page.\r\n\r\n\r\n1.0.0 (2013-02-13)\r\n------------------\r\n\r\n- Added Python 3.3 support.\r\n\r\n- Cleanup `setup.py`, add `tox.ini` and manifest.\r\n\r\n\r\n0.1.0 (2011-05-19)\r\n------------------\r\n\r\n- Initial release", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/zc.customdoctests", "keywords": "", "license": "ZPL 2.1", "maintainer": "", "maintainer_email": "", "name": "zc.customdoctests", "package_url": "https://pypi.org/project/zc.customdoctests/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/zc.customdoctests/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/zc.customdoctests" }, "release_url": "https://pypi.org/project/zc.customdoctests/1.0.1/", "requires_dist": null, "requires_python": null, "summary": "=====================================================", "version": "1.0.1" }, "last_serial": 802169, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "78d76baa63121d4dad6d92851f9edd89", "sha256": "d2c48ec1237d8d9422f78f65c405f7e9e7722e021143c962e0e6ce675ba4c5ad" }, "downloads": -1, "filename": "zc.customdoctests-0.1.0.tar.gz", "has_sig": false, "md5_digest": "78d76baa63121d4dad6d92851f9edd89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6005, "upload_time": "2011-05-19T19:20:19", "url": "https://files.pythonhosted.org/packages/d9/eb/c3fac45533a18dd4840a52e850ccbce80dada9606b2ab9ce7f0d6b595844/zc.customdoctests-0.1.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "ab5d6f4c06edc770064c78c9aca6e1c1", "sha256": "7b84e29d4638d437f612e12748de5e2a58fec64107ab1653f3563883dacbddfc" }, "downloads": -1, "filename": "zc.customdoctests-1.0.0.tar.gz", "has_sig": false, "md5_digest": "ab5d6f4c06edc770064c78c9aca6e1c1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7843, "upload_time": "2013-02-13T19:58:26", "url": "https://files.pythonhosted.org/packages/f3/30/8004b2e22fce91c45c9ed82040bec514ee2aac13a6ebaf6fdac20d3f1c67/zc.customdoctests-1.0.0.tar.gz" } ], "1.0.1": [ { "comment_text": "", "digests": { "md5": "d7a0ea4310efa4eac5d08402ac10896e", "sha256": "ca803c76697242c8637744416b7ec4438a20941e4364411f69b85a15024444a6" }, "downloads": -1, "filename": "zc.customdoctests-1.0.1.zip", "has_sig": false, "md5_digest": "d7a0ea4310efa4eac5d08402ac10896e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15775, "upload_time": "2013-02-14T14:05:15", "url": "https://files.pythonhosted.org/packages/6a/c1/8a8476b1dd2f9ebf665c27cb2f8e00bb0c54f353c52169ffa46e9824945f/zc.customdoctests-1.0.1.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d7a0ea4310efa4eac5d08402ac10896e", "sha256": "ca803c76697242c8637744416b7ec4438a20941e4364411f69b85a15024444a6" }, "downloads": -1, "filename": "zc.customdoctests-1.0.1.zip", "has_sig": false, "md5_digest": "d7a0ea4310efa4eac5d08402ac10896e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15775, "upload_time": "2013-02-14T14:05:15", "url": "https://files.pythonhosted.org/packages/6a/c1/8a8476b1dd2f9ebf665c27cb2f8e00bb0c54f353c52169ffa46e9824945f/zc.customdoctests-1.0.1.zip" } ] }