From 23be62deed9fb7d51a8bbc195433d1a4ce74c11f Mon Sep 17 00:00:00 2001 From: Corey Oordt Date: Mon, 12 Jun 2023 08:46:56 -0500 Subject: [PATCH] Updated tests for bad version parts --- tests/test_cli.py | 72 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 80b93cd2..59b5a31c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -153,8 +153,8 @@ def test_dirty_work_dir_raises_error(repo: str, scm_command: str, request): assert "working directory is not clean" in result.output -def test_listing_outputs_correctly_and_stops(tmp_path: Path, fixtures_path: Path): - """The --list option should list the configuration and nothing else.""" +def test_listing_with_version_part(tmp_path: Path, fixtures_path: Path): + """The --list option should list the configuration with new_version..""" # Arrange config_path = tmp_path / "pyproject.toml" toml_path = fixtures_path / "basic_cfg.toml" @@ -193,6 +193,45 @@ def test_listing_outputs_correctly_and_stops(tmp_path: Path, fixtures_path: Path } +def test_listing_without_version_part(tmp_path: Path, fixtures_path: Path): + """The --list option should list the configuration without new_version.""" + # Arrange + config_path = tmp_path / "pyproject.toml" + toml_path = fixtures_path / "basic_cfg.toml" + shutil.copy(toml_path, config_path) + runner: CliRunner = CliRunner() + + with inside_dir(tmp_path): + result: Result = runner.invoke(cli.cli, ["--list"]) + + if result.exit_code != 0: + print(result.output) + print(result.exception) + + assert result.exit_code == 0 + assert set(result.output.splitlines(keepends=False)) == { + "current_version=1.0.0", + "parse=(?P\\d+)\\.(?P\\d+)\\.(?P\\d+)(\\-(?P[a-z]+))?", + "serialize=['{major}.{minor}.{patch}-{release}', '{major}.{minor}.{patch}']", + "search={current_version}", + "replace={new_version}", + "tag=True", + "sign_tags=False", + "tag_name=v{new_version}", + "tag_message=Bump version: {current_version} → {new_version}", + "allow_dirty=False", + "commit=True", + "message=Bump version: {current_version} → {new_version}", + "commit_args=None", + "files=[{'filename': 'setup.py', 'glob': None, 'parse': None, 'serialize': " + "None, 'search': None, 'replace': None}, {'filename': " + "'bumpversion/__init__.py', 'glob': None, 'parse': None, 'serialize': None, " + "'search': None, 'replace': None}, {'filename': 'CHANGELOG.md', 'glob': None, " + "'parse': None, 'serialize': None, 'search': '**unreleased**', 'replace': " + "'**unreleased**\\n**v{new_version}**'}]", + } + + def test_non_scm_operations_if_scm_not_installed(tmp_path: Path, monkeypatch): """Everything works except SCM commands if the SCM is unusable.""" # Arrange @@ -209,3 +248,32 @@ def test_non_scm_operations_if_scm_not_installed(tmp_path: Path, monkeypatch): # Assert assert version_path.read_text() == "32.0.0" + + +@pytest.mark.parametrize( + ["version_part"], + [ + param("charlie", id="bad_version_part"), + param("", id="missing_version_part"), + ], +) +def test_detects_bad_or_missing_version_part(version_part: str, tmp_path: Path, monkeypatch): + """It properly detects bad or missing version part.""" + # Arrange + monkeypatch.setenv("PATH", "") + + with inside_dir(tmp_path): + version_path = tmp_path / "VERSION" + version_path.write_text("31.0.3") + + runner: CliRunner = CliRunner() + args = ["--current-version", "31.0.3"] + if version_part: + args.append(version_part) + args.append("VERSION") + # Act + result = runner.invoke(cli.cli, args) + + # Assert + assert result.exception is not None + assert "Unknown version part:" in result.stdout