diff --git a/test/dynamo/cpython/3_13/test_dict.py b/test/dynamo/cpython/3_13/test_dict.py index 4729132c5a5..14f829c1715 100644 --- a/test/dynamo/cpython/3_13/test_dict.py +++ b/test/dynamo/cpython/3_13/test_dict.py @@ -1,3 +1,57 @@ +# ======= BEGIN Dynamo patch ======= +# Owner(s): ["module: dynamo"] + +# ruff: noqa +# flake8: noqa + +import sys +import torch +import torch._dynamo.test_case +import unittest +from torch._dynamo.test_case import CPythonTestCase +from torch.testing._internal.common_utils import ( + run_tests, + xfailIfTorchDynamo, +) + +__TestCase = CPythonTestCase + + +# redirect import statements +import sys +import importlib.abc + +redirect_imports = ( + "test.mapping_tests", + "test.typinganndata", + "test.test_grammar", + "test.test_math", + "test.test_iter", + "test.typinganndata.ann_module", +) + +class RedirectImportFinder(importlib.abc.MetaPathFinder): + def find_spec(self, fullname, path, target=None): + # Check if the import is the problematic one + if fullname in redirect_imports: + try: + # Attempt to import the standalone module + name = fullname.removeprefix("test.") + r = importlib.import_module(name) + # Redirect the module in sys.modules + sys.modules[fullname] = r + # Return a module spec from the found module + return importlib.util.find_spec(name) + except ImportError: + return None + return None + +# Add the custom finder to sys.meta_path +sys.meta_path.insert(0, RedirectImportFinder()) + + +# ======= END DYNAMO PATCH ======= + import collections import collections.abc import gc @@ -11,7 +65,7 @@ from test import support from test.support import import_helper, get_c_recursion_limit -class DictTest(unittest.TestCase): +class DictTest(__TestCase): def test_invalid_keyword_arguments(self): class Custom(dict): @@ -265,6 +319,7 @@ class DictTest(unittest.TestCase): self.assertRaises(ValueError, {}.update, [(1, 2, 3)]) + @unittest.skip("test hangs") def test_fromkeys(self): self.assertEqual(dict.fromkeys('abc'), {'a':None, 'b':None, 'c':None}) d = {} @@ -477,7 +532,7 @@ class DictTest(unittest.TestCase): for copymode in -1, +1: # -1: b has same structure as a # +1: b is a.copy() - for log2size in range(12): + for log2size in range(4): size = 2**log2size a = {} b = {} @@ -1006,18 +1061,6 @@ class DictTest(unittest.TestCase): pass self._tracked(MyDict()) - @support.cpython_only - def test_track_lazy_instance_dicts(self): - class C: - pass - o = C() - d = o.__dict__ - self._not_tracked(d) - o.untracked = 42 - self._not_tracked(d) - o.tracked = [] - self._tracked(d) - def make_shared_key_dict(self, n): class C: pass @@ -1622,7 +1665,7 @@ class DictTest(unittest.TestCase): self.assertGreaterEqual(eq_count, 1) -class CAPITest(unittest.TestCase): +class CAPITest(__TestCase): # Test _PyDict_GetItem_KnownHash() @support.cpython_only @@ -1666,4 +1709,4 @@ class SubclassMappingTests(mapping_tests.BasicTestMappingProtocol): if __name__ == "__main__": - unittest.main() + run_tests()