Commits

Armin Rigo committed 7d2924d

Add two new tests, one of which fails on PyPy because we don't
create several module objects for the same *built-in* module.

  • Participants
  • Parent commits 93a61b8

Comments (0)

Files changed (1)

File pypy/module/imp/test/test_app.py

                 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