| 1 | import os |
| 2 | |
| 3 | import pytest |
| 4 | |
| 5 | from installer.__main__ import _get_scheme_dict as get_scheme_dict |
| 6 | from installer.__main__ import _main as main |
| 7 | |
| 8 | |
| 9 | def test_get_scheme_dict(): |
| 10 | d = get_scheme_dict(distribution_name="foo") |
| 11 | assert set(d.keys()) >= {"purelib", "platlib", "headers", "scripts", "data"} |
| 12 | |
| 13 | |
| 14 | def test_get_scheme_dict_prefix(): |
| 15 | d = get_scheme_dict(distribution_name="foo", prefix="/foo") |
| 16 | for key in ("purelib", "platlib", "headers", "scripts", "data"): |
| 17 | assert d[key].startswith(f"{os.sep}foo"), ( |
| 18 | f"{key} does not start with /foo: {d[key]}" |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | def test_main(fancy_wheel, tmp_path): |
| 23 | destdir = tmp_path / "dest" |
| 24 | |
| 25 | main([str(fancy_wheel), "-d", str(destdir)], "python -m installer") |
| 26 | |
| 27 | installed_py_files = destdir.rglob("*.py") |
| 28 | |
| 29 | assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} |
| 30 | |
| 31 | installed_pyc_files = destdir.rglob("*.pyc") |
| 32 | assert {f.name.split(".")[0] for f in installed_pyc_files} == { |
| 33 | "__init__", |
| 34 | "__main__", |
| 35 | } |
| 36 | |
| 37 | |
| 38 | def test_main_multiple_wheels(fancy_wheel, another_fancy_wheel, tmp_path): |
| 39 | destdir = tmp_path / "dest" |
| 40 | |
| 41 | main( |
| 42 | [str(fancy_wheel), str(another_fancy_wheel), "-d", str(destdir)], |
| 43 | "python -m installer", |
| 44 | ) |
| 45 | |
| 46 | for wheel_name in ("fancy", "another_fancy"): |
| 47 | installed_py_files = destdir.rglob(f"**/{wheel_name}/**/*.py") |
| 48 | assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} |
| 49 | |
| 50 | installed_pyc_files = destdir.rglob(f"**/{wheel_name}/**/*.pyc") |
| 51 | assert {f.name.split(".")[0] for f in installed_pyc_files} == { |
| 52 | "__init__", |
| 53 | "__main__", |
| 54 | } |
| 55 | |
| 56 | |
| 57 | def test_main_prefix(fancy_wheel, tmp_path): |
| 58 | destdir = tmp_path / "dest" |
| 59 | |
| 60 | main([str(fancy_wheel), "-d", str(destdir), "-p", "/foo"], "python -m installer") |
| 61 | |
| 62 | installed_py_files = list(destdir.rglob("*.py")) |
| 63 | |
| 64 | for f in installed_py_files: |
| 65 | assert str(f.parent).startswith(str(destdir / "foo")), ( |
| 66 | f"path does not respect destdir+prefix: {f}" |
| 67 | ) |
| 68 | assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} |
| 69 | |
| 70 | installed_pyc_files = destdir.rglob("*.pyc") |
| 71 | assert {f.name.split(".")[0] for f in installed_pyc_files} == { |
| 72 | "__init__", |
| 73 | "__main__", |
| 74 | } |
| 75 | |
| 76 | |
| 77 | def test_main_no_pyc(fancy_wheel, tmp_path): |
| 78 | destdir = tmp_path / "dest" |
| 79 | |
| 80 | main( |
| 81 | [str(fancy_wheel), "-d", str(destdir), "--no-compile-bytecode"], |
| 82 | "python -m installer", |
| 83 | ) |
| 84 | |
| 85 | installed_py_files = destdir.rglob("*.py") |
| 86 | |
| 87 | assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} |
| 88 | |
| 89 | installed_pyc_files = destdir.rglob("*.pyc") |
| 90 | assert set(installed_pyc_files) == set() |
| 91 | |
| 92 | |
| 93 | @pytest.mark.parametrize( |
| 94 | "validation_part", |
| 95 | ["all", "entries", "none"], |
| 96 | ) |
| 97 | def test_main_validate_record_all_pass(fancy_wheel, tmp_path, validation_part): |
| 98 | destdir = tmp_path / "dest" |
| 99 | |
| 100 | main( |
| 101 | [str(fancy_wheel), "-d", str(destdir), "--validate-record", validation_part], |
| 102 | "python -m installer", |
| 103 | ) |
| 104 | |
| 105 | installed_py_files = destdir.rglob("*.py") |
| 106 | |
| 107 | assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} |
| 108 | |
| 109 | installed_pyc_files = destdir.rglob("*.pyc") |
| 110 | assert {f.name.split(".")[0] for f in installed_pyc_files} == { |
| 111 | "__init__", |
| 112 | "__main__", |
| 113 | } |