{ "info": { "author": "Michael Williamson", "author_email": "mike@zwobble.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "Precisely: better assertions for Python tests\n=============================================\n\nPrecisely allows you to write precise assertions so you only test the behaviour you're really interested in.\nThis makes it clearer to the reader what the expected behaviour is,\nand makes tests less brittle.\nThis also allows better error messages to be generated when assertions fail.\nInspired by Hamcrest_.\n\n.. _Hamcrest: http://hamcrest.org\n\nFor instance, suppose we want to make sure that a ``unique`` function removes duplicates from a list.\nWe might write a test like so:\n\n.. code:: python\n\n from precisely import assert_that, contains_exactly\n\n def test_unique_removes_duplicates():\n result = unique([\"a\", \"a\", \"b\", \"a\", \"b\"])\n assert_that(result, contains_exactly(\"a\", \"b\"))\n\nThe assertion will pass so long as ``result`` contains ``\"a\"`` and ``\"b\"`` in any order,\nbut no other items.\nUnlike, say, ``assert result == [\"a\", \"b\"]``, our assertion ignores the ordering of elements.\nThis is useful when:\n\n* the ordering of the result is non-determistic, such as when using ``set``.\n\n* the ordering isn't specified in the contract of ``unique``.\n If we assert a particular ordering, then we'd be testing the implementation rather than the contract.\n\n* the ordering is specified in the contract of ``unique``,\n but the ordering is tested in a separate test case.\n\nWhen the assertion fails,\nrather than just stating the two values weren't equal,\nthe error message will describe the failure in more detail.\nFor instance, if unique has the value ``[\"a\", \"a\", \"b\"]``,\nwe'd get the failure message::\n\n Expected: iterable containing in any order:\n * 'a'\n * 'b'\n but: had extra elements:\n * 'a'\n\nInstallation\n------------\n\n::\n\n pip install precisely\n\nAPI\n---\n\nUse ``assert_that(value, matcher)`` to assert that a value satisfies a matcher.\n\nMany matchers are composed of other matchers.\nIf they are given a value instead of a matcher,\nthen that value is wrapped in ``equal_to()``.\nFor instance, ``has_attrs(name=\"bob\")`` is equivalent to ``has_attrs(name=equal_to(\"bob\"))``.\n\n* ``equal_to(value)``: matches a value if it is equal to ``value`` using ``==``.\n\n* ``has_attrs(**kwargs)``: matches a value if it has the specified attributes.\n For instance:\n\n .. code:: python\n\n assert_that(result, has_attrs(id=is_a(int), name=\"bob\"))\n\n* ``contains_exactly(*args)``: matches an iterable if it has the same elements in any order.\n For instance:\n\n .. code:: python\n\n assert_that(result, contains_exactly(\"a\", \"b\"))\n # Matches [\"a\", \"b\"] and [\"b\", \"a\"],\n # but not [\"a\", \"a\", \"b\"] nor [\"a\"] nor [\"a\", \"b\", \"c\"]\n\n* ``is_sequence(*args)``: matches an iterable if it has the same elements in the same order.\n For instance:\n\n .. code:: python\n\n assert_that(result, is_sequence(\"a\", \"b\"))\n # Matches [\"a\", \"b\"] but not [\"b\", \"a\"]\n\n* ``includes(*args)``: matches an iterable if it includes all of the elements.\n For instance:\n\n .. code:: python\n\n assert_that(result, includes(\"a\", \"b\"))\n # Matches [\"a\", \"b\"], [\"b\", \"a\"] and [\"a\", \"c\", \"b\"]\n # but not [\"a\", \"c\"] nor [\"a\"]\n\n* ``all_elements(matcher)``: matches an iterable if every element matches `matcher`.\n For instance:\n\n .. code:: python\n\n assert_that(result, all_elements(equal_to(42)))\n # Matches [42], [42, 42, 42] and []\n # but not [42, 43]\n\n* ``is_mapping(matchers)``: matches a mapping, such as a ``dict``, if it has the same keys with matching values.\n An error will be raised if the mapping is missing any keys, or has any extra keys.\n For instance:\n\n .. code:: python\n\n assert_that(result, is_mapping({\n \"a\": equal_to(1),\n \"b\": equal_to(4),\n }))\n\n* ``mapping_includes(matchers)``: matches a mapping, such as a ``dict``, if it has the same keys with matching values.\n An error will be raised if the mapping is missing any keys, but extra keys are allowed.\n For instance:\n\n .. code:: python\n\n result = {\"a\": 1, \"b\": 4, \"c\": 5}\n assert_that(result, mapping_includes({\n \"a\": equal_to(1),\n \"b\": equal_to(4),\n }))\n\n* ``anything``: matches all values.\n\n* ``is_instance(type)``: matches any value where ``isinstance(value, type)``.\n\n* ``all_of(*matchers)``: matchers a value if all sub-matchers match.\n For instance:\n\n .. code:: python\n\n assert_that(result, all_of(\n is_instance(User),\n has_attrs(name=\"bob\"),\n ))\n\n* ``any_of(*matchers)``: matchers a value if any sub-matcher matches.\n For instance:\n\n .. code:: python\n\n assert_that(result, any_of(\n equal_to(\"x=1, y=2\"),\n equal_to(\"y=2, x=1\"),\n ))\n\n* ``not_(matcher)``: negates a matcher.\n For instance:\n\n .. code:: python\n\n assert_that(result, not_(equal_to(\"hello\")))\n\n* ``starts_with(prefix)``: matches a string if it starts with ``prefix``.\n\n* ``contains_string(substring)``: matches a string if it contains ``substring``.\n\n* ``greater_than(value)``: matches values greater than ``value``.\n\n* ``greater_than_or_equal_to(value)``: matches values greater than or equal to ``value``.\n\n* ``less_than(value)``: matches values less than ``value``.\n\n* ``less_than_or_equal_to(value)``: matches values less than or equal to ``value``.\n\n* ``close_to(value, delta)``: matches values close to ``value`` within a tolerance of +/- ``delta``.\n\n* ``has_feature(name, extract, matcher)``: matches ``value`` if ``extract(value)`` matches ``matcher``.\n For instance:\n\n .. code:: python\n\n assert_that(result, has_feature(\"len\", len, equal_to(2)))\n\n For clarity, it often helps to extract the use of ``has_feature`` into its own function:\n\n .. code:: python\n\n def has_len(matcher):\n return has_feature(\"len\", len, matcher)\n\n assert_that(result, has_len(equal_to(2)))\n\n* ``raises(matcher)``: matches ``value`` if ``value()`` raises an exception matched by ``matcher``.\n For instance:\n\n .. code:: python\n\n assert_that(lambda: func(\"arg\"), raises(is_instance(ValueError)))\n\nAlternatives\n------------\n\nPyHamcrest is another Python implemention of matchers. I prefer the error\nmessages that this project produces, but feel free to judge for yourself:\n\n.. code:: python\n\n # Precisely\n from precisely import assert_that, is_sequence, has_attrs\n\n assert_that(\n [\n User(\"bob\", \"jim@example.com\"),\n User(\"jim\", \"bob@example.com\"),\n ],\n is_sequence(\n has_attrs(username=\"bob\", email_address=\"bob@example.com\"),\n has_attrs(username=\"jim\", email_address=\"jim@example.com\"),\n )\n )\n\n # Expected: iterable containing in order:\n # 0: attributes:\n # * username: 'bob'\n # * email_address: 'bob@example.com'\n # 1: attributes:\n # * username: 'jim'\n # * email_address: 'jim@example.com'\n # but: element at index 0 mismatched:\n # * attribute email_address: was 'jim@example.com'\n\n # Hamcrest\n from hamcrest import assert_that, contains, has_properties\n\n assert_that(\n [\n User(\"bob\", \"jim@example.com\"),\n User(\"jim\", \"bob@example.com\"),\n ],\n contains(\n has_properties(username=\"bob\", email_address=\"bob@example.com\"),\n has_properties(username=\"jim\", email_address=\"jim@example.com\"),\n )\n )\n\n # Hamcrest error:\n # Expected: a sequence containing [(an object with a property 'username' matching 'bob' and an object with a property 'email_address' matching 'bob@example.com'), (an object with a property 'username' matching 'jim' and an object with a property 'email_address' matching 'jim@example.com')]\n # but: item 0: an object with a property 'email_address' matching 'bob@example.com' property 'email_address' was 'jim@example.com'\n", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/mwilliamson/python-precisely", "keywords": "matcher matchers", "license": "", "maintainer": "", "maintainer_email": "", "name": "precisely", "package_url": "https://pypi.org/project/precisely/", "platform": "", "project_url": "https://pypi.org/project/precisely/", "project_urls": { "Homepage": "http://github.com/mwilliamson/python-precisely" }, "release_url": "https://pypi.org/project/precisely/0.1.8/", "requires_dist": null, "requires_python": "", "summary": "Rich matchers, useful for assertions in tests. Inspired by Hamcrest.", "version": "0.1.8" }, "last_serial": 5908211, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "bf99eb399c6b4e310a14b93dfaa67676", "sha256": "c3b16befc9db547a89b8d5b3b0186ae7ed95d0ef3a7830faa78c563732e741cd" }, "downloads": -1, "filename": "precisely-0.1.0.tar.gz", "has_sig": false, "md5_digest": "bf99eb399c6b4e310a14b93dfaa67676", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5333, "upload_time": "2016-12-27T11:30:30", "url": "https://files.pythonhosted.org/packages/b1/9b/945680710cb9dc3c59623d13d7bb7fe6e54ef99d64435d9ce6f8c9a185e5/precisely-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "a6e2c6096e7480799340d99e0efd72db", "sha256": "edff20d2efbf8cdcb4424cbddaa00a78b9a611d821aefbd7ecdde75668f3e628" }, "downloads": -1, "filename": "precisely-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a6e2c6096e7480799340d99e0efd72db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5537, "upload_time": "2016-12-27T14:03:23", "url": "https://files.pythonhosted.org/packages/ac/01/167b88a15fc0b7cbeabc438b8b774fda876ed1d29abe25ce89f0df7a2fd3/precisely-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "4a22b2d728d74d28adc1e6fca09f1dd2", "sha256": "d5d7899a816250a3390174e6449a3c20b9184a6af2fd5480ff904418cb4ee7d5" }, "downloads": -1, "filename": "precisely-0.1.2.tar.gz", "has_sig": false, "md5_digest": "4a22b2d728d74d28adc1e6fca09f1dd2", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5680, "upload_time": "2016-12-27T19:44:56", "url": "https://files.pythonhosted.org/packages/e1/2c/c1500cd3f3e5c75b892686fc1812e43667cf99cc07df5738ee8507247e99/precisely-0.1.2.tar.gz" } ], "0.1.3": [ { "comment_text": "", "digests": { "md5": "1160fc528720247988292eb645de5e90", "sha256": "e2eded73dca527a8ac00a299c5b87f5961c257985e911d0dfd03cc9f17215d26" }, "downloads": -1, "filename": "precisely-0.1.3.tar.gz", "has_sig": false, "md5_digest": "1160fc528720247988292eb645de5e90", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5734, "upload_time": "2017-02-19T21:25:58", "url": "https://files.pythonhosted.org/packages/aa/c8/c551b6d1b23970d855636960a474a0199b9ff94c1cca2391ef31fba54f9b/precisely-0.1.3.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "df5abd85ea47a2b90d4aac351c646962", "sha256": "68ade2f4e8c1ebd9a75ca873f65ffe16fa6634507e6b35aad2714cc464648bc5" }, "downloads": -1, "filename": "precisely-0.1.4-py2-none-any.whl", "has_sig": false, "md5_digest": "df5abd85ea47a2b90d4aac351c646962", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 10457, "upload_time": "2018-01-12T12:38:27", "url": "https://files.pythonhosted.org/packages/3c/80/84b3e814c1e18fbbbc0ace33df9f90afee1f913c08301f81a7bbec6409c1/precisely-0.1.4-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "83fb54fe00fb34579ced6654233c4b00", "sha256": "ee1dc55bd473e5ecce62035c26ed2e0177cbc2ea5295096d254ddcc9e4a52c1a" }, "downloads": -1, "filename": "precisely-0.1.4.tar.gz", "has_sig": false, "md5_digest": "83fb54fe00fb34579ced6654233c4b00", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5783, "upload_time": "2018-01-12T12:38:26", "url": "https://files.pythonhosted.org/packages/7d/fe/2cf579206486dba831d09556f287d8a7915a27cbee01d0606108b24b243f/precisely-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "db1605fe945b5545ebbbf33548644178", "sha256": "272359fdb8a329cb970b759ca36c04f79850f87aed3c6731afb6c457c8a0d69d" }, "downloads": -1, "filename": "precisely-0.1.5-py2-none-any.whl", "has_sig": false, "md5_digest": "db1605fe945b5545ebbbf33548644178", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 12516, "upload_time": "2018-06-28T15:00:43", "url": "https://files.pythonhosted.org/packages/3d/d4/cd69350eaa7173b6ff16e987858fcb5f3f5b18d82afd5b2370309e36bd41/precisely-0.1.5-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "003ca8d1e6b01855d9e3fccf84b9e903", "sha256": "6d0081c4c6816df996369d0ba8a4916b2db2bbdcb06b923647bef71e6c6e9026" }, "downloads": -1, "filename": "precisely-0.1.5.tar.gz", "has_sig": false, "md5_digest": "003ca8d1e6b01855d9e3fccf84b9e903", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6958, "upload_time": "2018-06-28T15:00:41", "url": "https://files.pythonhosted.org/packages/e7/44/f9328689d80965aa8a8064a3b6991a0eb61349cc9f2618b56812153111f9/precisely-0.1.5.tar.gz" } ], "0.1.6": [ { "comment_text": "", "digests": { "md5": "d352f6b71ec1d2e45fcc452fe79a9aee", "sha256": "87d6b7ce8ce607b8d5d4630e279a22c92a5849c4b3702a88c451103c10affde3" }, "downloads": -1, "filename": "precisely-0.1.6-py2-none-any.whl", "has_sig": false, "md5_digest": "d352f6b71ec1d2e45fcc452fe79a9aee", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13018, "upload_time": "2018-11-21T21:21:04", "url": "https://files.pythonhosted.org/packages/d3/20/51b3d01d88be3c931571e3926bdcd5c04af5086ba0314c37af1b62912b2b/precisely-0.1.6-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "894778cc005314d5e80920213ca680f4", "sha256": "7ebb69d6b0c772c248a25f20214b4d35dd4231dca9697d3bc92e45d22da599c8" }, "downloads": -1, "filename": "precisely-0.1.6.tar.gz", "has_sig": false, "md5_digest": "894778cc005314d5e80920213ca680f4", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7490, "upload_time": "2018-11-21T21:21:02", "url": "https://files.pythonhosted.org/packages/7b/80/5c641923b2648391778dd85eb61dec18195143bee3f7374e88ba095d924c/precisely-0.1.6.tar.gz" } ], "0.1.7": [ { "comment_text": "", "digests": { "md5": "cb7817b61d479822aae7de2dbe4a419e", "sha256": "8fe7a54e6de69a9f91b913a629bdfc4fd48eeacf46fba8d5419615b020a98946" }, "downloads": -1, "filename": "precisely-0.1.7-py3-none-any.whl", "has_sig": false, "md5_digest": "cb7817b61d479822aae7de2dbe4a419e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11500, "upload_time": "2019-04-20T14:17:53", "url": "https://files.pythonhosted.org/packages/1a/3e/f0db5c2d4f43ac4f3736445806543852078f3eac60a4470ba4080b6db990/precisely-0.1.7-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0351e726d237a18ecc5876b860b4658d", "sha256": "39ebe2854ed4748c7c0301d8d0e40bb95b8e0fa20323a045cef39547c42a1042" }, "downloads": -1, "filename": "precisely-0.1.7.tar.gz", "has_sig": false, "md5_digest": "0351e726d237a18ecc5876b860b4658d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9078, "upload_time": "2019-04-20T14:17:55", "url": "https://files.pythonhosted.org/packages/e6/a8/768bbe89a7a36823eb75b23e92c3e381457f6918caa9788221f382372909/precisely-0.1.7.tar.gz" } ], "0.1.8": [ { "comment_text": "", "digests": { "md5": "2dccb3f68b366732d47319c6c30ef4e3", "sha256": "80fd34bfeb4f1780cc6554e0728c458f536e1c70c8a4394bf21175e2d0d3e90e" }, "downloads": -1, "filename": "precisely-0.1.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2dccb3f68b366732d47319c6c30ef4e3", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13946, "upload_time": "2019-09-30T17:57:04", "url": "https://files.pythonhosted.org/packages/87/f0/1805f09e2d24268aa6b491439e5888b705c09a73d434daf324739b00135b/precisely-0.1.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f447da884c72f796476b445bd0f3cc68", "sha256": "187155d05960438361f5f20cd2743ec98572ccc18ff7baa737963496b31b3421" }, "downloads": -1, "filename": "precisely-0.1.8.tar.gz", "has_sig": false, "md5_digest": "f447da884c72f796476b445bd0f3cc68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7980, "upload_time": "2019-09-30T17:57:01", "url": "https://files.pythonhosted.org/packages/0a/59/e09f04d6451262f623f89d6ed0985fb24b61dcff7f9cac14c71b7e6fae53/precisely-0.1.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "2dccb3f68b366732d47319c6c30ef4e3", "sha256": "80fd34bfeb4f1780cc6554e0728c458f536e1c70c8a4394bf21175e2d0d3e90e" }, "downloads": -1, "filename": "precisely-0.1.8-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "2dccb3f68b366732d47319c6c30ef4e3", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13946, "upload_time": "2019-09-30T17:57:04", "url": "https://files.pythonhosted.org/packages/87/f0/1805f09e2d24268aa6b491439e5888b705c09a73d434daf324739b00135b/precisely-0.1.8-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "f447da884c72f796476b445bd0f3cc68", "sha256": "187155d05960438361f5f20cd2743ec98572ccc18ff7baa737963496b31b3421" }, "downloads": -1, "filename": "precisely-0.1.8.tar.gz", "has_sig": false, "md5_digest": "f447da884c72f796476b445bd0f3cc68", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7980, "upload_time": "2019-09-30T17:57:01", "url": "https://files.pythonhosted.org/packages/0a/59/e09f04d6451262f623f89d6ed0985fb24b61dcff7f9cac14c71b7e6fae53/precisely-0.1.8.tar.gz" } ] }