Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r64850:7d2924ddfa80 Date: 2013-06-11 13:24 +0200 http://bitbucket.org/pypy/pypy/changeset/7d2924ddfa80/
Log: Add two new tests, one of which fails on PyPy because we don't create several module objects for the same *built-in* module. diff --git a/pypy/module/imp/test/test_app.py b/pypy/module/imp/test/test_app.py --- a/pypy/module/imp/test/test_app.py +++ b/pypy/module/imp/test/test_app.py @@ -200,3 +200,48 @@ except KeyError: pass rmtree(dir_name, True) + + def test_builtin_reimport(self): + # from https://bugs.pypy.org/issue1514 + import sys, marshal + + old = marshal.loads + marshal.loads = 42 + + # save, re-import, restore. + saved = sys.modules.pop('marshal') + __import__('marshal') + sys.modules['marshal'] = saved + + assert marshal.loads == 42 + import marshal + assert marshal.loads == 42 + marshal.loads = old + + def test_builtin_reimport_mess(self): + # taken from https://bugs.pypy.org/issue1514, with extra cases + # that show a difference with CPython: we can get on CPython + # several module objects for the same built-in module :-( + skip("several built-in module objects: not supported by pypy") + import sys, marshal + + old = marshal.loads + marshal.loads = 42 + + # save, re-import, restore. + saved = sys.modules.pop('marshal') + marshal2 = __import__('marshal') + assert marshal2 is not marshal + assert marshal2.loads is old + assert marshal2 is sys.modules['marshal'] + assert marshal is saved + assert marshal.loads == 42 + + import marshal + assert marshal.loads is old + + sys.modules['marshal'] = saved + import marshal + assert marshal.loads == 42 + + marshal.loads = old _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit