Skip to content

Commit c48c53b

Browse files
committed
fix: tests
1 parent 5e5a992 commit c48c53b

4 files changed

Lines changed: 24 additions & 6 deletions

File tree

tests/obfuscator/conftest.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import builtins
66
import io
7-
import warnings
87
from base64 import b64decode
98
from dataclasses import dataclass, field
109
from pathlib import Path
@@ -79,6 +78,7 @@ class SourceFixture:
7978
name: str
8079
path: str
8180
expected_output: str
81+
error: str | None = None
8282

8383

8484
@dataclass
@@ -198,9 +198,16 @@ def discover_fixtures() -> list[SourceFixture]:
198198
source = path.read_text()
199199
expected_output = exec_capture(source, {"__builtins__": builtins})
200200
except Exception as exc: # noqa: BLE001
201-
warnings.warn(
202-
f"Skipping fixture {path.name}: {exc}",
203-
stacklevel=1,
201+
fixtures.append(
202+
SourceFixture(
203+
name=path.stem,
204+
path=str(path),
205+
expected_output="",
206+
error=(
207+
f"Fixture '{path.stem}' is invalid (pre-obfuscation): "
208+
f"{type(exc).__name__}: {exc}"
209+
),
210+
)
204211
)
205212
continue
206213
fixtures.append(

tests/obfuscator/fixtures/complex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def foo_yield(l):
136136
for i in l:
137137
yield i
138138

139-
x_foo_yield = foo_yield(list(range(1)))
139+
x_foo_yield = foo_yield(list(range(100)))
140140
print(next(x_foo_yield))
141141
print(next(x_foo_yield))
142142
print(next(x_foo_yield))

tests/obfuscator/fixtures/types.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, List, Dict, Final, Literal, Annotated
1+
from typing import Optional, List, Dict, Final, Literal, Annotated, Any
22

33
a: int = 42
44
b: float = 4.2
@@ -30,9 +30,14 @@ def print(self):
3030
print(self.foo2)
3131
print(self.foo3)
3232

33+
def l(self) -> List[Any]:
34+
return [self.foo1, self.foo2, self.foo3]
35+
3336

3437
Foo().print()
3538

39+
print(Foo().l())
40+
3641

3742
def foo_opt(a: Optional[int]) -> Optional[int]:
3843
if a is None:

tests/obfuscator/test_integration.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def test_output_matches(
3030
obfuscator_entry: ObfuscatorEntry,
3131
fixture_source: SourceFixture,
3232
) -> None:
33+
if fixture_source.error is not None:
34+
pytest.fail(fixture_source.error)
35+
3336
if not obfuscator_entry.is_output_preserving:
3437
return
3538

@@ -67,6 +70,9 @@ def test_valid_and_executes(
6770
obfuscator_entry: ObfuscatorEntry,
6871
fixture_source: SourceFixture,
6972
) -> None:
73+
if fixture_source.error is not None:
74+
pytest.fail(fixture_source.error)
75+
7076
if obfuscator_entry.is_output_preserving:
7177
return
7278

0 commit comments

Comments
 (0)