Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions pymini/pymini.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,8 @@ class VariableShortener(NodeTransformer):
# - attribute rewriting is limited to owners we can prove from the AST
# (`self`, `cls`, or known class names), not arbitrary dynamic receivers
#
# Keep regression coverage in tests/test_api.py and checked-in example
# outputs in sync via scripts/regenerate_examples.py whenever these rules
# change.
# Keep regression coverage in tests/test_api.py and the checked-in example
# outputs under tests/examples in sync whenever these rules change.
def __init__(
self,
generator,
Expand Down
72 changes: 0 additions & 72 deletions scripts/regenerate_examples.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/examples/pyminifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ def test(self, whatever):
if __name__ == "__main__":
print("Forming...")
f = Foo("epicaricacy", "perseverate")
f.test("Codswallop")
f.test("Codswallop")
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ class Foo(object):
def __init__(self,*args,**kwargs):0
def demiurgic_mystificator(self,dactyl):c=a.palpitation(dactyl);return b.dark_voodoo(c)
def test(self,whatever):print(whatever)
if __name__=='__main__':print('Forming...');c=Foo('epicaricacy','perseverate');c.test('Codswallop')
if __name__=='__main__':print('Forming...');c=Foo('epicaricacy','perseverate');c.test('Codswallop')
2 changes: 1 addition & 1 deletion tests/examples/pyminify.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ def handler(event, context):
l.exception('')
event['Status'] = 'FAILED'
event['Reason'] = str(ex)
return send(event)
return send(event)
2 changes: 1 addition & 1 deletion examples/pyminify.py → tests/examples/pyminify.pymini.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ def a(event,context):
else:raise RuntimeError('Unknown RequestType')
except Exception as b:l.exception('');j[f]='FAILED';j['Reason']=str(b);return q(j)
del (j,k,m,n,o,p,q,r,s)
handler=a
handler=a
40 changes: 32 additions & 8 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
import subprocess
import sys
from pathlib import Path

import pytest
from pymini import minify


ROOT = Path(__file__).resolve().parents[1]
EXAMPLES_DIR = ROOT / "tests" / "examples"
GENERATED_SUFFIX = ".pymini.py"
MINIFY_OPTIONS = {"keep_global_variables": True}


def generated_examples() -> dict[str, str]:
outputs: dict[str, str] = {}
for source_path in sorted(EXAMPLES_DIR.glob("*.py")):
if source_path.name.endswith(GENERATED_SUFFIX):
continue
cleaned, _ = minify(
source_path.read_text(encoding="utf-8"),
source_path.stem,
**MINIFY_OPTIONS,
)
outputs[source_path.name.removesuffix(".py") + GENERATED_SUFFIX] = cleaned[0]
return outputs


@pytest.mark.skipif(
sys.version_info < (3, 11),
reason="checked-in example output is canonicalized on Python 3.11+",
)
def test_checked_in_examples_match_regenerated_output():
result = subprocess.run(
[sys.executable, str(ROOT / "scripts" / "regenerate_examples.py"), "--check"],
cwd=ROOT,
capture_output=True,
text=True,
check=False,
mismatches = []
expected = generated_examples()
for name, source in expected.items():
output_path = EXAMPLES_DIR / name
if (
not output_path.exists()
or output_path.read_text(encoding="utf-8").rstrip("\n") != source.rstrip("\n")
):
mismatches.append(name)
extra_outputs = sorted(
path.name
for path in EXAMPLES_DIR.glob(f"*{GENERATED_SUFFIX}")
if path.name not in expected
)

assert result.returncode == 0, result.stdout + result.stderr
assert not (mismatches + extra_outputs), "\n".join(mismatches + extra_outputs)
Loading