{ "info": { "author": "Yan Wenjun", "author_email": "mylastnameisyan@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Topic :: Software Development :: Libraries" ], "description": "python better assertion.\r\n========================\r\n\r\ninspired by should.js and chai.js\r\n\r\nhttp://the-py.github.io/the/\r\n\r\n|Build Status| tested on python2.7, 3.2, 3.3\r\n\r\ninstall\r\n=======\r\n\r\n.. code:: shell\r\n\r\n pip install the\r\n\r\nAPI\r\n===\r\n\r\nIt provides one object called ``the`` with an alias ``expect``. (Take a\r\nlook at the Usage and Example.)\r\n\r\n.. code:: python\r\n\r\n from the import the, expect\r\n\r\nChains\r\n~~~~~~\r\n\r\n do nothing but return itself.\r\n\r\n- ``should``\r\n- ``have``\r\n- ``to``\r\n- ``when``\r\n- ``be``. Special. You can use it as a chain but it also plays as a\r\n matcher.\r\n- ``a``. Special. You can use it as a chain but it also plays as a\r\n matcher.\r\n\r\nMore chains?\r\n''''''''''''\r\n\r\n.. code:: python\r\n\r\n the.use(\"mychain\")\r\n\r\nMatchers without arg\r\n~~~~~~~~~~~~~~~~~~~~\r\n\r\n trigger a certain assertion.\r\n\r\n- ``true``. assert True\r\n- ``false``. assert False\r\n- ``none``. assert None\r\n- ``exist``. assert not None\r\n- ``ok``. assert Truthy\r\n- ``empty``. assert Falsy\r\n\r\nMore?\r\n'''''\r\n\r\n take a look at\r\n `the-easytype `__ lib.\r\n\r\n.. code:: python\r\n\r\n # define your matcher\r\n def happy(self):\r\n return self._check(self.obj == \"happy\",\r\n self.obj + \" is happy.\",\r\n self.obj + \" is not happy.\")\r\n\r\n # add to `the`\r\n the.use(happy)\r\n\r\n # DONE!\r\n the(string).should.be.happy\r\n\r\nMatchers with args\r\n~~~~~~~~~~~~~~~~~~\r\n\r\n trigger a certain assertion\r\n\r\n- ``eq(other)``, ``equal(other)``. assert equal(==) @param: other\r\n {mixed}\r\n\r\n- ``lt(other)``, ``below(other)``. assert less than(<) @param: other\r\n {mixed}\r\n\r\n- ``gt(other)``, ``above(other)``. assert greater than(<) @param: other\r\n {mixed}\r\n\r\n- ``ne(other)``. assert not equal(!=) @param: other {mixed}\r\n\r\n- ``le(other)``. assert less than or equal to (>=). @param: other\r\n {mixed}\r\n\r\n- ``ge(other)``. assert greater than(>=). @param: other {mixed}\r\n\r\n- ``match(regex)``. assert string match a regex. @param: regex {mixed}\r\n\r\n- ``length(n)``, ``size(n)``. assert length. @param: n {int}\r\n\r\n- ``item(**kwargs)``, ``items(**kwargs)``. assert dict have item(s).\r\n @params: \\*\\*kwargs\r\n\r\n- ``contain(other)``. assert a dict contains another dict. @param:\r\n other {dict}\r\n\r\n- ``key(*args)``, ``keys(*args)``. assert dict has key(s). @params:\r\n args\r\n\r\n- ``value(*args)``, ``values(*args)``. assert dict has value(s).\r\n @params: args\r\n\r\n- ``property(**kwargs)``, ``properties(**kwargs)``. assert object has\r\n property/properties. @params: args\r\n\r\n- ``include(item)``. assert container include item (in). @param: item\r\n {mixed}\r\n\r\n- ``within(container)``. assert item in container (in). @param:\r\n container {mixed}\r\n\r\n- ``inherit(parent)``. assert subclass. @param: parent {class}\r\n\r\n- ``method(m)``. assert object has method. @param: m {str}\r\n\r\n- ``result(r)``. assert function return value. Using ``apply`` to apply\r\n args @param: r {mixed}\r\n\r\n- ``throw(msg=None, ex=Exception)`` . assert function throw exception\r\n using ``apply`` to apply args @param: msg {regex} optional @param: ex\r\n {exception} optional\r\n\r\n- ``be(other)``. assert ``is``. (It can also be used as a chain)\r\n @param: other {mixed}.\r\n\r\n- ``a(cls)`` . assert ``isinstance`` . (It can also be used as a chain)\r\n @param: cls {class}\r\n\r\n- ``exception(msg=None, ex=Exception)`` assert exception throw\r\n **classmethod** @param: msg {regex} optional @param: ex {exception}\r\n optional\r\n\r\nMore?\r\n'''''\r\n\r\n take a look at `the-fs `__ lib.\r\n\r\n.. code:: python\r\n\r\n # define your matcher\r\n def firstname(self, name):\r\n fname = self.obj.split()[0]\r\n return self._check(fname == name,\r\n \"The firstname of {} is {}\".format(self.obj, name),\r\n \"The firstname of {} is not {}\".format(self.obj, name))\r\n\r\n # add to `the`\r\n the.use(firstname)\r\n\r\n # DONE!\r\n expect(\"Wenjun Yan\").to.have.firstname(\"Wenjun\")\r\n\r\nMagic methods\r\n~~~~~~~~~~~~~\r\n\r\n- ``==``. e.g. ``expect(1) == 1``\r\n- ``!=``. e.g. ``expect(1) != 2``\r\n- ``>=``. e.g. ``expect(1) >= 1``\r\n- ``<=``. e.g. ``expect(2) <= 3``\r\n- ``>``. e.g. ``expect(3) > 2``\r\n- ``<``. e.g. ``expect(4) < 5``\r\n- ``in``. e.g. ``1 in the(range(1,3))``\r\n- ``[]`` . e.g. ``the(dictionary)[\"key\"] == \"value\"``\r\n\r\nNegations\r\n~~~~~~~~~\r\n\r\n- ``NOT``\r\n- ``not_to``\r\n- ``should_not``\r\n\r\nPlugin\r\n~~~~~~\r\n\r\n``use(*args, **kwags)``. use this to extend ``the`` functionality.\r\n**classmethod** @param: \\*args @param: \\*\\*kwargs ``args`` can be a\r\nstring (which will become a new chain), method(new matcher), list of arg\r\nor a dict (in this case ``the`` will use the key as new matcher's name.\r\nSame as ``kwargs``.). ``args`` can even be a module if it provides a\r\n``API`` variable containing all matchers and chains to export.\r\n\r\nUsage and Examples\r\n==================\r\n\r\nassert ``>``, ``<``, ``>=``, ``<=``, ``==``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n expect(1) > 0\r\n expect(1).gt(0)\r\n expect(1).above(0)\r\n\r\n expect(1) >= 0\r\n expect(1).ge(0)\r\n\r\n expect(1) < 2\r\n expect(1).lt(0)\r\n expect(1).below(0)\r\n\r\n expect(1) <= 2\r\n expect(1).le(0)\r\n\r\n expect(1) == 1\r\n expect(1).eq(1)\r\n expect(1).equal(1)\r\n\r\nassert ``True``, ``False``, ``None``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(True).should.be.true\r\n expect(True).to.be.true\r\n\r\n the(False).should.be.false\r\n expect(False).to.be.false\r\n\r\n the(None).should.be.none\r\n expect(None).to.be.none\r\n\r\nassert ``truthy``, ``falsy``\r\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(1).should.be.ok\r\n expect(1).to.be.ok\r\n\r\n the(\"\").should.be.empty\r\n expect(\"\").to.be.empty\r\n\r\nassert ``is``\r\n~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(1).should.be(1)\r\n expect(1).to.be(1)\r\n\r\nassert ``isinstance``\r\n~~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(1).should.be.an(int)\r\n expect(\"1\").to.be.a(str)\r\n\r\nassert ``issubclass``\r\n~~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(int).should.inherit(object)\r\n expect(int).to.inherit(object)\r\n\r\nassert ``in``\r\n~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(1).should.be.within(range(1,3))\r\n expect(1).to.be.within(range(1,3))\r\n\r\nassert ``len``\r\n~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(range(1, 3)).should.have.length(3)\r\n expect(range(1, 3)).to.have.length(3)\r\n\r\nassert ``regexp``\r\n~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n the(\"abc\").should.match(\"a\")\r\n expect(\"abc\").to.match(\"a\")\r\n\r\nassert ``dict.item``\r\n~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n d = {a: 1, b: 2}\r\n the(d).should.have.items(a=1, b=2)\r\n expect(d).to.have.items(a=1, b=2)\r\n expect(d)[\"a\"] == 1\r\n\r\n the(d).should.contain({\"a\": 1, \"b\": 2})\r\n expect(d).to.contain({\"a\": 1, \"b\": 2})\r\n\r\nassert ``dict.key``\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n d = {a: 1, b: 2}\r\n the(d).should.have.key(\"a\")\r\n expect(d).to.have.keys(\"a\", \"b\")\r\n\r\nassert ``dict.value``\r\n~~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n d = {a: 1, b: 2}\r\n the(d).should.have.value(1)\r\n expect(d).to.have.values(1, 2)\r\n\r\nassert ``property``\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n class A(object):\r\n def __init__(self):\r\n self.x = 1\r\n\r\n def getx(self):\r\n return self.x\r\n\r\n expect(A()).to.have.property(\"x\")\r\n expect(A()).to.have.property(x=1)\r\n\r\nassert ``method``\r\n~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n class A(object):\r\n def __init__(self):\r\n self.x = 1\r\n\r\n def getx(self):\r\n return self.x\r\n\r\n expect(A()).to.have.method(\"getx\")\r\n the(A()).should.have.method(\"getx\")\r\n\r\nassert ``function``\r\n~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n def div(a, b):\r\n return a/b\r\n\r\n expect(div).when.apply(1,2).to.have.result(1/2)\r\n expect(div).when.apply(1,0).to.throw()\r\n\r\nassert ``exception``\r\n~~~~~~~~~~~~~~~~~~~~\r\n\r\n.. code:: python\r\n\r\n with expect.exception():\r\n assert 1 == 2\r\n\r\nPlugin\r\n======\r\n\r\n- `the-fs `__ Use ``os`` to assert\r\n file system .\r\n- `the-easytype `__. Another\r\n way to assert basic types.\r\n\r\n.. |Build Status| image:: https://travis-ci.org/the-py/the.png\r\n :target: https://travis-ci.org/the-py/the", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://the-py.github.io/the", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "the", "package_url": "https://pypi.org/project/the/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/the/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://the-py.github.io/the" }, "release_url": "https://pypi.org/project/the/0.1.5/", "requires_dist": null, "requires_python": null, "summary": "rspec/should.js assertion style for python test", "version": "0.1.5" }, "last_serial": 901649, "releases": { "0.0.4": [ { "comment_text": "", "digests": { "md5": "50974ab59d45b7392470b00d28fc07fd", "sha256": "4fa7e0de1117092e4bf5fda588d7bf8c9671e77e9a1d662328666dc77c631e5f" }, "downloads": -1, "filename": "the-0.0.4.tar.gz", "has_sig": false, "md5_digest": "50974ab59d45b7392470b00d28fc07fd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6077, "upload_time": "2013-09-05T16:40:53", "url": "https://files.pythonhosted.org/packages/5a/13/549a670c515dad82c22985487292d02a8a35a57568245f3e9fa97f8399f0/the-0.0.4.tar.gz" } ], "0.1.4": [ { "comment_text": "", "digests": { "md5": "f16a39f1c25514cfcaf844d95eb8fd0e", "sha256": "0a9623b8b9921d73d37c259947beca600cc081400f78c26127e7248896c65778" }, "downloads": -1, "filename": "the-0.1.4.tar.gz", "has_sig": false, "md5_digest": "f16a39f1c25514cfcaf844d95eb8fd0e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10692, "upload_time": "2013-10-22T14:16:57", "url": "https://files.pythonhosted.org/packages/6d/7f/29f2b6cae4fd05c52672d89d227973df79788eeaf841908ed0cff08f76d6/the-0.1.4.tar.gz" } ], "0.1.5": [ { "comment_text": "", "digests": { "md5": "4293075823d8e24dd934ebcf3c677270", "sha256": "977d36224b3ee6ca2c12728bbcfb890801f1cb793e2e1a0db2e285da7fb5835b" }, "downloads": -1, "filename": "the-0.1.5.tar.gz", "has_sig": false, "md5_digest": "4293075823d8e24dd934ebcf3c677270", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10692, "upload_time": "2013-10-23T16:16:34", "url": "https://files.pythonhosted.org/packages/1e/39/f7d201c5afcccc4ed9654d0e47c57364a22fa5efd25fe9dd39d564541505/the-0.1.5.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4293075823d8e24dd934ebcf3c677270", "sha256": "977d36224b3ee6ca2c12728bbcfb890801f1cb793e2e1a0db2e285da7fb5835b" }, "downloads": -1, "filename": "the-0.1.5.tar.gz", "has_sig": false, "md5_digest": "4293075823d8e24dd934ebcf3c677270", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10692, "upload_time": "2013-10-23T16:16:34", "url": "https://files.pythonhosted.org/packages/1e/39/f7d201c5afcccc4ed9654d0e47c57364a22fa5efd25fe9dd39d564541505/the-0.1.5.tar.gz" } ] }