def test_sync_pipfile_but_lockfile_missing(tmp_path): """ expected behavior: if the user uses `pipenv-setup sync --pipfile`, the absence of a lockfile should not fail the command """ with data("missing_lockfile_0", tmp_path) as path: cmd(["", "sync", "--pipfile"])
def test_only_setup_missing( capsys, tmp_path, shared_datadir, source_pipfile_dirname, update_count ): # type: (Any, Path, Path, str, int) -> None """ test generate setup.py (when it is missing) """ pipfile_dir = shared_datadir / source_pipfile_dirname with data(source_pipfile_dirname, tmp_path): # delete the setup.py file that was copied to the tmp_path (tmp_path / "setup.py").unlink() cmd(argv=["", "sync"]) generated_setup = Path("setup.py") assert generated_setup.exists() generated_setup_text = generated_setup.read_text() expected_setup_text = Path("setup.py").read_text() for kw_arg_names in ("install_requires", "dependency_links"): assert compare_list_of_string_kw_arg( generated_setup_text, expected_setup_text, kw_arg_names, ordering_matters=False, ) captured = capsys.readouterr() assert msg_formatter.generate_success(update_count) in captured.out, captured.out
def test_sync_pipfile_no_original(capsys, tmp_path, shared_datadir, source_pipfile_dirname, update_count): """ sync --pipfile should reference Pipfile (not Pipfile.lock) when printing results """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with data(str(pipfile_dir), tmp_path) as path: setup_file = path / "setup.py" # type: Path cmd(["", "sync", "--pipfile"]) text = setup_file.read_text() generated_setup = Path("setup.py") assert generated_setup.exists() generated_setup_text = generated_setup.read_text() expected_setup_text = Path("setup.py").read_text() for kw_arg_names in ("install_requires", "dependency_links"): assert compare_list_of_string_kw_arg( generated_setup_text, expected_setup_text, kw_arg_names, ordering_matters=False, ) captured = capsys.readouterr() assert "Pipfile.lock" not in captured.out, captured.out assert "Pipfile" in captured.out, captured.out
def test_update( capsys, tmp_path, shared_datadir, source_pipfile_dirname, update_count ): # type: (Any, Path, Path, str, int) -> None """ test updating setup.py (when it already exists) """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with data(source_pipfile_dirname, tmp_path): cmd(argv=["", "sync"]) generated_setup = Path("setup.py") assert generated_setup.exists() generated_setup_text = generated_setup.read_text() expected_setup_text = Path("setup.py").read_text() for kw_arg_names in ("install_requires", "dependency_links"): assert compare_list_of_string_kw_arg( generated_setup_text, expected_setup_text, kw_arg_names, ordering_matters=False, ) captured = capsys.readouterr() assert msg_formatter.update_success(update_count) in captured.out
def test_check_lockfile_vcs_branch( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ When Pipfile specifies a VCS dependency with a `ref` that is a mutable reference (e.g. - a branch, not a tag or a commit hash), `setup.py` gets updated with the resolved `sha` of that branch from Pipfile.lock. This causes `check` to fail b/c setup.py doesn't match Pipfile. The `--lockfile` flag allows checking against `Pipefile.lock` instead, which fixes this check. """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py") with cwd(tmp_path): # Check will fail b/c `master` branch resolves to commit sha in setup.py with pytest.raises(SystemExit) as e: cmd(argv=["", "check"]) assert e.value.code == 1 # `check --lockfile` will pass because Pipfile.lock also has the resolved sha cmd(argv=["", "check", "--lockfile"])
def test_help_text(capsys): cmd(argv=[""]) captured = capsys.readouterr() assert "Commands:" in captured.out assert "sync" in captured.out assert "check" in captured.out assert captured.err == ""
def test_sync_dev_no_original(tmp_path): """ sync --dev should add extras_require: {"dev": [blah]} in the absence of a extras_require keyword """ with data("generic_nice_1", tmp_path) as path: setup_file = path / "setup.py" # type: Path cmd(["", "sync", "--dev"]) text = setup_file.read_text() assert "gitdir==1.1.3" in text
def test_sync_underscore_or_dash(shared_datadir): """ sync --pipfile should work for either dash or underscore names. No need to run any assertions; we are testing that no error is raised. Asserts fix for https://github.com/Madoshakalaka/pipenv-setup/issues/72. """ with data("dash_or_underscore_0", shared_datadir / "dash_or_underscore_0"): cmd(["", "sync", "--pipfile"]) cmd(["", "check"])
def test_sync_dev_original_other_extras(tmp_path): """ sync --dev should update extras_require: {"dev": [blah]} in place when there is existing extras_require """ # todo: better test with data("generic_nice_2", tmp_path) as path: setup_file = path / "setup.py" # type: Path cmd(["", "sync", "--dev"]) text = setup_file.read_text() print(text) assert "gitdir==1.1.3" in text assert "pytest" in text
def test_sync_dev_pipfile_no_original(tmp_path): """ sync --dev --pipfile should add extras_require: {"dev": [blah]} in the absence of an extras_require keyword """ # todo: this test is too simple with data("self_0", tmp_path) as path: setup_file = path / "setup.py" # type: Path cmd(["", "sync", "--dev", "--pipfile"]) text = setup_file.read_text() assert "pytest~=5.1" in text, text assert "requirementslib~=1.5" in text, text
def test_sync_no_setup_call( tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Path, Path, str) -> None """ when setup call is not found, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "sync"]) assert e.value.code == 1
def test_sync_lock_file_package_broken( tmp_path, shared_datadir, source_pipfile_dirname): # type: (Path, Path, str) -> None """ when Pipfile.lock is missing, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "sync"]) assert e.value.code == 1
def test_check_file_install_requires_missing( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ when Pipfile.lock is missing, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py") with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check"]) assert e.value.code == 1
def test_check_file_many_conflicts( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ many conflicts, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check"]) assert e.value.code == 1
def test_sync_lock_file_missing_messages( capfd, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ when pipfile is missing, there should be error msgs """ pipfile_dir = shared_datadir / source_pipfile_dirname copy_file(pipfile_dir / "Pipfile", tmp_path) # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py") with cwd(tmp_path): with pytest.raises(SystemExit): cmd(argv=["", "sync"]) captured = capfd.readouterr() assert msg_formatter.no_sync_performed() in captured.err assert msg_formatter.missing_file(Path("Pipfile.lock")) in captured.err
def test_check_file_missing_exit_code( capfd, tmp_path, shared_datadir, source_pipfile_dirname, missing_filenames ): # type: (Any, Path, Path, str, List[str]) -> None """ when Pipfile.lock is missing, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ["Pipfile", "Pipfile.lock", "setup.py"]: file = pipfile_dir / filename if filename not in missing_filenames: copy_file(file, tmp_path) # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py") with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check"]) assert e.value.code == 1
def test_check_file_strict( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ when --strict flag is passed. compatible but not identical versioning should fail """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check", "--strict"]) assert e.value.code == 1 cmd(argv=["", "check"]) captured = capsys.readouterr() assert msg_formatter.checked_no_problem() in captured.out
def test_check_file_ignore_local( capsys, tmp_path, shared_datadir, source_pipfile_dirname ): # type: (Any, Path, Path, str) -> None """ when Pipfile.lock is missing, return code should be one """ pipfile_dir = shared_datadir / source_pipfile_dirname for filename in ("Pipfile", "Pipfile.lock", "setup.py"): copy_file(pipfile_dir / filename, tmp_path) # copy_file(shared_datadir / "minimal_empty_setup.py", tmp_path, "setup.py") with cwd(tmp_path): with pytest.raises(SystemExit) as e: cmd(argv=["", "check"]) assert e.value.code == 1 cmd(argv=["", "check", "--ignore-local"]) captured = capsys.readouterr() assert msg_formatter.checked_no_problem() in captured.out
def test_generation(tmp_path, shared_datadir, source_pipfile_dirname): # type: (Path, Path, str) -> None """ test boilerplate """ pipfile_dir = shared_datadir / source_pipfile_dirname copy_pipfiles(pipfile_dir, tmp_path) with data(source_pipfile_dirname, tmp_path): cmd(argv=["", "sync"]) generated_setup = Path("setup.py") assert generated_setup.exists() generated_setup_text = generated_setup.read_text() expected_setup_text = Path("setup.py").read_text() for kw_arg_names in ("install_requires", "dependency_links"): assert compare_list_of_string_kw_arg( generated_setup_text, expected_setup_text, kw_arg_names, ordering_matters=False, )
""" this file gives an alternative of using `python -m pipenv_setup` """ from pipenv_setup.main import cmd if __name__ == "__main__": cmd()