Debian Codegraph @

test-data/unit/fine-grained-cache-incremental.test

raw
1 -- Test cases for building caches for fine-grained mode using incremental
2 -- builds.
3 --
4 -- These tests are run only with the cache.
5 --
6 -- '# num_build_steps: N' specifies how many regular build steps (without the daemon)
7 -- to do before switching to running using the daemon. Default is 1.
8
9
10 -- Add file
11 -- --------
12
13
14 [case testIncrCacheBasic1]
15 # num_build_steps: 2
16 import a
17 [file a.py]
18 from b import x
19 def f() -> int:
20 return 0
21 [file b.py]
22 x = 1
23 [file a.py.2]
24 from b import x
25 def f() -> int:
26 return 0 + x
27 [file b.py.3]
28 x = 'hi'
29 [out]
30 ==
31 ==
32 a.py:3: error: Unsupported operand types for + ("int" and "str")
33
34 [case testIncrCacheBasic2]
35 # num_build_steps: 2
36 import a
37 [file a.py]
38 from b import x
39 def f() -> int:
40 return 0+x
41 [file b.py]
42 x = 1
43 [file b.py.2]
44 from c import x
45 [file c.py.2]
46 x = 1
47 [file c.py.3]
48 x = 'hi'
49 [out]
50 ==
51 ==
52 a.py:3: error: Unsupported operand types for + ("int" and "str")
53
54 [case testIncrCacheDoubleChange1]
55 # num_build_steps: 2
56 import b
57 import c
58 [file a.py]
59 def f(x: int) -> None:
60 pass
61 [file b.py]
62 from a import f
63 f(10)
64 [file c.py]
65 from a import f
66 f(10)
67
68 [file a.py.2]
69 def f(x: int) -> None:
70 pass
71 # nothing changed
72
73 [file a.py.3]
74 def f(x: str) -> None:
75 pass
76 [out]
77 ==
78 ==
79 c.py:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
80 b.py:2: error: Argument 1 to "f" has incompatible type "int"; expected "str"
81
82 [case testIncrCacheProtocol1]
83 # num_build_steps: 2
84 import a
85 [file a.py]
86 import b
87 from typing import Protocol
88 class P(Protocol):
89 x: int
90 def f() -> None:
91 def g(x: P) -> None:
92 pass
93 g(b.C())
94 [file c.py]
95 [file c.py.2]
96 # yo
97 [file b.py]
98 class C:
99 x: int
100 [file b.py.3]
101 class C:
102 x: str
103 -- If we did a *full* reload (because the proto cache failed to load),
104 -- nothing would show up as stale
105 [stale2 b]
106 [rechecked2 a, b]
107 [out]
108 ==
109 ==
110 a.py:8: error: Argument 1 to "g" has incompatible type "C"; expected "P"
111 a.py:8: note: Following member(s) of "C" have conflicts:
112 a.py:8: note: x: expected "int", got "str"
113
114 [case testIncrCacheProtocol2]
115 # num_build_steps: 3
116 import a
117 [file a.py]
118 import b
119 from typing import Protocol
120 class P(Protocol):
121 x: int
122 class Q(Protocol):
123 x: int
124 def f() -> None:
125 def g(x: P) -> None:
126 pass
127 g(b.C())
128 [file c.py]
129 [file c.py.2]
130 # uh
131 [file c.py.3]
132 from a import Q
133 import b
134 def f() -> None:
135 def g(x: Q) -> None:
136 pass
137 g(b.C())
138 [file b.py]
139 class C:
140 x: int
141 [file b.py.4]
142 class C:
143 x: str
144 -- If we did a *full* reload (because the proto cache failed to load),
145 -- nothing would show up as stale
146 [stale3 b]
147 [rechecked3 a, b, c]
148 [out]
149 ==
150 ==
151 ==
152 c.py:6: error: Argument 1 to "g" has incompatible type "C"; expected "Q"
153 c.py:6: note: Following member(s) of "C" have conflicts:
154 c.py:6: note: x: expected "int", got "str"
155 a.py:10: error: Argument 1 to "g" has incompatible type "C"; expected "P"
156 a.py:10: note: Following member(s) of "C" have conflicts:
157 a.py:10: note: x: expected "int", got "str"
158
159 [case testIncrCacheProtocol3]
160 # num_build_steps: 2
161 import a
162 [file a.py]
163 import b
164 from typing import Protocol
165 class P(Protocol):
166 x: int
167 def f() -> None:
168 def g(x: P) -> None:
169 pass
170 g(b.C())
171 [file c.py]
172 [file c.py.2]
173 # yo
174 [file b.py]
175 class C:
176 x: int
177 [file b.py.3]
178 class C:
179 x: int
180 y: int
181 [file b.py.4]
182 class C:
183 x: str
184 y: int
185 -- If we did a *full* reload (because the proto cache failed to load),
186 -- nothing would show up as stale
187 [stale2 b]
188 [rechecked2 b]
189 [stale3 b]
190 [rechecked3 a, b]
191 [out]
192 ==
193 ==
194 ==
195 a.py:8: error: Argument 1 to "g" has incompatible type "C"; expected "P"
196 a.py:8: note: Following member(s) of "C" have conflicts:
197 a.py:8: note: x: expected "int", got "str"
198
199 [case testIncrCacheBustedProtocol]
200 # flags: --no-sqlite-cache
201 [file a.py]
202 [file b.py]
203 -- This is a heinous hack, but we simulate having a invalid cache by clobbering
204 -- the proto deps file with something with mtime mismatches.
205 [file ../.mypy_cache/3.10/@deps.meta.json.2]
206 {"snapshot": {"__main__": "a7c958b001a45bd6a2a320f4e53c4c16", "a": "d41d8cd98f00b204e9800998ecf8427e", "b": "d41d8cd98f00b204e9800998ecf8427e", "builtins": "c532c89da517a4b779bcf7a964478d67"}, "deps_meta": {"@root": {"path": "@root.deps.json", "mtime": 0}, "__main__": {"path": "__main__.deps.json", "mtime": 0}, "a": {"path": "a.deps.json", "mtime": 0}, "b": {"path": "b.deps.json", "mtime": 0}, "builtins": {"path": "builtins.deps.json", "mtime": 0}}}
207
208 [file b.py.2]
209 # uh
210 -- A full reload shows up as nothing getting rechecked by fine-grained mode.
211 -- If we did not do a full reload, b would be stale and checked in fine-grained mode
212 [stale]
213 [rechecked]
214 [out]
215 ==
216
217 [case testInvalidateCachePart]
218 # flags: --no-sqlite-cache
219 # cmd: mypy a1.py a2.py b.py p/__init__.py p/c.py
220 [file a1.py]
221 import p
222 from b import x
223 from p.c import C
224
225 [file a2.py]
226 import p
227 from b import x
228 from p.c import C
229
230 [file b.py]
231 x = 10
232
233 [file p/__init__.py]
234 [file p/c.py]
235 class C: pass
236
237 [delete ../.mypy_cache/3.10/b.meta.ff.2]
238 [delete ../.mypy_cache/3.10/p/c.meta.ff.2]
239
240 [out]
241 ==