{ "info": { "author": "Ian Bicking", "author_email": "ianb@colorstudy.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Topic :: Software Development :: Testing" ], "description": "MiniMock\r\n========\r\n\r\n.. contents::\r\n :depth: 1\r\n\r\n-----------------------\r\nLicense & Collaboration\r\n-----------------------\r\n\r\nMiniMock is by `Ian Bicking `_ with\r\nsubstantial contributions by Mike Beachy, and is maintained by\r\nLow Kian Seong. It is licensed under an `MIT-style license\r\n`_.\r\n\r\nIt has a `github repository `_\r\nwhich you can clone with ``git clone https://github.com/lowks/minimock.git``.\r\nThere is also a `Google Group `_\r\nfor the development mailing list which can be emailed at\r\n`minimock-dev@googlegroups.com `_.\r\n\r\n------------\r\nIntroduction\r\n------------\r\n\r\nminimock is a simple library for doing Mock objects with doctest.\r\nWhen using doctest, mock objects can be very simple.\r\n\r\nHere's an example of something we might test, a simple email sender::\r\n\r\n >>> import smtplib\r\n >>> def send_email(from_addr, to_addr, subject, body):\r\n ... conn = smtplib.SMTP('localhost')\r\n ... msg = 'To: %s\\nFrom: %s\\nSubject: %s\\n\\n%s' % (\r\n ... to_addr, from_addr, subject, body)\r\n ... conn.sendmail(from_addr, [to_addr], msg)\r\n ... conn.quit()\r\n\r\nNow we want to make a mock ``smtplib.SMTP`` object. We'll have to\r\ninject our mock into the ``smtplib`` module::\r\n\r\n >>> from minimock import Mock\r\n >>> smtplib.SMTP = Mock('smtplib.SMTP')\r\n >>> smtplib.SMTP.mock_returns = Mock('smtp_connection')\r\n\r\nNow we do the test::\r\n\r\n >>> send_email('ianb@colorstudy.com', 'joe@example.com',\r\n ... 'Hi there!', 'How is it going?')\r\n Called smtplib.SMTP('localhost')\r\n Called smtp_connection.sendmail(\r\n 'ianb@colorstudy.com',\r\n ['joe@example.com'],\r\n 'To: joe@example.com\\nFrom: ianb@colorstudy.com\\nSubject: Hi there!\\n\\nHow is it going?')\r\n Called smtp_connection.quit()\r\n\r\nVoila! We've tested implicitly that no unexpected methods were called\r\non the object. We've also tested the arguments that the mock object\r\ngot. We've provided fake return calls (for the ``smtplib.SMTP()``\r\nconstructor). These are all the core parts of a mock library. The\r\nimplementation is simple because most of the work is done by doctest.\r\n\r\n-----------------\r\nControlling Mocks\r\n-----------------\r\n\r\nMock objects have several attributes, all of which you can set when\r\ninstantiating the object. To avoid name collision, all the attributes\r\nstart with ``mock_``, while the constructor arguments don't.\r\n\r\n``name``:\r\n The name of the object, used when printing out messages. In the\r\n example above it was ``'smtplib.SMTP'``.\r\n\r\n``returns``:\r\n When this object is called, it will return this value. By default\r\n it is None.\r\n\r\n``returns_iter``:\r\n Alternately, you can give an iterable of return results, like\r\n ``returns_iter=[1, 2, 3]``; on each subsequent call it will return\r\n the next value.\r\n\r\n``returns_func``:\r\n If given, this will be called to get the return value. In\r\n essence, this function will be the *real* implementation of the\r\n method.\r\n\r\n``raises``:\r\n An exception (instance or class) that will be raised when this\r\n object is called.\r\n\r\n``tracker``:\r\n An object which is notified every time the mock object is called or\r\n an attribute is set on it (assuming ``show_attrs`` is ``True``);\r\n defaults to a ``Printer`` to stdout. ``TraceTracker`` can instead be\r\n useful for non-doctest tests. Pass ``None`` to disable this behavior.\r\n\r\n``show_attrs``:\r\n If this is true, every time a new attribute is set on the mock\r\n object the tracker will be notified. Otherwise attribute sets are\r\n silent, and only calls trigger notification.\r\n\r\nSo to create an object that always raises ValueError, do::\r\n\r\n >>> dummy_module = Mock('mylibrary')\r\n >>> dummy_module.invalid_func.mock_raises = ValueError\r\n\r\n--------------\r\nCreating Mocks\r\n--------------\r\n\r\nEvery attribute of a mock object will itself be another mock object,\r\nunless you specifically set it to something else. For instance, you\r\ncan do::\r\n\r\n >>> from minimock import Mock\r\n >>> dummy_module = Mock('mylibrary')\r\n >>> dummy_module.CONSTANT = 1\r\n\r\nThen the ``CONSTANT`` value will persist. But you can also traverse\r\nto whatever object you want, and you will get another mock object.\r\n\r\nAnother technique for creating a mock object is the ``mock(...)``\r\nfunction. This works like::\r\n\r\n >>> from minimock import mock\r\n >>> import os.path\r\n >>> mock('os.path.isfile', returns=True)\r\n\r\nThis looks up the ``os.path.isfile`` object, and changes it to a mock\r\nobject. Any keyword arguments you give (like ``returns=True`` in this\r\nexample) will be used to create the mock object; you can also give a\r\n``mock_obj`` keyword argument to pass in a mock object you've already\r\ncreated.\r\n\r\nThis function looks in the calling function to figure out what to\r\nreplace (``os.path.isfile`` in the example). You must import the\r\nproper modules first. Alternately you can pass in a dictionary like\r\n``[locals(), globals()]`` for it to use for lookup.\r\n\r\nTo restore all the objects mocked with ``mock()``, use\r\n``minimock.restore()`` (with no arguments; all the mocks are kept\r\ntrack of).", "description_content_type": null, "docs_url": null, "download_url": "https://pypi.python.org/packages/source/M/MiniMock/MiniMock-1.2.8.tar.gz#md5=76593aaba949b5e010fec95283556449", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/MiniMock", "keywords": "mock testing unittest", "license": "MIT", "maintainer": "Low Kian Seong", "maintainer_email": "kianseong@gmail.com", "name": "MiniMock", "package_url": "https://pypi.org/project/MiniMock/", "platform": "", "project_url": "https://pypi.org/project/MiniMock/", "project_urls": { "Download": "https://pypi.python.org/packages/source/M/MiniMock/MiniMock-1.2.8.tar.gz#md5=76593aaba949b5e010fec95283556449", "Homepage": "http://pypi.python.org/pypi/MiniMock" }, "release_url": "https://pypi.org/project/MiniMock/1.2.8/", "requires_dist": null, "requires_python": null, "summary": "The simplest possible mock library", "version": "1.2.8" }, "last_serial": 2429912, "releases": { "0.8": [ { "comment_text": "", "digests": { "md5": "161f396c66aefa52fa31fc902d8bf59c", "sha256": "939639096ce501a2fe18317e0723000e1f505e3701dd84796f3b82afea0d1798" }, "downloads": -1, "filename": "MiniMock-0.8-py2.4.egg", "has_sig": false, "md5_digest": "161f396c66aefa52fa31fc902d8bf59c", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 9059, "upload_time": "2007-10-15T02:38:10", "url": "https://files.pythonhosted.org/packages/52/a4/308f0fdba9b7b0ddba0dfde2acb187f8fb029a2651ba53d7d196b7b5c549/MiniMock-0.8-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "f2bedae745b2247aadb1067c54df9dd1", "sha256": "d3fdc9af3012345890dfc1b79d6012f1bca98b1e2fb7431111226c734212a1ea" }, "downloads": -1, "filename": "MiniMock-0.8-py2.5.egg", "has_sig": false, "md5_digest": "f2bedae745b2247aadb1067c54df9dd1", "packagetype": "bdist_egg", "python_version": "2.5", "requires_python": null, "size": 8950, "upload_time": "2007-10-15T02:38:18", "url": "https://files.pythonhosted.org/packages/8a/e4/5560b68269d5131f08222ce3941696e941634ebe941362b4058005ed25a2/MiniMock-0.8-py2.5.egg" }, { "comment_text": "", "digests": { "md5": "ff96ba95eb88382c72dd00154ea52f00", "sha256": "a6b9d74500bdfa82627486388f2e48f4e57138d89e22b33329390043c3d2199a" }, "downloads": -1, "filename": "MiniMock-0.8.tar.gz", "has_sig": false, "md5_digest": "ff96ba95eb88382c72dd00154ea52f00", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5708, "upload_time": "2007-10-15T02:38:10", "url": "https://files.pythonhosted.org/packages/24/37/6aeb4231a18f4cf0c08d06b18242e5624c6dbc4d2d7b5ae79daf05f0ad3d/MiniMock-0.8.tar.gz" } ], "0.9": [ { "comment_text": "", "digests": { "md5": "f0f7e6bcf33c092536cbae0bef3d0cb6", "sha256": "5d863061183d03646766e7389ba85e3bb3dad91dddf090cb2e4e28b298f2fb48" }, "downloads": -1, "filename": "MiniMock-0.9.tar.gz", "has_sig": false, "md5_digest": "f0f7e6bcf33c092536cbae0bef3d0cb6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6185, "upload_time": "2008-07-18T00:54:27", "url": "https://files.pythonhosted.org/packages/ca/f7/5263e08ad5945d0351a3cda39eaaf5fd53e5afa1d60970be27ad4d852765/MiniMock-0.9.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "8483d225dbdd0036939a663ec6de396e", "sha256": "1869eabe3a6f06d5b2d8b569a282e73da13e0a4a24b6be834bef644cc2b94050" }, "downloads": -1, "filename": "MiniMock-1.0.tar.gz", "has_sig": false, "md5_digest": "8483d225dbdd0036939a663ec6de396e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6625, "upload_time": "2008-10-17T19:41:40", "url": "https://files.pythonhosted.org/packages/e0/95/44630a90579684736576f814eb7ce1d8ec6dff94a04ad424fd42d017771e/MiniMock-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "3806eb9830e6534539aaf1c5af36bf6c", "sha256": "53c3627f7283b03fe1df7ef63fe92845ae9f74a27365d49dcfb12da8790b02ac" }, "downloads": -1, "filename": "MiniMock-1.1.tar.gz", "has_sig": false, "md5_digest": "3806eb9830e6534539aaf1c5af36bf6c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7153, "upload_time": "2009-01-30T01:53:44", "url": "https://files.pythonhosted.org/packages/8f/63/cc0e87b029a6d2035e1904de73862d0c6978f236846f93e4c76d4cbc5a96/MiniMock-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "3fcc743c183a3d31064d2df7c281ec89", "sha256": "d6b2fbed00dfd503320f50e47e0dc06fcb844502f350eca16be6d2af0b5ea678" }, "downloads": -1, "filename": "MiniMock-1.2.tar.gz", "has_sig": false, "md5_digest": "3fcc743c183a3d31064d2df7c281ec89", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8153, "upload_time": "2009-03-12T23:05:47", "url": "https://files.pythonhosted.org/packages/22/7e/f8db0caad76df2ae57369d43f13251c75ac5ecfcb171fc564d0209a832e7/MiniMock-1.2.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "93d379af564e2b6823a9bc9b7af775c7", "sha256": "26e5a896f040f74c9c681d89feced340efd11711b4f337a72310826d73aecdb2" }, "downloads": -1, "filename": "MiniMock-1.2.1.tar.gz", "has_sig": false, "md5_digest": "93d379af564e2b6823a9bc9b7af775c7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8271, "upload_time": "2009-03-14T15:05:36", "url": "https://files.pythonhosted.org/packages/06/ed/7edfa998589c23bc7f59fc408e0f3e2ef04ad45528affa6af39467995522/MiniMock-1.2.1.tar.gz" } ], "1.2.2": [ { "comment_text": "", "digests": { "md5": "9dac5c14cd90456ee486a9815441aecd", "sha256": "a8f426e3117fdba2836f5e6baeeb81663906a3d2cf4ede102417391f47b265b3" }, "downloads": -1, "filename": "MiniMock-1.2.2.tar.gz", "has_sig": false, "md5_digest": "9dac5c14cd90456ee486a9815441aecd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9182, "upload_time": "2009-03-26T02:57:01", "url": "https://files.pythonhosted.org/packages/29/4e/593a77a6ba64b7fc6acd989ee6925d10491746d557d558f351930d4fb1b4/MiniMock-1.2.2.tar.gz" } ], "1.2.3": [ { "comment_text": "", "digests": { "md5": "c583f4edf60007f5747748b3ab9da631", "sha256": "d94297937f5aa54ec53f61f894d6ef73ce5c23f0a0125b753d6bbacd3427320d" }, "downloads": -1, "filename": "MiniMock-1.2.3.tar.gz", "has_sig": false, "md5_digest": "c583f4edf60007f5747748b3ab9da631", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9321, "upload_time": "2009-04-22T21:20:41", "url": "https://files.pythonhosted.org/packages/06/90/f755a709e8164750f572ea9f4e8319dddf2edbf7079469e91cd3786992d3/MiniMock-1.2.3.tar.gz" } ], "1.2.4": [ { "comment_text": "", "digests": { "md5": "726f711fca6847cb9260331c7fd1bec8", "sha256": "b84af1e97f4036135ed4c97fa869641a4b2a0903a8bff7a626be6b2757b97460" }, "downloads": -1, "filename": "MiniMock-1.2.4.tar.gz", "has_sig": false, "md5_digest": "726f711fca6847cb9260331c7fd1bec8", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8203, "upload_time": "2009-07-30T21:37:34", "url": "https://files.pythonhosted.org/packages/69/e5/c653d423ab217ae343460ee5c0759495c95b153acb55a88bdb43aa7bdcd0/MiniMock-1.2.4.tar.gz" } ], "1.2.5": [ { "comment_text": "", "digests": { "md5": "404ad9b0b2052686dee28936403aa3e7", "sha256": "4a8dd16281aad2f7f3dd0e9426d038b5b6114b3902133daa232d0e42539941c2" }, "downloads": -1, "filename": "MiniMock-1.2.5.tar.gz", "has_sig": false, "md5_digest": "404ad9b0b2052686dee28936403aa3e7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9204, "upload_time": "2009-08-07T06:52:55", "url": "https://files.pythonhosted.org/packages/28/95/bec8b5c4ec82723e9f4a0e8490f4d48dd38f73aa9cfd8a2a3dfec0c7878f/MiniMock-1.2.5.tar.gz" } ], "1.2.6": [ { "comment_text": "", "digests": { "md5": "e34e580b7a545a6a2fb3c05e9932d91e", "sha256": "f26e7d092b0071915e94bdacb018d2579d2758b88a5a66a6b1612e293f71c374" }, "downloads": -1, "filename": "MiniMock-1.2.6.tar.gz", "has_sig": false, "md5_digest": "e34e580b7a545a6a2fb3c05e9932d91e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10776, "upload_time": "2011-02-19T20:21:45", "url": "https://files.pythonhosted.org/packages/27/11/9870d652f16d43c153b9d7885d8b4f5285fa0507db0d5e8d9d05a535518b/MiniMock-1.2.6.tar.gz" } ], "1.2.7": [ { "comment_text": "", "digests": { "md5": "31e813667ed46b6990630a0f5bd62d94", "sha256": "3de5c14b986f984fa3cc113035d8b21b6c29c92d9f8b31cd34d33002e2fbb33b" }, "downloads": -1, "filename": "MiniMock-1.2.7.tar.gz", "has_sig": false, "md5_digest": "31e813667ed46b6990630a0f5bd62d94", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15118, "upload_time": "2011-08-19T17:25:11", "url": "https://files.pythonhosted.org/packages/62/f4/933c1d68a14df94fb9fcd28e87166d037e9fab0902809476fdcddd4a4af2/MiniMock-1.2.7.tar.gz" } ], "1.2.8": [ { "comment_text": "", "digests": { "md5": "d85904a41bfffe61d56d51b58fdfccaa", "sha256": "de0cb9bb71f83350acdc7228b41b23520be7466cd4fa1f467055d0f504996404" }, "downloads": -1, "filename": "MiniMock-1.2.8-py2-none-any.whl", "has_sig": false, "md5_digest": "d85904a41bfffe61d56d51b58fdfccaa", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13866, "upload_time": "2016-10-28T23:52:42", "url": "https://files.pythonhosted.org/packages/20/c2/648140031ab22b059bcbde451cd4bb638d64b9a6fd48fe7ef4f4f82d0274/MiniMock-1.2.8-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "76593aaba949b5e010fec95283556449", "sha256": "5fdfdfeadf0fc781d0592a1b90d2fcc11581f682ff7cba6201cfdb15c3ea5a4c" }, "downloads": -1, "filename": "MiniMock-1.2.8.tar.gz", "has_sig": false, "md5_digest": "76593aaba949b5e010fec95283556449", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13217, "upload_time": "2013-03-19T15:46:35", "url": "https://files.pythonhosted.org/packages/43/c8/0928c5f684d6f86fb34c12e4b6bcde2dd8b951d060f304b5e4cc4d13d106/MiniMock-1.2.8.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d85904a41bfffe61d56d51b58fdfccaa", "sha256": "de0cb9bb71f83350acdc7228b41b23520be7466cd4fa1f467055d0f504996404" }, "downloads": -1, "filename": "MiniMock-1.2.8-py2-none-any.whl", "has_sig": false, "md5_digest": "d85904a41bfffe61d56d51b58fdfccaa", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 13866, "upload_time": "2016-10-28T23:52:42", "url": "https://files.pythonhosted.org/packages/20/c2/648140031ab22b059bcbde451cd4bb638d64b9a6fd48fe7ef4f4f82d0274/MiniMock-1.2.8-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "76593aaba949b5e010fec95283556449", "sha256": "5fdfdfeadf0fc781d0592a1b90d2fcc11581f682ff7cba6201cfdb15c3ea5a4c" }, "downloads": -1, "filename": "MiniMock-1.2.8.tar.gz", "has_sig": false, "md5_digest": "76593aaba949b5e010fec95283556449", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13217, "upload_time": "2013-03-19T15:46:35", "url": "https://files.pythonhosted.org/packages/43/c8/0928c5f684d6f86fb34c12e4b6bcde2dd8b951d060f304b5e4cc4d13d106/MiniMock-1.2.8.tar.gz" } ] }