[Python-checkins] [3.11] gh-106016: Add Lib/test/test_module/ directory (GH-108293) (#108304)

vstinner webhook-mailer at python.org
Tue Aug 22 11:42:04 EDT 2023


https://github.com/python/cpython/commit/5be32d88182f956f423a56c6250ce4020e8cd53c
commit: 5be32d88182f956f423a56c6250ce4020e8cd53c
branch: 3.11
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: vstinner <vstinner at python.org>
date: 2023-08-22T15:42:00Z
summary:

[3.11] gh-106016: Add Lib/test/test_module/ directory (GH-108293) (#108304)

gh-106016: Add Lib/test/test_module/ directory (GH-108293)

* Move Python scripts related to test_module to this new directory:
  good_getattr.py and bad_getattrX.py scripts.
* Move Lib/test/test_module.py to Lib/test/test_module/__init__.py.
(cherry picked from commit adfc118fdab66882599e01a84c22bd897055f3f1)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
A Lib/test/test_module/__init__.py
A Lib/test/test_module/bad_getattr.py
A Lib/test/test_module/bad_getattr2.py
A Lib/test/test_module/bad_getattr3.py
A Lib/test/test_module/good_getattr.py
D Lib/test/bad_getattr.py
D Lib/test/bad_getattr2.py
D Lib/test/bad_getattr3.py
D Lib/test/good_getattr.py
D Lib/test/test_module.py
M Makefile.pre.in

diff --git a/Lib/test/test_module.py b/Lib/test/test_module/__init__.py
similarity index 92%
rename from Lib/test/test_module.py
rename to Lib/test/test_module/__init__.py
index f72177dda3702..87d1a8e3d6c97 100644
--- a/Lib/test/test_module.py
+++ b/Lib/test/test_module/__init__.py
@@ -126,8 +126,8 @@ def test_weakref(self):
         self.assertIs(wr(), None)
 
     def test_module_getattr(self):
-        import test.good_getattr as gga
-        from test.good_getattr import test
+        import test.test_module.good_getattr as gga
+        from test.test_module.good_getattr import test
         self.assertEqual(test, "There is test")
         self.assertEqual(gga.x, 1)
         self.assertEqual(gga.y, 2)
@@ -135,46 +135,46 @@ def test_module_getattr(self):
                                     "Deprecated, use whatever instead"):
             gga.yolo
         self.assertEqual(gga.whatever, "There is whatever")
-        del sys.modules['test.good_getattr']
+        del sys.modules['test.test_module.good_getattr']
 
     def test_module_getattr_errors(self):
-        import test.bad_getattr as bga
-        from test import bad_getattr2
+        import test.test_module.bad_getattr as bga
+        from test.test_module import bad_getattr2
         self.assertEqual(bga.x, 1)
         self.assertEqual(bad_getattr2.x, 1)
         with self.assertRaises(TypeError):
             bga.nope
         with self.assertRaises(TypeError):
             bad_getattr2.nope
-        del sys.modules['test.bad_getattr']
-        if 'test.bad_getattr2' in sys.modules:
-            del sys.modules['test.bad_getattr2']
+        del sys.modules['test.test_module.bad_getattr']
+        if 'test.test_module.bad_getattr2' in sys.modules:
+            del sys.modules['test.test_module.bad_getattr2']
 
     def test_module_dir(self):
-        import test.good_getattr as gga
+        import test.test_module.good_getattr as gga
         self.assertEqual(dir(gga), ['a', 'b', 'c'])
-        del sys.modules['test.good_getattr']
+        del sys.modules['test.test_module.good_getattr']
 
     def test_module_dir_errors(self):
-        import test.bad_getattr as bga
-        from test import bad_getattr2
+        import test.test_module.bad_getattr as bga
+        from test.test_module import bad_getattr2
         with self.assertRaises(TypeError):
             dir(bga)
         with self.assertRaises(TypeError):
             dir(bad_getattr2)
-        del sys.modules['test.bad_getattr']
-        if 'test.bad_getattr2' in sys.modules:
-            del sys.modules['test.bad_getattr2']
+        del sys.modules['test.test_module.bad_getattr']
+        if 'test.test_module.bad_getattr2' in sys.modules:
+            del sys.modules['test.test_module.bad_getattr2']
 
     def test_module_getattr_tricky(self):
-        from test import bad_getattr3
+        from test.test_module import bad_getattr3
         # these lookups should not crash
         with self.assertRaises(AttributeError):
             bad_getattr3.one
         with self.assertRaises(AttributeError):
             bad_getattr3.delgetattr
-        if 'test.bad_getattr3' in sys.modules:
-            del sys.modules['test.bad_getattr3']
+        if 'test.test_module.bad_getattr3' in sys.modules:
+            del sys.modules['test.test_module.bad_getattr3']
 
     def test_module_repr_minimal(self):
         # reprs when modules have no __file__, __name__, or __loader__
diff --git a/Lib/test/bad_getattr.py b/Lib/test/test_module/bad_getattr.py
similarity index 100%
rename from Lib/test/bad_getattr.py
rename to Lib/test/test_module/bad_getattr.py
diff --git a/Lib/test/bad_getattr2.py b/Lib/test/test_module/bad_getattr2.py
similarity index 100%
rename from Lib/test/bad_getattr2.py
rename to Lib/test/test_module/bad_getattr2.py
diff --git a/Lib/test/bad_getattr3.py b/Lib/test/test_module/bad_getattr3.py
similarity index 100%
rename from Lib/test/bad_getattr3.py
rename to Lib/test/test_module/bad_getattr3.py
diff --git a/Lib/test/good_getattr.py b/Lib/test/test_module/good_getattr.py
similarity index 100%
rename from Lib/test/good_getattr.py
rename to Lib/test/test_module/good_getattr.py
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 2a407a7df697e..6405d06afe14e 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -2012,6 +2012,7 @@ TESTSUBDIRS=	ctypes/test \
 		test/test_importlib/zipdata01 \
 		test/test_importlib/zipdata02 \
 		test/test_json \
+		test/test_module \
 		test/test_peg_generator \
 		test/test_sqlite3 \
 		test/test_tomllib \



More information about the Python-checkins mailing list