|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import pytest
|
2 |
| -from pytest import param |
| 4 | +from click import UsageError |
| 5 | +from pytest import LogCaptureFixture, param |
3 | 6 |
|
4 | 7 | from bumpversion import config, exceptions
|
5 | 8 | from bumpversion.utils import get_context
|
6 | 9 | from bumpversion.version_part import VersionPart
|
7 |
| -from tests.conftest import get_config_data |
| 10 | +from tests.conftest import get_config_data, inside_dir |
8 | 11 |
|
9 | 12 |
|
10 | 13 | @pytest.fixture(
|
@@ -274,3 +277,24 @@ def test_part_first_value(initial: str, bump_type: str, expected: str):
|
274 | 277 |
|
275 | 278 | new_version = current_version.bump(bump_type, version_config.order)
|
276 | 279 | assert version_config.serialize(new_version, get_context(conf)) == expected
|
| 280 | + |
| 281 | + |
| 282 | +def test_version_part_invalid_regex_exit(tmp_path: Path) -> None: |
| 283 | + """A version part with an invalid regex should raise an exception.""" |
| 284 | + # Arrange |
| 285 | + overrides = { |
| 286 | + "current_version": "12", |
| 287 | + "parse": "*kittens*", |
| 288 | + } |
| 289 | + with inside_dir(tmp_path): |
| 290 | + with pytest.raises(UsageError): |
| 291 | + get_config_data(overrides) |
| 292 | + |
| 293 | + |
| 294 | +def test_parse_doesnt_parse_current_version(tmp_path: Path, caplog: LogCaptureFixture) -> None: |
| 295 | + """A warning should be output when the parse regex doesn't parse the version.""" |
| 296 | + overrides = {"current_version": "12", "parse": "xxx"} |
| 297 | + with inside_dir(tmp_path): |
| 298 | + get_config_data(overrides) |
| 299 | + |
| 300 | + assert caplog.messages == ["Evaluating 'parse' option: 'xxx' does not parse current version '12'"] |
0 commit comments