()
| 40 | |
| 41 | |
| 42 | def test_compile_success(): |
| 43 | # type: () -> None |
| 44 | with compilation( |
| 45 | valid_paths=["a.py", "c/c.py"], |
| 46 | invalid_paths=["b.py", "d/d.py"], |
| 47 | compile_paths=["a.py", "c/c.py"], |
| 48 | ) as (root, compiled_relpaths): |
| 49 | |
| 50 | assert 2 == len(compiled_relpaths) |
| 51 | |
| 52 | results = {} |
| 53 | for compiled in compiled_relpaths: |
| 54 | compiled_abspath = os.path.join(root, compiled) |
| 55 | with open(compiled_abspath, "rb") as fp: |
| 56 | fp.read(4) # Skip the magic header. |
| 57 | if sys.version_info[:2] >= (3, 7): |
| 58 | # We're in PEP-552 mode: https://peps.python.org/pep-0552 |
| 59 | fp.read(4) # Skip the invalidation mode bitfield. |
| 60 | fp.read(4) # Skip the timestamp. |
| 61 | if compatibility.PY3: |
| 62 | fp.read(4) # Skip the size. |
| 63 | code = marshal.load(fp) |
| 64 | local_symbols = {} # type: Dict[str, str] |
| 65 | exec (code, {}, local_symbols) |
| 66 | results[compiled] = local_symbols |
| 67 | |
| 68 | assert {"basename": "a.py"} == results.pop("a.pyc") |
| 69 | assert {"basename": "c.py"} == results.pop("c/c.pyc") |
| 70 | assert 0 == len(results) |
| 71 | |
| 72 | |
| 73 | def test_compile_failure(): |
nothing calls this directly
no test coverage detected