Skip to content

Commit 0855bdd

Browse files
committed
test_import: Move modexport tests to their own class
1 parent ffe3322 commit 0855bdd

File tree

1 file changed

+77
-82
lines changed

1 file changed

+77
-82
lines changed

Lib/test/test_import/__init__.py

Lines changed: 77 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2482,88 +2482,6 @@ def test_testmultiphase_exec_multiple(self):
24822482
self.assertLess(keys.index('a'), keys.index('b'))
24832483
self.assertLess(keys.index('b'), keys.index('c'))
24842484

2485-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2486-
def test_from_modexport(self):
2487-
modname = '_test_from_modexport'
2488-
filename = _testmultiphase.__file__
2489-
module = import_extension_from_file(modname, filename,
2490-
put_in_sys_modules=False)
2491-
2492-
self.assertEqual(module.__name__, modname)
2493-
2494-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2495-
def test_from_modexport_null(self):
2496-
modname = '_test_from_modexport_null'
2497-
filename = _testmultiphase.__file__
2498-
with self.assertRaises(SystemError):
2499-
import_extension_from_file(modname, filename,
2500-
put_in_sys_modules=False)
2501-
2502-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2503-
def test_from_modexport_exception(self):
2504-
modname = '_test_from_modexport_exception'
2505-
filename = _testmultiphase.__file__
2506-
with self.assertRaises(ValueError):
2507-
import_extension_from_file(modname, filename,
2508-
put_in_sys_modules=False)
2509-
2510-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2511-
def test_from_modexport_create_nonmodule(self):
2512-
modname = '_test_from_modexport_create_nonmodule'
2513-
filename = _testmultiphase.__file__
2514-
module = import_extension_from_file(modname, filename,
2515-
put_in_sys_modules=False)
2516-
self.assertIsInstance(module, str)
2517-
2518-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2519-
def test_from_modexport_smoke(self):
2520-
# General positive test for sundry features
2521-
# (PyModule_FromSlotsAndSpec tests exercise these more carefully)
2522-
modname = '_test_from_modexport_smoke'
2523-
filename = _testmultiphase.__file__
2524-
module = import_extension_from_file(modname, filename,
2525-
put_in_sys_modules=False)
2526-
self.assertEqual(module.__doc__, "the expected docstring")
2527-
self.assertEqual(module.number, 147)
2528-
self.assertEqual(module.get_state_int(), 258)
2529-
self.assertGreater(module.get_test_token(), 0)
2530-
2531-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2532-
def test_from_modexport_smoke_token(self):
2533-
_testcapi = import_module("_testcapi")
2534-
2535-
modname = '_test_from_modexport_smoke'
2536-
filename = _testmultiphase.__file__
2537-
module = import_extension_from_file(modname, filename,
2538-
put_in_sys_modules=False)
2539-
token = module.get_test_token()
2540-
self.assertEqual(_testcapi.pymodule_get_token(module), token)
2541-
2542-
tp = module.Example
2543-
self.assertEqual(_testcapi.pytype_getmodulebytoken(tp, token), module)
2544-
class Sub(tp):
2545-
pass
2546-
self.assertEqual(_testcapi.pytype_getmodulebytoken(Sub, token), module)
2547-
2548-
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
2549-
def test_from_modexport_empty_slots(self):
2550-
# Module to test that:
2551-
# - no slots are mandatory for PyModExport
2552-
# - the slots array is used as the default token
2553-
modname = '_test_from_modexport_empty_slots'
2554-
filename = _testmultiphase.__file__
2555-
module = import_extension_from_file(
2556-
modname, filename, put_in_sys_modules=False)
2557-
2558-
self.assertEqual(module.__name__, modname)
2559-
self.assertEqual(module.__doc__, None)
2560-
2561-
_testcapi = import_module("_testcapi")
2562-
smoke_mod = import_extension_from_file(
2563-
'_test_from_modexport_smoke', filename, put_in_sys_modules=False)
2564-
self.assertEqual(_testcapi.pymodule_get_token(module),
2565-
smoke_mod.get_modexport_empty_slots())
2566-
25672485
@unittest.skipIf(_testinternalcapi is None, "requires _testinternalcapi")
25682486
def test_python_compat(self):
25692487
module = 'threading'
@@ -3460,6 +3378,83 @@ def test_basic_multiple_interpreters_reset_each(self):
34603378
# * module's global state was initialized, not reset
34613379

