@@ -2109,43 +2109,6 @@ def test_set_bad_filter(self):
21092109 self .assertRaises (ValueError , _testcapi .PyImport_SetLazyImportsFilter , 42 )
21102110
21112111
2112-
2113- class DictOperationsWithLazyTests (unittest .TestCase ):
2114- """Tests for dict operations with lazy import values."""
2115-
2116- def tearDown (self ):
2117- for key in list (sys .modules .keys ()):
2118- if key .startswith ('test.test_lazy_import.data' ):
2119- del sys .modules [key ]
2120- sys .set_lazy_imports_filter (None )
2121- sys .set_lazy_imports ("normal" )
2122-
2123- def test_dict_copy_preserves_lazy (self ):
2124- """dict.copy() should preserve lazy import proxy objects."""
2125- sys .set_lazy_imports ("all" )
2126- from test .test_lazy_import .data .metasyntactic import names
2127- d = names .__dict__ .copy ()
2128- self .assertIsInstance (d ["Foo" ], types .LazyImportType )
2129- self .assertEqual (d ["Metasyntactic" ], "Metasyntactic" )
2130-
2131- def test_dict_or_preserves_lazy (self ):
2132- """dict | should keep the winning side's lazy/resolved status."""
2133- sys .set_lazy_imports ("all" )
2134- from test .test_lazy_import .data .metasyntactic import names
2135- lazy = names .__dict__ .copy ()
2136- resolved = {"Foo" : "resolved" }
2137- self .assertEqual ((lazy | resolved )["Foo" ], "resolved" )
2138- self .assertIsInstance ((resolved | lazy )["Foo" ], types .LazyImportType )
2139-
2140- def test_dict_update_preserves_lazy (self ):
2141- """dict.update() should transfer lazy import proxy objects."""
2142- sys .set_lazy_imports ("all" )
2143- from test .test_lazy_import .data .metasyntactic import names
2144- target = {}
2145- target .update (names .__dict__ )
2146- self .assertIsInstance (target ["Foo" ], types .LazyImportType )
2147-
2148-
21492112class SubmoduleLazinessTests (unittest .TestCase ):
21502113 """Tests that module-level lazy imports remain lazy until accessed."""
21512114
@@ -2276,56 +2239,5 @@ def test_fails_without_lazy(self):
22762239 self .assertIn ("ImportError" , result .stderr )
22772240
22782241
2279- @support .requires_subprocess ()
2280- class DictMutationDuringLoadTests (unittest .TestCase ):
2281- """Tests that module dict mutation during loading doesn't crash."""
2282-
2283- def test_dict_mutation_during_import (self ):
2284- """Iterating a module dict while lazy imports resolve should not
2285- crash even if the dict is mutated during iteration."""
2286- with tempfile .TemporaryDirectory () as tmpdir :
2287- pkg = os .path .join (tmpdir , "dcwl_pkg" )
2288- os .makedirs (pkg )
2289-
2290- with open (os .path .join (pkg , "__init__.py" ), "w" ) as f :
2291- f .write (textwrap .dedent ("""\
2292- from .elements import elements_function
2293-
2294- def __go(lcls):
2295- global __all__
2296- __all__ = sorted(
2297- name
2298- for name, obj in lcls.items()
2299- if not name.startswith("_")
2300- )
2301-
2302- __go(locals())
2303- """ ))
2304-
2305- with open (os .path .join (pkg , "elements.py" ), "w" ) as f :
2306- f .write (textwrap .dedent ("""\
2307- from .elements_sub import elements_sub_function
2308-
2309- def elements_function():
2310- pass
2311- """ ))
2312-
2313- with open (os .path .join (pkg , "elements_sub.py" ), "w" ) as f :
2314- f .write ("def elements_sub_function(): pass\n " )
2315-
2316- env = os .environ .copy ()
2317- env ["PYTHONPATH" ] = tmpdir
2318- result = subprocess .run (
2319- [sys .executable , "-X" , "lazy_imports=all" ,
2320- "-c" , "import dcwl_pkg; print('OK')" ],
2321- capture_output = True , text = True , env = env ,
2322- )
2323- self .assertEqual (
2324- result .returncode , 0 ,
2325- f"stdout: { result .stdout } , stderr: { result .stderr } " ,
2326- )
2327- self .assertIn ("OK" , result .stdout )
2328-
2329-
23302242if __name__ == '__main__' :
23312243 unittest .main ()
0 commit comments