Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a test case for line-start regexes #107

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading