-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathtest_module.py
More file actions
34 lines (26 loc) · 866 Bytes
/
test_module.py
File metadata and controls
34 lines (26 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Smoke test: obfuscated output must execute and preserve semantics."""
import textwrap
from python_obfuscator import ObfuscationConfig, Obfuscator, obfuscate
def test_default_obfuscation_preserves_computation() -> None:
source = textwrap.dedent(
"""\
v1 = 0
v2 = 0
v4 = 10
assert v4 + v4 == 20
assert v1 + v2 == 0
"""
)
result = obfuscate(source)
exec(result) # must not raise
def test_obfuscator_class_smoke() -> None:
o = Obfuscator()
result = o.obfuscate("x = 1 + 2")
assert isinstance(result, str)
def test_obfuscator_with_subset_config() -> None:
cfg = ObfuscationConfig.only("string_hex_encoder")
result = obfuscate('greeting = "hello"', config=cfg)
assert "fromhex" in result
ns: dict = {}
exec(result, ns)
assert ns["greeting"] == "hello"