diff options
Diffstat (limited to 'Lib/test/test_pkg.py')
-rw-r--r-- | Lib/test/test_pkg.py | 76 |
1 files changed, 39 insertions, 37 deletions
diff --git a/Lib/test/test_pkg.py b/Lib/test/test_pkg.py index 5f1659b0f6d..a4ddb15875c 100644 --- a/Lib/test/test_pkg.py +++ b/Lib/test/test_pkg.py @@ -5,7 +5,7 @@ import os import tempfile import textwrap import unittest -from test import test_support +from test import support # Helpers to create and destroy hierarchies. @@ -42,15 +42,17 @@ def fixdir(lst): # from package import * (defined in __init__) -class Test(unittest.TestCase): +class TestPkg(unittest.TestCase): def setUp(self): self.root = None self.pkgname = None self.syspath = list(sys.path) + self.modules_before = support.modules_setup() def tearDown(self): sys.path[:] = self.syspath + support.modules_cleanup(*self.modules_before) if self.root: # Only clean if the test was actually run cleanout(self.root) @@ -87,18 +89,18 @@ class Test(unittest.TestCase): self.pkgname = descr[0][0] def test_1(self): - hier = [("t1", None), ("t1 __init__"+os.extsep+"py", "")] + hier = [("t1", None), ("t1 __init__.py", "")] self.mkhier(hier) import t1 def test_2(self): hier = [ ("t2", None), - ("t2 __init__"+os.extsep+"py", "'doc for t2'"), + ("t2 __init__.py", "'doc for t2'"), ("t2 sub", None), - ("t2 sub __init__"+os.extsep+"py", ""), + ("t2 sub __init__.py", ""), ("t2 sub subsub", None), - ("t2 sub subsub __init__"+os.extsep+"py", "spam = 1"), + ("t2 sub subsub __init__.py", "spam = 1"), ] self.mkhier(hier) @@ -141,11 +143,11 @@ class Test(unittest.TestCase): def test_3(self): hier = [ ("t3", None), - ("t3 __init__"+os.extsep+"py", ""), + ("t3 __init__.py", ""), ("t3 sub", None), - ("t3 sub __init__"+os.extsep+"py", ""), + ("t3 sub __init__.py", ""), ("t3 sub subsub", None), - ("t3 sub subsub __init__"+os.extsep+"py", "spam = 1"), + ("t3 sub subsub __init__.py", "spam = 1"), ] self.mkhier(hier) @@ -158,14 +160,14 @@ class Test(unittest.TestCase): hier = [ ("t4.py", "raise RuntimeError('Shouldnt load t4.py')"), ("t4", None), - ("t4 __init__"+os.extsep+"py", ""), + ("t4 __init__.py", ""), ("t4 sub.py", "raise RuntimeError('Shouldnt load sub.py')"), ("t4 sub", None), - ("t4 sub __init__"+os.extsep+"py", ""), - ("t4 sub subsub"+os.extsep+"py", + ("t4 sub __init__.py", ""), + ("t4 sub subsub.py", "raise RuntimeError('Shouldnt load subsub.py')"), ("t4 sub subsub", None), - ("t4 sub subsub __init__"+os.extsep+"py", "spam = 1"), + ("t4 sub subsub __init__.py", "spam = 1"), ] self.mkhier(hier) @@ -178,9 +180,9 @@ class Test(unittest.TestCase): def test_5(self): hier = [ ("t5", None), - ("t5 __init__"+os.extsep+"py", "import t5.foo"), - ("t5 string"+os.extsep+"py", "spam = 1"), - ("t5 foo"+os.extsep+"py", + ("t5 __init__.py", "import t5.foo"), + ("t5 string.py", "spam = 1"), + ("t5 foo.py", "from . import string; assert string.spam == 1"), ] self.mkhier(hier) @@ -194,35 +196,35 @@ class Test(unittest.TestCase): import t5 self.assertEqual(fixdir(dir(t5)), - ['__doc__', '__file__', '__name__', + ['__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'foo', 'string', 't5']) self.assertEqual(fixdir(dir(t5.foo)), - ['__doc__', '__file__', '__name__', '__package__', - 'string']) + ['__cached__', '__doc__', '__file__', '__name__', + '__package__', 'string']) self.assertEqual(fixdir(dir(t5.string)), - ['__doc__', '__file__', '__name__','__package__', - 'spam']) + ['__cached__', '__doc__', '__file__', '__name__', + '__package__', 'spam']) def test_6(self): hier = [ ("t6", None), - ("t6 __init__"+os.extsep+"py", + ("t6 __init__.py", "__all__ = ['spam', 'ham', 'eggs']"), - ("t6 spam"+os.extsep+"py", ""), - ("t6 ham"+os.extsep+"py", ""), - ("t6 eggs"+os.extsep+"py", ""), + ("t6 spam.py", ""), + ("t6 ham.py", ""), + ("t6 eggs.py", ""), ] self.mkhier(hier) import t6 self.assertEqual(fixdir(dir(t6)), - ['__all__', '__doc__', '__file__', + ['__all__', '__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__']) s = """ import t6 from t6 import * self.assertEqual(fixdir(dir(t6)), - ['__all__', '__doc__', '__file__', + ['__all__', '__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'eggs', 'ham', 'spam']) self.assertEqual(dir(), ['eggs', 'ham', 'self', 'spam', 't6']) @@ -231,17 +233,17 @@ class Test(unittest.TestCase): def test_7(self): hier = [ + ("t7.py", ""), ("t7", None), - ("t7"+os.extsep+"py", ""), - ("t7 __init__"+os.extsep+"py", ""), - ("t7 sub"+os.extsep+"py", + ("t7 __init__.py", ""), + ("t7 sub.py", "raise RuntimeError('Shouldnt load sub.py')"), ("t7 sub", None), - ("t7 sub __init__"+os.extsep+"py", ""), - ("t7 sub "+os.extsep+"py", + ("t7 sub __init__.py", ""), + ("t7 sub .py", "raise RuntimeError('Shouldnt load subsub.py')"), ("t7 sub subsub", None), - ("t7 sub subsub __init__"+os.extsep+"py", + ("t7 sub subsub __init__.py", "spam = 1"), ] self.mkhier(hier) @@ -250,18 +252,18 @@ class Test(unittest.TestCase): t7, sub, subsub = None, None, None import t7 as tas self.assertEqual(fixdir(dir(tas)), - ['__doc__', '__file__', '__name__', + ['__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__']) self.assertFalse(t7) from t7 import sub as subpar self.assertEqual(fixdir(dir(subpar)), - ['__doc__', '__file__', '__name__', + ['__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__']) self.assertFalse(t7) self.assertFalse(sub) from t7.sub import subsub as subsubsub self.assertEqual(fixdir(dir(subsubsub)), - ['__doc__', '__file__', '__name__', + ['__cached__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'spam']) self.assertFalse(t7) self.assertFalse(sub) @@ -285,7 +287,7 @@ class Test(unittest.TestCase): self.assertEqual(t8.__doc__, "doc for t8") def test_main(): - test_support.run_unittest(__name__) + support.run_unittest(__name__) if __name__ == "__main__": |