34623380

3381+
@unittest.skipIf(_testmultiphase is None, "test requires _testmultiphase module")
3382+
class ModexportTests(unittest.TestCase):
3383+
def test_from_modexport(self):
3384+
modname = '_test_from_modexport'
3385+
filename = _testmultiphase.__file__
3386+
module = import_extension_from_file(modname, filename,
3387+
put_in_sys_modules=False)
3388+
3389+
self.assertEqual(module.__name__, modname)
3390+
3391+
def test_from_modexport_null(self):
3392+
modname = '_test_from_modexport_null'
3393+
filename = _testmultiphase.__file__
3394+
with self.assertRaises(SystemError):
3395+
import_extension_from_file(modname, filename,
3396+
put_in_sys_modules=False)
3397+
3398+
def test_from_modexport_exception(self):
3399+
modname = '_test_from_modexport_exception'
3400+
filename = _testmultiphase.__file__
3401+
with self.assertRaises(ValueError):
3402+
import_extension_from_file(modname, filename,
3403+
put_in_sys_modules=False)
3404+
3405+
def test_from_modexport_create_nonmodule(self):
3406+
modname = '_test_from_modexport_create_nonmodule'
3407+
filename = _testmultiphase.__file__
3408+
module = import_extension_from_file(modname, filename,
3409+
put_in_sys_modules=False)
3410+
self.assertIsInstance(module, str)
3411+
3412+
def test_from_modexport_smoke(self):
3413+
# General positive test for sundry features
3414+
# (PyModule_FromSlotsAndSpec tests exercise these more carefully)
3415+
modname = '_test_from_modexport_smoke'
3416+
filename = _testmultiphase.__file__
3417+
module = import_extension_from_file(modname, filename,
3418+
put_in_sys_modules=False)
3419+
self.assertEqual(module.__doc__, "the expected docstring")
3420+
self.assertEqual(module.number, 147)
3421+
self.assertEqual(module.get_state_int(), 258)
3422+
self.assertGreater(module.get_test_token(), 0)
3423+
3424+
def test_from_modexport_smoke_token(self):
3425+
_testcapi = import_module("_testcapi")
3426+
3427+
modname = '_test_from_modexport_smoke'
3428+
filename = _testmultiphase.__file__
3429+
module = import_extension_from_file(modname, filename,
3430+
put_in_sys_modules=False)
3431+
token = module.get_test_token()
3432+
self.assertEqual(_testcapi.pymodule_get_token(module), token)
3433+
3434+
tp = module.Example
3435+
self.assertEqual(_testcapi.pytype_getmodulebytoken(tp, token), module)
3436+
class Sub(tp):
3437+
pass
3438+
self.assertEqual(_testcapi.pytype_getmodulebytoken(Sub, token), module)
3439+
3440+
def test_from_modexport_empty_slots(self):
3441+
# Module to test that:
3442+
# - no slots are mandatory for PyModExport
3443+
# - the slots array is used as the default token
3444+
modname = '_test_from_modexport_empty_slots'
3445+
filename = _testmultiphase.__file__
3446+
module = import_extension_from_file(
3447+
modname, filename, put_in_sys_modules=False)
3448+
3449+
self.assertEqual(module.__name__, modname)
3450+
self.assertEqual(module.__doc__, None)
3451+
3452+
_testcapi = import_module("_testcapi")
3453+
smoke_mod = import_extension_from_file(
3454+
'_test_from_modexport_smoke', filename, put_in_sys_modules=False)
3455+
self.assertEqual(_testcapi.pymodule_get_token(module),
3456+
smoke_mod.get_modexport_empty_slots())
3457+
34633458
@cpython_only
34643459
class TestMagicNumber(unittest.TestCase):
34653460
def test_magic_number_endianness(self):

0 commit comments

Comments
 (0)