{ "info": { "author": "Joseph Heyming", "author_email": "joeheyming@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.4", "Programming Language :: Python :: 2.5", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.1", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Software Development :: Testing" ], "description": "# Redef\n\n[![Build Status](https://secure.travis-ci.org/joeheyming/redef.png)](http://travis-ci.org/joeheyming/redef)\n\n\nTo install, just run:\n\nbash\npython setup.py build\npython setup.py install\n\n\nSee [test_redef.py](/joeheyming/redef/blob/master/test_redef.py) under your install path for examples.\n\nRedef is intended to create lexically scoped variables, that when destroyed, undo mock behavior.\nIt was inspired by a Perl module, [Test::Resub](http://search.cpan.org/~airwave/Test-Resub-1.02/lib/Test/Resub.pm)\n\nThe best examples use unittest, but it should work with any testing framework.\n\npython\nimport unittest\nfrom redef import redef\n\nclass MyClass:\n def lame_function(self):\n return \"something I don't want\"\n\nclass MyTest(unittest.TestCase):\n def test1(self):\n myobj = MyClass()\n self.assertEqual(myobj.lame_function(), \"something I don't want\")\n want = 'something I want'\n\twith redef(MyClass, 'lame_function', lambda s: want) as rd_lf:\n\t self.assertEqual(myobj.lame_function(), want)\n\n # after test1, rd_lf gets deleted and resets\n\n def test2(self): \n myobj = MyClass()\n # test2 is uneffected by test1\n self.assertEqual(myobj.lame_function(), \"something I don't want\")\n\n\nThis doesn't have to be a function, you can also redefine attributes directly on an object.\n\npython\nclass MyClass:\n unpredictable = 'random string'\n\nmy_global_object = MyClass()\n\nclass MyTest(unittest.TestCase):\n def test3(self):\n rd_u = redef(my_global_object, 'unpredictable', 'unit testable string')\n # ... test something awesome!\n self.assertEqual(my_global_object.unpredictable, 'unit testable string')\n\n def test4(self):\n # hey, my_global_object is back to being unpredictable\n self.assertEqual(my_global_object.unpredictable, 'unpredictable')\n\n \nIf you don't want to rely on automatic scope you can explicitally call close\n on your redefed function. Calling del on the redefed function is the sam\n as calling close\n \nThere are other useful functions provided on the redef object itself:\n\n* Class Redef:\n * __init__:\n * takes an object and a key. The rest of the arguments are kwargs:\n * if the key doesn't exist in the object, an exception will be raised unless you provide kwargs must_exist\n * value: if provided, this value will redefine the key in the object, otherwise you 'wiretap' the object\n * must_call: if provided, when the Redef object is destroyed, it warns if this constraint is violated.\n\n * called():\n Stores how many times a redef'd function was called.\n * method_args():\n Stores the most recent *args to the redef'd function.\n * named_method_args():\n Stores the most recent **kwargs to the redef'd function.\n * reset():\n Sets called, method_args, and named_method_args back to the default state of 0, None, None\n * was_called():\n Asks the redef object if there was ever a call. Regardless of calling the reset() function\n * never_called():\n Asks the redef object if there was never a call. Regardless of calling the reset() function\n\nRedef also provides a freebie static function:\n\n* redef(obj, key, value):\n Static constructor of a Redef object\n\nWhere\n * obj: is a Class, Module, or Object you want to temporariliy change\n * key: The string name of the attribute you want to change\n * value: The new value. If the value is None, you only capture called, method_args, and named_method_args\n * The None case won't redefine the key on the obj\n\nThese static functions were provided to show the usefulness of redef: \nFor example, you could capture stdout of a function call, and after capturing it,\nsys.stdout goes back to normal:\n\n* Class CapturedOutput:\n * Has 2 variables you want: output, returned\n\n* Static Functions that return a CapturedOutput:\n * stdout_of(func, *args, **kwargs):\n Call a function and capture the stdout.\n Returns a CapturedOutput object that has the stdout and the return value of calling func.\n\n * stderr_of(func, *args, **kwargs):\n Call a function and capture the stderr.\n Returns a CapturedOutput object that has the stderr and the return value of calling func.\n \n* wiretap:\n * A static function that creates a Redef object only for the purpose of capturing the method_args and called values.\n * The original functionality should remain the same.\n\nPlease ask any questions on github: http://github.com/joeheyming/redef/issues", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/joeheyming/redef/zipball/master", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/joeheyming/redef", "keywords": null, "license": "GNU GPLv3, Python License", "maintainer": null, "maintainer_email": null, "name": "redef", "package_url": "https://pypi.org/project/redef/", "platform": "any", "project_url": "https://pypi.org/project/redef/", "project_urls": { "Download": "https://github.com/joeheyming/redef/zipball/master", "Homepage": "http://github.com/joeheyming/redef" }, "release_url": "https://pypi.org/project/redef/1.7/", "requires_dist": null, "requires_python": null, "summary": "Test utility for redefining functions", "version": "1.7" }, "last_serial": 1309260, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "264ed9f3341c75245dcc183eef796099", "sha256": "d02082a5c8f3f597d09eca81d5d93d19f3d5f130a18053c41f8423687458fad5" }, "downloads": -1, "filename": "redef-1.0.tar.gz", "has_sig": true, "md5_digest": "264ed9f3341c75245dcc183eef796099", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2609, "upload_time": "2012-07-09T03:13:37", "url": "https://files.pythonhosted.org/packages/30/52/e64d8fbab295d4bee24a177dd3e6e78efc1615bd71c7077248ef6f202d2a/redef-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "4bc128d710a5c2b294280b4df7f22618", "sha256": "dfbe10c5bd0b9f13ed1cce183d4262fe6d827bed45dd156ef1a904dfa2840a3c" }, "downloads": -1, "filename": "redef-1.1.tar.gz", "has_sig": true, "md5_digest": "4bc128d710a5c2b294280b4df7f22618", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3305, "upload_time": "2012-07-10T08:57:18", "url": "https://files.pythonhosted.org/packages/d1/b9/bb60f25646e958ca298c5445c8f75871dfcfeca40332aefab939907a34f9/redef-1.1.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "0e5f37b87a7f83130ad429ce24ac851f", "sha256": "92e842c317b617ebdb6c703e992c4f031a8909455feda0ecbcca06162ebd0c79" }, "downloads": -1, "filename": "redef-1.2.tar.gz", "has_sig": true, "md5_digest": "0e5f37b87a7f83130ad429ce24ac851f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4355, "upload_time": "2012-07-15T19:53:29", "url": "https://files.pythonhosted.org/packages/13/fe/65f841de279a31b34b788c735d53db492aaa6f64e540c42a9ac438b5cc88/redef-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "0935296e8ef312a01291504652223cf4", "sha256": "581c7a6a7418134c1d93af3efd264d4134b6297927dbb65a5146c5950f64f9ee" }, "downloads": -1, "filename": "redef-1.3.macosx-10.8-intel.exe", "has_sig": false, "md5_digest": "0935296e8ef312a01291504652223cf4", "packagetype": "bdist_wininst", "python_version": "any", "requires_python": null, "size": 70529, "upload_time": "2013-10-26T04:47:58", "url": "https://files.pythonhosted.org/packages/5d/dd/f0aee80f8a5cb6aed6c0156ebf8557c9c96a48933b87a1ead9bc30f2f58d/redef-1.3.macosx-10.8-intel.exe" }, { "comment_text": "", "digests": { "md5": "5f8a6d6b1374525fb5512064ad3774f7", "sha256": "dfae4312802b53540ed854efac4efd71c164f196dfd24b60504d7766f758f925" }, "downloads": -1, "filename": "redef-1.3.tar.gz", "has_sig": true, "md5_digest": "5f8a6d6b1374525fb5512064ad3774f7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4456, "upload_time": "2012-07-17T07:14:33", "url": "https://files.pythonhosted.org/packages/3b/6a/ba1c53f1c8e80f2d5259898885f1223c3c0478467f0de4026f8faa2a71c9/redef-1.3.tar.gz" } ], "1.4": [ { "comment_text": "", "digests": { "md5": "188ff1b76fb02144cd47771a81e701a9", "sha256": "bdd47689ac2994871c793a27b7e9f4b41965d6a5de1abe979f5b5285d779c668" }, "downloads": -1, "filename": "redef-1.4.macosx-10.8-intel.exe", "has_sig": false, "md5_digest": "188ff1b76fb02144cd47771a81e701a9", "packagetype": "bdist_wininst", "python_version": "any", "requires_python": null, "size": 70529, "upload_time": "2013-10-26T04:51:26", "url": "https://files.pythonhosted.org/packages/12/64/2a1826d68a4f761ca24deac1dd8aea9c5c1d9db835e10191b3b2f4d90de6/redef-1.4.macosx-10.8-intel.exe" }, { "comment_text": "", "digests": { "md5": "73158ab603a0c194c5435aa7d6087aa6", "sha256": "2d58818ab1ef767d1a0de0d6b990c6a715fee6a96b35a3560b8d4a834b711554" }, "downloads": -1, "filename": "redef-1.4.tar.gz", "has_sig": false, "md5_digest": "73158ab603a0c194c5435aa7d6087aa6", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4632, "upload_time": "2013-10-26T04:51:23", "url": "https://files.pythonhosted.org/packages/ee/74/893b01a9b62e22b50e9a42cfff200ba444d90fc9ab15b54a37b5e7a3b89a/redef-1.4.tar.gz" } ], "1.5": [ { "comment_text": "", "digests": { "md5": "83275354f3905fb4e521e0d7f5a5d94e", "sha256": "c298d7352f555e413ff7df1914daffa4df8cd2c330afa6f768b8294b22330983" }, "downloads": -1, "filename": "redef-1.5.tar.gz", "has_sig": false, "md5_digest": "83275354f3905fb4e521e0d7f5a5d94e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4671, "upload_time": "2014-04-18T20:39:53", "url": "https://files.pythonhosted.org/packages/62/79/becbd13b0f97c06f486da30c5d53f1cc782f60c811e32593651cda20846e/redef-1.5.tar.gz" } ], "1.6": [ { "comment_text": "", "digests": { "md5": "7c14519237d59c2d37a4b842fe407055", "sha256": "221dc474755d7fd57179becbfad08aa42fc640bef0b88aff7e81c0d75c15f36b" }, "downloads": -1, "filename": "redef-1.6.tar.gz", "has_sig": false, "md5_digest": "7c14519237d59c2d37a4b842fe407055", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4740, "upload_time": "2014-04-20T18:04:32", "url": "https://files.pythonhosted.org/packages/42/83/ce58813370c836ae5497e3b3300b562a76bf7593ae64327abd00ddc101f3/redef-1.6.tar.gz" } ], "1.7": [ { "comment_text": "", "digests": { "md5": "8eaa16a4709788ed56a8daf49b66b73c", "sha256": "02b3b4a130b3c706ce58457997c76371c340ca885ebab52c0de1fe9d5c0adf64" }, "downloads": -1, "filename": "redef-1.7.tar.gz", "has_sig": false, "md5_digest": "8eaa16a4709788ed56a8daf49b66b73c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4816, "upload_time": "2014-11-17T00:25:35", "url": "https://files.pythonhosted.org/packages/84/e9/ae831a5fcdd493d133ef7343adf90def63f3cbbc499a0bb674869be4dc5c/redef-1.7.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8eaa16a4709788ed56a8daf49b66b73c", "sha256": "02b3b4a130b3c706ce58457997c76371c340ca885ebab52c0de1fe9d5c0adf64" }, "downloads": -1, "filename": "redef-1.7.tar.gz", "has_sig": false, "md5_digest": "8eaa16a4709788ed56a8daf49b66b73c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4816, "upload_time": "2014-11-17T00:25:35", "url": "https://files.pythonhosted.org/packages/84/e9/ae831a5fcdd493d133ef7343adf90def63f3cbbc499a0bb674869be4dc5c/redef-1.7.tar.gz" } ] }