33import os
44import tempfile
55import unittest
6- from unittest .mock import patch
76
8- import mypyc .build as mypyc_build_module
97from mypyc .build import get_header_deps , resolve_cfile_deps
108from mypyc .ir .ops import BasicBlock
119from mypyc .ir .pprint import format_blocks , generate_names_for_ir
@@ -27,68 +25,6 @@ def test_debug_op(self) -> None:
2725 assert code [:- 1 ] == ["L0:" , " r0 = 'foo'" , " CPyDebug_PrintObject(r0)" ]
2826
2927
30- class TestIncrementalOutputFiles (unittest .TestCase ):
31- def test_cached_dependency_output_file_not_overwritten_for_preserved_suppression (self ) -> None :
32- with tempfile .TemporaryDirectory () as tmp :
33- build_dir = os .path .join (tmp , "build" )
34- with open (os .path .join (tmp , "mypy.ini" ), "w" , encoding = "utf-8" ) as f :
35- f .write ("[mypy]\n follow_imports = skip\n " )
36- os .mkdir (os .path .join (tmp , "skipped" ))
37- with open (os .path .join (tmp , "skipped" , "__init__.py" ), "w" , encoding = "utf-8" ) as f :
38- f .write ("x = 1\n " )
39- with open (os .path .join (tmp , "skipped" , "child.py" ), "w" , encoding = "utf-8" ) as f :
40- f .write ("import skipped\n \n def child() -> int:\n return 1\n " )
41- with open (os .path .join (tmp , "dep.py" ), "w" , encoding = "utf-8" ) as f :
42- f .write ("import skipped\n \n def value() -> int:\n return 1\n " )
43- with open (os .path .join (tmp , "main.py" ), "w" , encoding = "utf-8" ) as f :
44- f .write ("import dep\n \n def value() -> int:\n return dep.value()\n " )
45-
46- compiler_options = CompilerOptions (separate = True , target_dir = build_dir )
47-
48- old_cwd = os .getcwd ()
49- os .chdir (tmp )
50- try :
51- files = ["dep.py" , "skipped/child.py" , "main.py" ]
52-
53- groups , group_cfilenames , _ = mypyc_build_module .mypyc_build (
54- files , compiler_options , separate = True
55- )
56-
57- dep_group = next (
58- i
59- for i , (group_sources , _ ) in enumerate (groups )
60- if [source .module for source in group_sources ] == ["dep" ]
61- )
62- dep_output_files = {
63- os .path .abspath (path )
64- for paths in group_cfilenames [dep_group ]
65- for path in paths
66- }
67-
68- # Only main changed; dep should be loaded from the mypyc IR cache and reuse
69- # its existing C outputs.
70- with open ("main.py" , "w" , encoding = "utf-8" ) as f :
71- f .write ("import dep\n \n def value() -> int:\n return dep.value() + 1\n " )
72-
73- written_paths : set [str ] = set ()
74- original_write_file = mypyc_build_module .write_file
75-
76- def recording_write_file (path : str , contents : str ) -> None :
77- written_paths .add (os .path .abspath (path ))
78- original_write_file (path , contents )
79-
80- with patch .object (
81- mypyc_build_module , "write_file" , side_effect = recording_write_file
82- ):
83- # skipped.child imports its skipped package ancestor; loading that cached
84- # state should not make cached dep stale or rewrite dep's generated outputs.
85- mypyc_build_module .mypyc_build (files , compiler_options , separate = True )
86- finally :
87- os .chdir (old_cwd )
88-
89- assert written_paths .isdisjoint (dep_output_files )
90-
91-
9228class TestHeaderDeps (unittest .TestCase ):
9329 """
9430 Tests for the header-dependency tracking used to build `Extension.depends`, which drives
0 commit comments