MCPcopy Index your code
hub / github.com/python/cpython / test_variants

Method test_variants

Lib/test/test_import/__init__.py:2984–3066  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2982 self.assertEqual(init_count, -1)
2983
2984 def test_variants(self):
2985 # Exercise the most meaningful variants described in Python/import.c.
2986 self.maxDiff = None
2987
2988 # Check the "basic" module.
2989
2990 name = self.NAME
2991 expected_init_count = 1
2992 with self.subTest(name):
2993 loaded = self.load(name)
2994
2995 self.check_common(loaded)
2996 self.check_direct(loaded)
2997 self.check_basic(loaded, expected_init_count)
2998 basic = loaded.module
2999
3000 # Check its indirect variants.
3001
3002 name = f'{self.NAME}_basic_wrapper'
3003 self.add_module_cleanup(name)
3004 expected_init_count += 1
3005 with self.subTest(name):
3006 loaded = self.load(name)
3007
3008 self.check_common(loaded)
3009 self.check_indirect(loaded, basic)
3010 self.check_basic(loaded, expected_init_count)
3011
3012 # Currently PyState_AddModule() always replaces the cached module.
3013 self.assertIs(basic.look_up_self(), loaded.module)
3014 self.assertEqual(basic.initialized_count(), expected_init_count)
3015
3016 # The cached module shouldn't change after this point.
3017 basic_lookedup = loaded.module
3018
3019 # Check its direct variant.
3020
3021 name = f'{self.NAME}_basic_copy'
3022 self.add_module_cleanup(name)
3023 expected_init_count += 1
3024 with self.subTest(name):
3025 loaded = self.load(name)
3026
3027 self.check_common(loaded)
3028 self.check_direct(loaded)
3029 self.check_basic(loaded, expected_init_count)
3030
3031 # This should change the cached module for _testsinglephase.
3032 self.assertIs(basic.look_up_self(), basic_lookedup)
3033 self.assertEqual(basic.initialized_count(), expected_init_count)
3034
3035 # Check the non-basic variant that has no state.
3036
3037 name = f'{self.NAME}_with_reinit'
3038 self.add_module_cleanup(name)
3039 with self.subTest(name):
3040 loaded = self.load(name)
3041

Callers

nothing calls this directly

Calls 12

loadMethod · 0.95
check_commonMethod · 0.95
check_directMethod · 0.95
check_basicMethod · 0.95
add_module_cleanupMethod · 0.95
check_indirectMethod · 0.95
check_with_reinitMethod · 0.95
addCleanupMethod · 0.80
assertIsNotMethod · 0.80
subTestMethod · 0.45
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected