{ "info": { "author": "qweeze", "author_email": "qweeeze@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.7" ], "description": "## matchlib\n\n[![PyPI version](https://badge.fury.io/py/matchlib.svg)](https://badge.fury.io/py/matchlib)\n\nThis package provides a handy way to partially compare python data structures \n(typically nested lists/dictionaries).\n\n### Installation\n```bash\npip install matchlib\n```\n### Usage\n```python\nfrom matchlib import matches\n\nuser = {\n 'id': 42,\n 'name': 'John Doe',\n 'email': 'johndoe@gmail.com',\n 'posts': [\n {\n 'id': 1,\n 'text': 'some text'\n },\n {\n 'id': 2,\n 'text': 'lorem ipsum',\n 'comments': [42, 142, 242]\n }\n ]\n}\n\nassert matches(\n user,\n {\n 'id': ...,\n 'name': 'John Doe',\n 'email': 'johndoe@gmail.com',\n ...: ...\n }\n)\n```\nSame can be achieved using standard `==` operator with `matchlib.Partial` object:\n```python\nfrom matchlib import Partial\n\nassert user == Partial({\n 'id': 42,\n 'email': 'johndoe@gmail.com',\n ...: ...\n})\n```\nThe `...` \"wildcard\" could be placed at any nested level. \nLet's say we only need to check that comment `142` is present in specific post: \n```python \nassert user == Partial({\n 'posts': [\n ...,\n {\n 'id': 2,\n 'comments': [..., 142, ...],\n ...: ...\n }\n ],\n ...: ...\n})\n``` \nMatching rules are simple:\n - In __lists__ and __tuples__ `...` matches zero or more elements and order is preserved:\n ```python\n Partial([1, 2, ...]) == [1, 2, 3, 4]\n Partial([1, 2, ...]) == [1, 2]\n\n Partial([1, 2, ...]) != [0, 1, 2]\n Partial([1, 2, ...]) != [2, 1]\n ```\n - Same for the __sets__ except they are unordered:\n ```python\n Partial({1, 2, ...}) == {1, 2}\n Partial({1, 2, ...}) == {0, 1, 2, 3}\n\n Partial({1, 2, ...}) != {0, 1, 3}\n ```\n - As __dict value__ `...` matches any object:\n ```python\n Partial({'a': 1, 'b': ...}) == {'a': 1, 'b': 2}\n ```\n - As __dict key__ `...` matches any key if assosiated values match:\n ```python\n Partial({'a': 1, ...: 2}) == {'a': 2, 'b': 2}\n ``` \n - When passed as __both key and value__ matches zero or more arbitrary key-value pairs:\n ```python\n Partial({'a': 1, ...: ...}) == {'a': 1, 'b': 2, 'c': 3}\n ```\n\n### Some more hacks\n`mathchlib` provides a `Regex` object that allows to match an arbitrary string element \n(except if it is a dict key) against a regular expression.\nAlso `pytest.approx` is supported for floating-point numbers comparison:\n```python\nfrom pytest import approx\nfrom matchlib import Regex, Partial\n\naccount = {\n 'id': 1,\n 'balance': 1007.62,\n 'owner': {\n 'email': 'user42@domain.com',\n }\n}\n\nassert account == Partial({\n 'id': ...,\n 'balance': approx(1000, 0.1),\n 'owner': {\n 'email': Regex(r'\\w+@domain\\.com')\n }\n})\n```\nIf for any reason you dislike Ellipsis literal (`...`) \na `matchlib.Any` object can be used interchangeably.\n\n", "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/qweeze/matchlib", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "matchlib", "package_url": "https://pypi.org/project/matchlib/", "platform": "", "project_url": "https://pypi.org/project/matchlib/", "project_urls": { "Homepage": "https://github.com/qweeze/matchlib" }, "release_url": "https://pypi.org/project/matchlib/0.2.1/", "requires_dist": null, "requires_python": "", "summary": "A tool for partial comparison of (nested) data structures", "version": "0.2.1" }, "last_serial": 4841126, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "c69ac439dfab6ca1e4ea80cce2d9450e", "sha256": "69a776847f6f524a7d6ee31909e4d2bfc5e3b7f2ab875fa350f9743d469e1477" }, "downloads": -1, "filename": "matchlib-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "c69ac439dfab6ca1e4ea80cce2d9450e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3757, "upload_time": "2019-02-17T19:08:41", "url": "https://files.pythonhosted.org/packages/0b/ba/0bb5358258f928c7921dcb7c317b6981d3e6b9c8425dae5d5da6d2c1a599/matchlib-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "84f43b41fe5ed4d87ab3fd7ca41a6339", "sha256": "d6f16a67cf6e1021fa1532dd8e81f03ea192990b129b67191bce935c9fd413b3" }, "downloads": -1, "filename": "matchlib-0.1.0.tar.gz", "has_sig": false, "md5_digest": "84f43b41fe5ed4d87ab3fd7ca41a6339", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2700, "upload_time": "2019-02-17T19:08:43", "url": "https://files.pythonhosted.org/packages/9a/cb/26a712793911f6bb92e586d3b575f0aa628ffc1aa254a99c1161764de5fe/matchlib-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "fb7785d7e9221b23412eb31335f997b7", "sha256": "9104067e675f7f7603ea2023de49742ef99bb0af3cd852b983ccaf1f3fd10a2f" }, "downloads": -1, "filename": "matchlib-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "fb7785d7e9221b23412eb31335f997b7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 3781, "upload_time": "2019-02-17T19:20:21", "url": "https://files.pythonhosted.org/packages/f3/4b/ddabd6d6c30e35a40a0c135a0215ae8a5121557953ead5fd445a63ac6a03/matchlib-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a1d1c0c682c36a366e970382f20d18f0", "sha256": "e7cc856d3184c06e184f486abcd72705cf4ef1eedd18db4eb088e26a34460f99" }, "downloads": -1, "filename": "matchlib-0.1.1.tar.gz", "has_sig": false, "md5_digest": "a1d1c0c682c36a366e970382f20d18f0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2733, "upload_time": "2019-02-17T19:20:23", "url": "https://files.pythonhosted.org/packages/a0/11/d4c6838cf9e7a9c6e63c734bbb7cd660b6695c0728e100623ddd936685dd/matchlib-0.1.1.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "fdcc1ed175032795eccdb801b553a4b1", "sha256": "c6f1995f2778f08524ca54828a9de9ee5550cf85411c9db8913086ee496b1c90" }, "downloads": -1, "filename": "matchlib-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "fdcc1ed175032795eccdb801b553a4b1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4186, "upload_time": "2019-02-19T18:20:32", "url": "https://files.pythonhosted.org/packages/73/08/bbc858d6083313d1f01bbb2f385dff7133acd252732ecc6bbcdd42f9734a/matchlib-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "604ffa7107379e75399e03a33d17c2fe", "sha256": "43a9a1eb09cc048a8cd7f8ef44520f10ab46b676e3952d28ef8c32fba3a6a640" }, "downloads": -1, "filename": "matchlib-0.2.1.tar.gz", "has_sig": false, "md5_digest": "604ffa7107379e75399e03a33d17c2fe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3236, "upload_time": "2019-02-19T18:20:34", "url": "https://files.pythonhosted.org/packages/84/35/7c62cb07fca01c487e2b4d7491d9a7c0823208c24ef47cfa6375f38b402d/matchlib-0.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "fdcc1ed175032795eccdb801b553a4b1", "sha256": "c6f1995f2778f08524ca54828a9de9ee5550cf85411c9db8913086ee496b1c90" }, "downloads": -1, "filename": "matchlib-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "fdcc1ed175032795eccdb801b553a4b1", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 4186, "upload_time": "2019-02-19T18:20:32", "url": "https://files.pythonhosted.org/packages/73/08/bbc858d6083313d1f01bbb2f385dff7133acd252732ecc6bbcdd42f9734a/matchlib-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "604ffa7107379e75399e03a33d17c2fe", "sha256": "43a9a1eb09cc048a8cd7f8ef44520f10ab46b676e3952d28ef8c32fba3a6a640" }, "downloads": -1, "filename": "matchlib-0.2.1.tar.gz", "has_sig": false, "md5_digest": "604ffa7107379e75399e03a33d17c2fe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3236, "upload_time": "2019-02-19T18:20:34", "url": "https://files.pythonhosted.org/packages/84/35/7c62cb07fca01c487e2b4d7491d9a7c0823208c24ef47cfa6375f38b402d/matchlib-0.2.1.tar.gz" } ] }