diff options
Diffstat (limited to 'tests/test_main.py')
-rw-r--r-- | tests/test_main.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/test_main.py b/tests/test_main.py new file mode 100644 index 0000000..391a13d --- /dev/null +++ b/tests/test_main.py @@ -0,0 +1,69 @@ +import os + +from installer.__main__ import _get_scheme_dict as get_scheme_dict +from installer.__main__ import _main as main + + +def test_get_scheme_dict(): + d = get_scheme_dict(distribution_name="foo") + assert set(d.keys()) >= {"purelib", "platlib", "headers", "scripts", "data"} + + +def test_get_scheme_dict_prefix(): + d = get_scheme_dict(distribution_name="foo", prefix="/foo") + for key in ("purelib", "platlib", "headers", "scripts", "data"): + assert d[key].startswith( + f"{os.sep}foo" + ), f"{key} does not start with /foo: {d[key]}" + + +def test_main(fancy_wheel, tmp_path): + destdir = tmp_path / "dest" + + main([str(fancy_wheel), "-d", str(destdir)], "python -m installer") + + installed_py_files = destdir.rglob("*.py") + + assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} + + installed_pyc_files = destdir.rglob("*.pyc") + assert {f.name.split(".")[0] for f in installed_pyc_files} == { + "__init__", + "__main__", + } + + +def test_main_prefix(fancy_wheel, tmp_path): + destdir = tmp_path / "dest" + + main([str(fancy_wheel), "-d", str(destdir), "-p", "/foo"], "python -m installer") + + installed_py_files = list(destdir.rglob("*.py")) + + for f in installed_py_files: + assert str(f.parent).startswith( + str(destdir / "foo") + ), f"path does not respect destdir+prefix: {f}" + assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} + + installed_pyc_files = destdir.rglob("*.pyc") + assert {f.name.split(".")[0] for f in installed_pyc_files} == { + "__init__", + "__main__", + } + + +def test_main_no_pyc(fancy_wheel, tmp_path): + destdir = tmp_path / "dest" + + main( + [str(fancy_wheel), "-d", str(destdir), "--no-compile-bytecode"], + "python -m installer", + ) + + installed_py_files = destdir.rglob("*.py") + + assert {f.stem for f in installed_py_files} == {"__init__", "__main__", "data"} + + installed_pyc_files = destdir.rglob("*.pyc") + assert set(installed_pyc_files) == set() |