{ "info": { "author": "Thomas Lotze", "author_email": "thomas@thomas-lotze.de", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: Zope Public License", "Programming Language :: Python", "Topic :: Software Development :: Testing" ], "description": "===========================\r\nThe tl.testing distribution\r\n===========================\r\n\r\nThis package provides various utilities that can be used when writing tests.\r\nIt is compatible to Python versions 2.6 and 2.7.\r\n\r\n\r\nSandboxes of directories and files\r\n==================================\r\n\r\nWhen testing code that modifies directories and files, it is useful to be able\r\nto create and inspect a sample tree of directories and files easily. The\r\n``tl.testing.fs`` module provides support for creating a tree from a textual\r\ndescription, listing it in the same format and clean up after itself.\r\n\r\nIn a doc test, these facilities might be used like this to create and list a\r\ndirectory, a file and a symbolic link:\r\n\r\n>>> from tl.testing.fs import new_sandbox, ls\r\n>>> new_sandbox(\"\"\"\\\r\n... d foo\r\n... f foo/bar asdf\r\n... l baz -> foo/bar\r\n... \"\"\")\r\n\r\n>>> ls()\r\nl baz -> foo/bar\r\nd foo\r\nf foo/bar asdf\r\n\r\nSee the file ``fs.txt`` found with the source code for further advice,\r\nincluding how to set up and tear down tests using file-system sandboxes.\r\n\r\n\r\nInstalling callable scripts\r\n===========================\r\n\r\nSome functionality one might want to test makes use of external programs such\r\nas a pager or a text editor. The ``tl.testing.script`` module provides\r\nutilities that install simple mock scripts in places where the code to be\r\ntested will find them. They take a string of Python code and create a wrapper\r\nscript that sets the Python path to match that of the test and runs the code.\r\n\r\nThis is how such a mock script might be used in a doc test:\r\n\r\n>>> from tl.testing.script import install\r\n>>> script_path = install(\"print 'A simple script.'\")\r\n>>> print open(script_path).read()\r\n#!...\r\n\r\nimport sys\r\nsys.path[:] = [...]\r\n\r\nprint 'A simple script.'\r\n\r\n>>> import subprocess\r\n>>> sub = subprocess.Popen(script_path, shell=True, stdout=subprocess.PIPE)\r\n>>> stdout, stderr = sub.communicate()\r\n>>> print stdout\r\nA simple script.\r\n\r\nSee the file ``script.txt`` found with the source code for further\r\npossibilities how to install and access mock scripts as well as how to tear\r\ndown tests using mock scripts.\r\n\r\n\r\nDoc-testing the graphical content of cairo surfaces\r\n===================================================\r\n\r\nWhile it is straight-forward to compare the content of two `cairo`_ surfaces\r\nin Python code, handling graphics is beyond doc tests. However, the `manuel`_\r\npackage can be used to extract more general test cases from a text document\r\nwhile allowing to mix them with doc tests in a natural way.\r\n\r\n.. _cairo: http://cairographics.org/pycairo/\r\n\r\n.. _manuel: http://pypi.python.org/pypi/manuel\r\n\r\nThe ``tl.testing.cairo`` module provides a test suite factory that uses manuel\r\nto execute graphical tests formulated as restructured-text figures. The\r\ncaption of such a figure is supposed to be a literal Python expression whose\r\nvalue is a cairo surface, and its image is used as the test expectation.\r\n\r\nThis is how a surface might be compared to an expected image in a doc test:\r\n\r\n::\r\n\r\n >>> import cairo\r\n >>> from pkg_resources import resource_filename\r\n\r\n >>> image = resource_filename('tl.testing', 'testimages/correct.png')\r\n\r\n .. figure:: tl/testing/testimages/correct.png\r\n\r\n ``cairo.ImageSurface.create_from_png(image)``\r\n\r\nSee the file ``cairo.txt`` found with the source code for further advice and\r\ndocumentation of the possible test output.\r\n\r\n\r\nWorking with threads in test code\r\n=================================\r\n\r\nThe standard ``TestCase`` class doesn't collect errors and failures that\r\noccurred in other threads than the main one. The ``tl.testing.thread`` module\r\nprovides thread classes and a ``ThreadAwareTestCase`` class to allow just\r\nthat, as well as some other conveniences for tests that deal with threads:\r\npreventing expected unhandled exceptions in threads from being printed with\r\nthe test output, reporting threads left behind by a test, running code in a\r\ndaemon thread, joining threads and counting the threads started during the\r\ntest's run time:\r\n\r\n>>> import time\r\n>>> import tl.testing.thread\r\n>>> class SampleTest(tl.testing.thread.ThreadAwareTestCase):\r\n...\r\n... def test_error_in_thread_should_be_reported(self):\r\n... with tl.testing.thread.ThreadJoiner(1):\r\n... self.run_in_thread(lambda: 1/0)\r\n...\r\n... def test_active_count_should_count_only_new_threads(self):\r\n... with tl.testing.thread.ThreadJoiner(1):\r\n... self.run_in_thread(lambda: time.sleep(0.1))\r\n... self.assertEqual(1, self.active_count())\r\n... self.assertEqual(0, self.active_count())\r\n\r\n>>> import unittest\r\n>>> run(unittest.makeSuite(SampleTest))\r\n======================================================================\r\nERROR: test_error_in_thread_should_be_reported (__builtin__.SampleTest)\r\n----------------------------------------------------------------------\r\nTraceback (most recent call last):\r\n ...\r\nZeroDivisionError: integer division or modulo by zero\r\n----------------------------------------------------------------------\r\nRan 2 tests in N.NNNs\r\nFAILED (errors=1)\r\n\r\nSee the file ``thread.txt`` found with the source code for further details of\r\nthe ``ThreadAwareTestCase`` class.\r\n\r\n\r\nConstructing test suites that use manuel\r\n========================================\r\n\r\nAs ``manuel`` provides some powerful features in addition to standard\r\ndoctests, manuel test suites are set up slightly differently from standard\r\nones. The ``tl.testing.doctest`` module implements a ``DocFileSuite`` factory\r\nthat can be used like the standard one but creates a test suite using manuel\r\nand allows some additional configuration related to manuel, among them the\r\nability to interpret footnotes that used to be done using the deprecated\r\n``zope.testing.doctest``:\r\n\r\n>>> sample_txt = write('sample.txt', \"\"\"\\\r\n... [#footnote]_\r\n... >>> x\r\n... 1\r\n...\r\n... .. [#footnote]\r\n... >>> x = 1\r\n... \"\"\")\r\n\r\n>>> from tl.testing.doctest import DocFileSuite\r\n>>> run(DocFileSuite(sample_txt, footnotes=True))\r\n----------------------------------------------------------------------\r\nRan 1 test in N.NNNs\r\nOK\r\n\r\n>>> sample_txt = write('sample.txt', \"\"\"\\\r\n... .. code-block:: python\r\n... x = 1\r\n...\r\n... >>> x\r\n... 1\r\n... \"\"\")\r\n\r\n>>> import manuel.codeblock\r\n>>> run(DocFileSuite(sample_txt, manuel=manuel.codeblock.Manuel()))\r\n----------------------------------------------------------------------\r\nRan 1 test in N.NNNs\r\nOK\r\n\r\n\r\n.. Local Variables:\r\n.. mode: rst\r\n.. End:\r\n\r\n\r\n================\r\nAbout tl.testing\r\n================\r\n\r\n:Author:\r\n `Thomas Lotze `_ \r\n\r\n:Online documentation:\r\n http://packages.python.org/tl.testing/ and\r\n http://tltesting.readthedocs.org/\r\n\r\n:PyPI page:\r\n http://pypi.python.org/pypi/tl.testing/\r\n\r\n:Issue tracker:\r\n https://bitbucket.org/tlotze/tl.testing/issues/\r\n\r\n:Source code:\r\n https://bitbucket.org/tlotze/tl.testing/\r\n\r\n:Current change log:\r\n https://bitbucket.org/tlotze/tl.testing/raw/tip/CHANGES.txt\r\n\r\n:Support the project:\r\n .. image:: flattr-badge-large.png\r\n :alt: Flattr this\r\n :target:\r\n http://flattr.com/thing/453077/tl-testing-assorted-tools-for-testing-in-Python\r\n\r\n.. Local Variables:\r\n.. mode: rst\r\n.. End:", "description_content_type": null, "docs_url": "https://pythonhosted.org/tl.testing/", "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/tlotze/tl.testing/", "keywords": "testing unittest doctest file directory tree sandbox helper ls mkdir mock script manuel cairo graphics image thread", "license": "ZPL 2.1", "maintainer": "", "maintainer_email": "", "name": "tl.testing", "package_url": "https://pypi.org/project/tl.testing/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/tl.testing/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/tlotze/tl.testing/" }, "release_url": "https://pypi.org/project/tl.testing/0.5/", "requires_dist": null, "requires_python": null, "summary": "Utilities for writing tests: sandbox directories, mock external programs, graphical doc-tests for cairo surfaces, error handling in threads.", "version": "0.5" }, "last_serial": 800761, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "0205760b4eb13302e1ce54a42f420ee3", "sha256": "7c8c367f0bbc612139c5b701ba8e029574a7e0a72cdbbeec4e4ed26e9571f247" }, "downloads": -1, "filename": "tl.testing-0.1.tar.gz", "has_sig": true, "md5_digest": "0205760b4eb13302e1ce54a42f420ee3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8426, "upload_time": "2008-11-11T16:33:09", "url": "https://files.pythonhosted.org/packages/07/34/83c778be6f556442e7b3faba86199d400b477f706f0a1c96421f756410f1/tl.testing-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "dc387ff7e24674ed171fd4034bb910b1", "sha256": "42e3055fa0722e2407e48f8c2ab8a81712ded01deb3f602802ac172830468313" }, "downloads": -1, "filename": "tl.testing-0.2.tar.gz", "has_sig": true, "md5_digest": "dc387ff7e24674ed171fd4034bb910b1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31670, "upload_time": "2009-05-15T19:18:45", "url": "https://files.pythonhosted.org/packages/87/5a/2845f237ebf9428e8099138eced7a88aa9e724701ce6109dcaa205485caf/tl.testing-0.2.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "aa4441d08e81f78e3a0801d11dc129e2", "sha256": "a7a0b7437e65dcc0b9a6377d093a3f0c602acf0ea060eb2ec07e18555c30d767" }, "downloads": -1, "filename": "tl.testing-0.2.1.tar.gz", "has_sig": true, "md5_digest": "aa4441d08e81f78e3a0801d11dc129e2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 31680, "upload_time": "2009-06-09T23:00:51", "url": "https://files.pythonhosted.org/packages/b7/f0/7df3a3bac0f847e8897b9b8e91a574247e1dac5f03718559e22a6e61ac13/tl.testing-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "7961317f2ed089fb93d77c43a535d528", "sha256": "3e09f4f367346a4708f45b69840a55da880131d33a94f984194a9ca942e4a918" }, "downloads": -1, "filename": "tl.testing-0.2.2.tar.gz", "has_sig": true, "md5_digest": "7961317f2ed089fb93d77c43a535d528", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 32099, "upload_time": "2009-06-24T23:39:23", "url": "https://files.pythonhosted.org/packages/f3/3e/be08ae1a0b73db3435595aab669301dec0ca479ff836e758081c59ed9485/tl.testing-0.2.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "69acce3bbf89baf765920edeef4ed94d", "sha256": "b8c698c1f430e9dfd045399aa6bfe420f5d70cf3bad60eba91e7614d2b41fb30" }, "downloads": -1, "filename": "tl.testing-0.3.tar.gz", "has_sig": true, "md5_digest": "69acce3bbf89baf765920edeef4ed94d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 21093, "upload_time": "2009-07-23T23:47:43", "url": "https://files.pythonhosted.org/packages/0c/37/27c816d33bf2abf3762339ffa6a9881f56115ad02088b514579cce4a1018/tl.testing-0.3.tar.gz" } ], "0.4": [ { "comment_text": "", "digests": { "md5": "20c365f0526dff93339a7ca284374f7d", "sha256": "aabc7526e5d0f6af9acee3769ac1039cc574e8d13835bd195642ee4c0b3c2519" }, "downloads": -1, "filename": "tl.testing-0.4.tar.gz", "has_sig": true, "md5_digest": "20c365f0526dff93339a7ca284374f7d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23452, "upload_time": "2009-09-14T23:17:17", "url": "https://files.pythonhosted.org/packages/72/5c/aba5e9434f328a8b9123a79ccf47e4d15c8ecb1fce5a91f487cf32913c3b/tl.testing-0.4.tar.gz" } ], "0.5": [ { "comment_text": "", "digests": { "md5": "a2c0eb4e2573db4bd0b96293846897f9", "sha256": "36d2529b12d942a1f907c22b933a7e3de96cba9f3dd507cfe322d3bcd164cdf8" }, "downloads": -1, "filename": "tl.testing-0.5.tar.gz", "has_sig": true, "md5_digest": "a2c0eb4e2573db4bd0b96293846897f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34061, "upload_time": "2012-01-04T23:51:22", "url": "https://files.pythonhosted.org/packages/98/ec/12706c6c6dd9a2635857ac9a27550b38b96c1662ca5f4eae21ea3fe96804/tl.testing-0.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a2c0eb4e2573db4bd0b96293846897f9", "sha256": "36d2529b12d942a1f907c22b933a7e3de96cba9f3dd507cfe322d3bcd164cdf8" }, "downloads": -1, "filename": "tl.testing-0.5.tar.gz", "has_sig": true, "md5_digest": "a2c0eb4e2573db4bd0b96293846897f9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 34061, "upload_time": "2012-01-04T23:51:22", "url": "https://files.pythonhosted.org/packages/98/ec/12706c6c6dd9a2635857ac9a27550b38b96c1662ca5f4eae21ea3fe96804/tl.testing-0.5.tar.gz" } ] }