{ "info": { "author": "Andrea Corbellini", "author_email": "corbellini.andrea@gmail.com", "bugtrack_url": null, "classifiers": [], "description": "# PyStubs: dummy values for equality testing\n\nThis tiny Python module provides various types that can be used to check\nfor conditions using equality (`==`) testing. For example, to test whether\na number is less than 5:\n\n```python\n>>> from stubs import *\n>>> 2 == LessThan(5)\nTrue\n```\n\nWhich is completely equivalent to:\n\n```\n>>> 2 < 5\nTrue\n```\n\nThis approach comes in handy when comparing nested containers, such as\nJSON objects returned by an API:\n\n```python\n>>> expected_order = {\n... 'id': MatchesRegex('[0-9a-z]{10}'),\n... 'quantity': GreaterThan(10),\n... 'shippingAddress': Contains('Dublin'),\n... 'deliveryDate': ANY,\n... 'amount': InRange(200, 500),\n... 'items': Contains('apples') &\n... Contains('bananas') &\n... ~Contains('pears'),\n... }\n\n>>> expected_order == {\n... 'id': 'cxw23fac3n',\n... 'quantity': 26,\n... 'shippingAddress': '18 Some Street, Dublin, London',\n... 'deliveryDate': 'tomorrow',\n... 'amount': 300,\n... 'items': [\n... 'apples',\n... 'avocados',\n... 'bananas',\n... ],\n... }\nTrue\n\n>>> expected_order == {\n... 'id': 'XXX',\n... 'quantity': 3,\n... 'shippingAddress': '18 Some Other Street, New York City, USA',\n... 'deliveryDate': 'yesterday',\n... 'amount': 600,\n... 'items': [\n... 'apples',\n... 'pears',\n... ],\n... }\nFalse\n```\n\nThis approach can be very useful in unit testing, to make tests cases\nshorter and easier to understand.\n\n\n# Installation\n\nPyStubs has no external dependencies. To install it:\n\n```shell\n$ pip install pystubs\n```\n\n\n## List of stubs\n\n**Generics:**\n\n| Stub | Usage | Equivalent to | Notes |\n|---------------------------|-------------------------------|-------------------------------|-------------------------------------------------------------------|\n| **ANY** | `x == ANY` | `True` | |\n| **PLACEHOLDER** | `x == PLACEHOLDER` | `False` | Meant to be used as a placeholder to be replaced at a later time |\n| **AnyOf** | `x == AnyOf([...])` | `x in [...]` | |\n| **NoneOf** | `x == NoneOf([...])` | `x not in [...]` | |\n\n**Equality:**\n\n| Stub | Usage | Equivalent to | Notes |\n|---------------------------|-------------------------------|-------------------------------|-------------------------------------------------------------------|\n| **Equal** | `x == Equal(y)` | `x == y` | Useful when combined with other stubs |\n| **NotEqual** | `x == NotEqual(y)` | `x != y` | |\n\n**Order:**\n\n| Stub | Usage | Equivalent to | Notes |\n|---------------------------|-------------------------------|-------------------------------|-------------------------------------------------------------------|\n| **LessThan** | `x == LessThan(y)` | `x < y` | |\n| **LessThanOrEqual** | `x == LessThanOrEqual(y)` | `x <= y` | |\n| **GreaterThan** | `x == GreaterThan(y)` | `x > y` | |\n| **GreaterThanOrEqual** | `x == GreaterThanOrEqual(y)` | `x >= y` | |\n| **InRange** | `x == InRange(a, b)` | `a <= x < b` | |\n\n**Containers:**\n\n| Stub | Usage | Equivalent to | Notes |\n|---------------------------|-------------------------------|-------------------------------|-------------------------------------------------------------------|\n| **Contains** | `x == Contains(y)` | `y in x` | |\n| **HasSize** | `x == HasSize(y)` | `len(x) == y` | |\n| **CountOf** | `x == CountOf(y, c)` | `x.count(y) == c` | Works on any iterable, even those that don't support `count()` |\n| **HasItems** | `x == HasItems({key: value})` | `x[key] = value` | |\n\n**Strings:**\n\nThese works on both `str` and `bytes` objects.\n\n| Stub | Usage | Equivalent to | Notes |\n|---------------------------|-------------------------------|-------------------------------|-------------------------------------------------------------------|\n| **StartsWith** | `x == StartsWith(y)` | `x.startswith(y)` | |\n| **EndsWith** | `x == EndsWith(y)` | `x.endswith(y)` | |\n| **MatchesRegex** | `x == MatchesRegex(p)` | `re.match(p, x) is not None` | |\n| **ContainsRegex** | `x == ContainsRegex(p)` | `re.search(p, x) is not None` | |\n\n**Type and identity testing:**\n\n| Stub | Usage | Equivalent to | Notes |\n|---------------------------|-------------------------------|-------------------------------|-------------------------------------------------------------------|\n| **Is** | `x == Is(y)` | `x is y` | |\n| **IsNot** | `x == IsNot(y)` | `x is not y` | |\n| **InstanceOf** | `x == InstanceOf(type)` | `isinstance(x, type)` | |\n\n\n## Combining stubs\n\nStubs can be combined with the `|` (or), `&` (and), `^` (exclusive or) and\n`~` (not) operators. For example, the following stub expression:\n\n```python\n>>> 'apple' == HasSize(5) & Contains('a')\nTrue\n```\n\nis equivalent to the expression:\n\n```python\n>>> len('apple') == 5 and 'a' in 'apple'\nTrue\n```\n\n\n## License\n\nPyStubs is placed in the public domain. Feel free to do whatever you want with\nit and/or it's source code!", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/andreacorbellini/pystubs", "keywords": "", "license": "Public Domain", "maintainer": "", "maintainer_email": "", "name": "pystubs", "package_url": "https://pypi.org/project/pystubs/", "platform": "", "project_url": "https://pypi.org/project/pystubs/", "project_urls": { "Homepage": "https://github.com/andreacorbellini/pystubs" }, "release_url": "https://pypi.org/project/pystubs/2018.5.3/", "requires_dist": null, "requires_python": "", "summary": "Dummy values for equality testing", "version": "2018.5.3" }, "last_serial": 3838846, "releases": { "2018.5.0": [ { "comment_text": "", "digests": { "md5": "0e495195aa0b0d61959b6e7887344b30", "sha256": "ddc73dfffa1e8c34a72891f383e605617b337a77723ac35aad9e83648db1c405" }, "downloads": -1, "filename": "pystubs-2018.5.0.tar.gz", "has_sig": false, "md5_digest": "0e495195aa0b0d61959b6e7887344b30", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5008, "upload_time": "2018-05-06T16:10:32", "url": "https://files.pythonhosted.org/packages/68/ee/5c6c8e995dff82b4c32316a42945b4abe4dbbbf3269c996aa8eda2fa96d2/pystubs-2018.5.0.tar.gz" } ], "2018.5.1": [ { "comment_text": "", "digests": { "md5": "5444f75d9f91e096492ae886e6a9b9be", "sha256": "31262d32d7a962385758371081666dbbebfdc0c5d2c699267bc52ca938fef692" }, "downloads": -1, "filename": "pystubs-2018.5.1.tar.gz", "has_sig": false, "md5_digest": "5444f75d9f91e096492ae886e6a9b9be", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5095, "upload_time": "2018-05-06T16:25:37", "url": "https://files.pythonhosted.org/packages/6e/76/5c892668518c86540318f3a53636e7db94d5b9233625e3c41fdc6baac653/pystubs-2018.5.1.tar.gz" } ], "2018.5.2": [ { "comment_text": "", "digests": { "md5": "2a293cd0e2900c5531c329a7ac8ef918", "sha256": "eb9f79472469019dd214cfc2f6ec2458a4591999876ba318934a0ae31084e0c5" }, "downloads": -1, "filename": "pystubs-2018.5.2.tar.gz", "has_sig": false, "md5_digest": "2a293cd0e2900c5531c329a7ac8ef918", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5093, "upload_time": "2018-05-06T16:29:42", "url": "https://files.pythonhosted.org/packages/a4/06/c283caab39c8116f413218a248b8a85117979107a1d57a0be4e98b3284a3/pystubs-2018.5.2.tar.gz" } ], "2018.5.3": [ { "comment_text": "", "digests": { "md5": "e9d6edbaa3f6285d725775d2c2a9f837", "sha256": "dafd6a02bdf4d29f56512e6825b75e74ccd8849b93756dce1a69c6dadc243ffb" }, "downloads": -1, "filename": "pystubs-2018.5.3.tar.gz", "has_sig": false, "md5_digest": "e9d6edbaa3f6285d725775d2c2a9f837", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6035, "upload_time": "2018-05-06T16:32:09", "url": "https://files.pythonhosted.org/packages/61/73/18785f051c2c8d94fc49f19482219b063021b19de591423e5577727705e2/pystubs-2018.5.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e9d6edbaa3f6285d725775d2c2a9f837", "sha256": "dafd6a02bdf4d29f56512e6825b75e74ccd8849b93756dce1a69c6dadc243ffb" }, "downloads": -1, "filename": "pystubs-2018.5.3.tar.gz", "has_sig": false, "md5_digest": "e9d6edbaa3f6285d725775d2c2a9f837", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6035, "upload_time": "2018-05-06T16:32:09", "url": "https://files.pythonhosted.org/packages/61/73/18785f051c2c8d94fc49f19482219b063021b19de591423e5577727705e2/pystubs-2018.5.3.tar.gz" } ] }