Skip to content

Commit

Permalink
Merge pull request #107 from callowayproject/97-search-with-caret-in-…
Browse files Browse the repository at this point in the history
…regex

Added a test case for line-start regexes
  • Loading branch information
coordt authored Dec 18, 2023
2 parents e52c683 + ef4823c commit daa5268
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/fixtures/regex_with_caret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1.0.0
dependencies:
- name: kube-prometheus-stack
version: 1.0.0
8 changes: 8 additions & 0 deletions tests/fixtures/regex_with_caret_config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[tool.bumpversion]
current_version = "1.0.0"
regex = true

[[tool.bumpversion.files]]
filename = "thingy.yaml"
search = "^version: {current_version}"
replace = "version: {new_version}"
25 changes: 25 additions & 0 deletions tests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,31 @@ def test_regex_search_with_escaped_chars(tmp_path: Path) -> None:
assert version_path.read_text() == f"## [Release] 1.2.4 {now}"


def test_regex_search_with_caret(tmp_path: Path, fixtures_path: Path) -> None:
"""A search that uses a caret to indicate the beginning of the line works correctly."""
# Arrange
config_path = tmp_path / ".bumpversion.toml"
thingy_path = tmp_path / "thingy.yaml"
shutil.copyfile(fixtures_path / "regex_with_caret.yaml", thingy_path)
shutil.copyfile(fixtures_path / "regex_with_caret_config.toml", config_path)

conf = config.get_configuration(config_file=config_path)
version_config = VersionConfig(conf.parse, conf.serialize, conf.search, conf.replace, conf.parts)
current_version = version_config.parse(conf.current_version)
new_version = current_version.bump("patch", version_config.order)

with inside_dir(tmp_path):
cfg_files = [files.ConfiguredFile(file_cfg, version_config) for file_cfg in conf.files]

# Act
files.modify_files(cfg_files, current_version, new_version, get_context(conf))

# Assert
assert (
thingy_path.read_text() == "version: 1.0.1\ndependencies:\n- name: kube-prometheus-stack\n version: 1.0.0\n"
)


def test_bad_regex_search(tmp_path: Path, caplog) -> None:
"""A search string not meant to be a regex is still found and replaced."""
# Arrange
Expand Down

0 comments on commit daa5268

Please sign in to comment.