|
5 | 5 | from textwrap import dedent
|
6 | 6 |
|
7 | 7 | import pytest
|
| 8 | +from click.testing import CliRunner, Result |
8 | 9 | from pytest import param
|
9 | 10 |
|
10 | 11 | from bumpversion import config
|
@@ -194,3 +195,54 @@ def test_update_config_file(tmp_path: Path, cfg_file_name: str, expected_diff: s
|
194 | 195 | new_content = cfg_path.read_text().splitlines(keepends=True)
|
195 | 196 | difference = difflib.context_diff(original_content, new_content, n=0)
|
196 | 197 | assert "".join(difference) == expected_diff
|
| 198 | + |
| 199 | + |
| 200 | +def test_pep440_config(git_repo: Path, fixtures_path: Path): |
| 201 | + """ |
| 202 | + Check the PEP440 config file. |
| 203 | + """ |
| 204 | + from bumpversion.utils import get_context |
| 205 | + from bumpversion.bump import get_next_version |
| 206 | + from bumpversion import cli |
| 207 | + import subprocess |
| 208 | + |
| 209 | + # Arrange |
| 210 | + |
| 211 | + cfg_path = git_repo / "pyproject.toml" |
| 212 | + orig_path = fixtures_path / "pep440.toml" |
| 213 | + cfg_path.write_text(orig_path.read_text()) |
| 214 | + version_path = git_repo / "VERSION" |
| 215 | + version_path.write_text("1.0.0") |
| 216 | + readme_path = git_repo / "README.md" |
| 217 | + runner: CliRunner = CliRunner() |
| 218 | + |
| 219 | + with inside_dir(git_repo): |
| 220 | + subprocess.run(["git", "add", "VERSION"], check=True, capture_output=True) |
| 221 | + subprocess.run(["git", "commit", "-m", "initial commit"], check=True, capture_output=True) |
| 222 | + subprocess.run(["git", "tag", "v1.0.0"], check=True, capture_output=True) |
| 223 | + |
| 224 | + cfg = config.get_configuration(cfg_path) |
| 225 | + ctx = get_context(cfg) |
| 226 | + version = cfg.version_config.parse(cfg.current_version) |
| 227 | + next_version = get_next_version(version, cfg, "patch", None) |
| 228 | + next_version_str = cfg.version_config.serialize(next_version, ctx) |
| 229 | + assert next_version_str == "1.0.1" |
| 230 | + |
| 231 | + subprocess.run(["git", "checkout", "-b", "my-really-LONG-branch_name"], check=True, capture_output=True) |
| 232 | + readme_path.write_text("This is my branch!") |
| 233 | + result: Result = runner.invoke(cli.cli, ["bump", "dev_label", "--no-tag"]) |
| 234 | + assert result.exit_code == 0 |
| 235 | + cfg = config.get_configuration(cfg_path) |
| 236 | + assert cfg.current_version == "1.0.0.dev0+myreallylongbranchna" |
| 237 | + |
| 238 | + # try: |
| 239 | + # subprocess.run(["git", "add", "README.md"], check=True, capture_output=True) |
| 240 | + # subprocess.run(["git", "commit", "-am", "my branch commit"], check=True, capture_output=True) |
| 241 | + # except subprocess.CalledProcessError as e: |
| 242 | + # print(e.stdout) |
| 243 | + # print(e.stderr) |
| 244 | + # raise |
| 245 | + # result: Result = runner.invoke(cli.cli, ["bump", "dev_label", "--no-tag"]) |
| 246 | + # assert result.exit_code == 0 |
| 247 | + # cfg = config.get_configuration(cfg_path) |
| 248 | + # assert cfg.current_version == "1.0.0.dev1+myreallylongbranchna" |
0 commit comments