MCPcopy Index your code
hub / github.com/RustPython/RustPython / test_variants

Method test_variants

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

Source from the content-addressed store, hash-verified

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

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
subTestMethod · 0.80
addCleanupMethod · 0.80
assertIsNotMethod · 0.80
assertIsMethod · 0.45
assertEqualMethod · 0.45

Tested by

no test coverage detected