{ "info": { "author": "Martin Thorsen Ranang", "author_email": "mtr@ranang.org", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Operating System :: POSIX", "Programming Language :: Python", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Testing" ], "description": "Any Valid\r\n=========\r\n\r\nThe AnyValid class is a wrapper class to be used with, for example,\r\n`formencode.validators `__,\r\nthat lets you partially specify what kind of objects it should match. To\r\nsee the usefulness of this, it might be easier to first have a look at\r\nmock's ANY object (`from unittest.mock's\r\ndocumentation `__):\r\n\r\n Sometimes you may need to make assertions about some of the\r\n arguments in a call to mock, but either not care about some of the\r\n arguments or want to pull them individually out of call\\_args and\r\n make more complex assertions on them.\r\n\r\n To ignore certain arguments you can pass in objects that compare\r\n equal to everything. Calls to assert\\_called\\_with() and\r\n assert\\_called\\_once\\_with() will then succeed no matter what was\r\n passed in.\r\n\r\n .. code:: python\r\n\r\n >>\r\n >> mock = Mock(return_value=None)\r\n >> mock('foo', bar=object())\r\n >> mock.assert_called_once_with('foo', bar=ANY)\r\n\r\n ANY can also be used in comparisons with call lists like\r\n mock\\_calls:\r\n\r\n .. code:: python\r\n\r\n >> \r\n >> m = MagicMock(return_value=None) \r\n >> m(1) \r\n >> m(1, 2) \r\n >> m(object()) \r\n >> m.mock_calls == [call(1), call(1, 2), ANY] \r\n True\r\n\r\nNow, what if you would like to make certain assertions about an\r\nargument, but perhaps don't know the exact value, or want to avoid\r\ncertain values (for example ``None``). This is where AnyValid might come\r\nin handy. It provides a really simple way to leverage all the great work\r\nthat has been put into formencode's validators, so that your testing\r\ncode can make advanced assertions while being easy to read and maintain.\r\n\r\nExamples\r\n========\r\n\r\nSimple argument matching:\r\n\r\n.. code:: python\r\n\r\n>>> \r\n>>> from mock import Mock \r\n>>> from any_valid import AnyValid, Int, String \r\n>>> \r\n>>> def check_call(foo, bar): \r\n... try: \r\n... mock = Mock(return_value=None) \r\n... mock(foo, bar=bar) \r\n... mock.assert_called_once_with(AnyValid(String(min_lenght=3)), \r\n... bar=AnyValid(Int(min=2))) \r\n... except AssertionError: \r\n... return False \r\n... return True \r\n... \r\n>>> check_call('fo', 1) \r\nFalse \r\n>>> check_call(8, 0) \r\nFalse \r\n>>> check_call('foo', 2) \r\nTrue\r\n\r\nMatching a loosely defined dict argument:\r\n\r\n.. code:: python\r\n\r\n>>> from any_valid import AnyValid, Number, OneOf \r\n>>> valid_input = { ... 'core_temperature': AnyValid(Number(min=35, max=41.5)), \r\n... 'protocol': AnyValid(OneOf(['https', 'http'])), \r\n... } \r\n>>> mock = Mock(return_value=None) \r\n>>> mock({'core_temperature': 36.8, 'protocol': 'https'}) \r\n>>> mock.assert_called_with(valid_input) \r\n>>>", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mtr/AnyValid", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "AnyValid", "package_url": "https://pypi.org/project/AnyValid/", "platform": "", "project_url": "https://pypi.org/project/AnyValid/", "project_urls": { "Homepage": "https://github.com/mtr/AnyValid" }, "release_url": "https://pypi.org/project/AnyValid/1.0.0/", "requires_dist": null, "requires_python": null, "summary": "Library that eases partial matching of objects.", "version": "1.0.0" }, "last_serial": 887721, "releases": { "1.0.0": [ { "comment_text": "", "digests": { "md5": "e2aa202bbc1c090a1b0473b4cc6575a5", "sha256": "53cb486804e87986de9e0e278b5a9fa6c458222625ea6c9711c7b2aefe275097" }, "downloads": -1, "filename": "AnyValid-1.0.0.tar.gz", "has_sig": false, "md5_digest": "e2aa202bbc1c090a1b0473b4cc6575a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2825, "upload_time": "2013-10-11T20:10:46", "url": "https://files.pythonhosted.org/packages/21/30/560dea258fd45b63cd64fdb0e839bc9d9b845e7861337df872c6bc317ce9/AnyValid-1.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "e2aa202bbc1c090a1b0473b4cc6575a5", "sha256": "53cb486804e87986de9e0e278b5a9fa6c458222625ea6c9711c7b2aefe275097" }, "downloads": -1, "filename": "AnyValid-1.0.0.tar.gz", "has_sig": false, "md5_digest": "e2aa202bbc1c090a1b0473b4cc6575a5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2825, "upload_time": "2013-10-11T20:10:46", "url": "https://files.pythonhosted.org/packages/21/30/560dea258fd45b63cd64fdb0e839bc9d9b845e7861337df872c6bc317ce9/AnyValid-1.0.0.tar.gz" } ] }