Skip to content

Commit a47d1a6

Browse files
rustyconoverclaude
andcommitted
Make the import side-effect tests pass on Windows and under mypy tests/
The first cut failed CI in two places, neither in the fix itself: - mypy tests/ (which CI runs, alongside mypy vgi/) flagged four `type: ignore[type-var]` comments as unused. - On Windows, test_storage_is_still_created_on_first_use looked for the database under the temporary HOME, but platformdirs asks Windows for its folders directly and ignores HOME and XDG there, so the store landed in the real LOCAL_APPDATA. The isolated environment now also sets platformdirs' WIN_PD_OVERRIDE_LOCAL_APPDATA and WIN_PD_OVERRIDE_APPDATA. The import test also now asserts, inside the subprocess, that the storage descriptor was never resolved, reading it through Function.__dict__ so the read cannot resolve it either. That check does not depend on where any platform keeps its state directory. The import tests still fail on the pre-fix code. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 94df3e3 commit a47d1a6

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

‎tests/test_import_side_effects.py‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ def on_bind(cls, params):
4545
@classmethod
4646
def process(cls, params, state, out):
4747
out.finish()
48+
49+
50+
# The direct check, independent of where a platform keeps its state directory:
51+
# reading through __dict__ does not invoke the descriptor.
52+
from vgi.function import Function
53+
54+
assert Function.__dict__["storage"]._resolved is None, "storage was resolved during import"
4855
"""
4956

5057

@@ -59,6 +66,10 @@ def _isolated_env(home: Path) -> dict[str, str]:
5966
env["HOME"] = str(home)
6067
for name in ("XDG_STATE_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "XDG_CONFIG_HOME"):
6168
env[name] = str(home / name.lower())
69+
# platformdirs asks Windows for its folders directly and ignores HOME and
70+
# XDG there, but honors these overrides.
71+
for name in ("LOCAL_APPDATA", "APPDATA"):
72+
env[f"WIN_PD_OVERRIDE_{name}"] = str(home / name.lower())
6273
return env
6374

6475

@@ -127,7 +138,7 @@ def test_a_concrete_class_is_validated(self) -> None:
127138
"""Control: without an abstract member, the invalid argument type is rejected."""
128139
with pytest.raises(TypeError, match="must be a dataclass"):
129140

130-
class Concrete(TableFunctionGenerator[_NotADataclass, None]): # type: ignore[type-var]
141+
class Concrete(TableFunctionGenerator[_NotADataclass, None]):
131142
@classmethod
132143
def on_bind(cls, params): # type: ignore[no-untyped-def]
133144
raise NotImplementedError
@@ -139,7 +150,7 @@ def process(cls, params, state, out): # type: ignore[no-untyped-def]
139150
def test_an_abstract_classmethod_marks_the_class_abstract(self) -> None:
140151
"""An inherited-concrete class that adds an abstract classmethod skips validation."""
141152

142-
class WithAbstractClassmethod(TableFunctionGenerator[_NotADataclass, None]): # type: ignore[type-var]
153+
class WithAbstractClassmethod(TableFunctionGenerator[_NotADataclass, None]):
143154
@classmethod
144155
def on_bind(cls, params): # type: ignore[no-untyped-def]
145156
raise NotImplementedError
@@ -158,7 +169,7 @@ def extra(cls) -> None:
158169
def test_an_abstract_staticmethod_marks_the_class_abstract(self) -> None:
159170
"""An abstract staticmethod is recognized through its raw attribute too."""
160171

161-
class WithAbstractStaticmethod(TableFunctionGenerator[_NotADataclass, None]): # type: ignore[type-var]
172+
class WithAbstractStaticmethod(TableFunctionGenerator[_NotADataclass, None]):
162173
@classmethod
163174
def on_bind(cls, params): # type: ignore[no-untyped-def]
164175
raise NotImplementedError
@@ -177,7 +188,7 @@ def extra() -> None:
177188
def test_an_abstract_property_marks_the_class_abstract(self) -> None:
178189
"""An abstract property is recognized through its raw attribute too."""
179190

180-
class WithAbstractProperty(TableFunctionGenerator[_NotADataclass, None]): # type: ignore[type-var]
191+
class WithAbstractProperty(TableFunctionGenerator[_NotADataclass, None]):
181192
@classmethod
182193
def on_bind(cls, params): # type: ignore[no-untyped-def]
183194
raise NotImplementedError

0 commit comments

Comments
 (0)