Skip to content

Commit 9cb8f60

Browse files
committed
Added utf8 test in files
1 parent fe794dd commit 9cb8f60

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/test_files.py

+46
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,49 @@ def test_non_matching_search_does_not_modify_file(tmp_path: Path):
254254
files.modify_files(configured_files, current_version, new_version, get_context(conf))
255255

256256
assert changelog_path.read_text() == changelog_content
257+
258+
259+
def test_simple_replacement_in_utf8_file(tmp_path: Path):
260+
"""Changing a file in UTF-8 should not change the non-ASCII characters."""
261+
# Arrange
262+
version_path = tmp_path / "VERSION"
263+
version_path.write_bytes("Kröt1.3.0".encode())
264+
265+
overrides = {"current_version": "1.3.0", "files": [{"filename": str(version_path)}]}
266+
with inside_dir(tmp_path):
267+
conf, version_config, current_version = get_config_data(overrides)
268+
new_version = current_version.bump("patch", version_config.order)
269+
270+
# Act
271+
for file_cfg in conf.files:
272+
cfg_file = files.ConfiguredFile(file_cfg, version_config)
273+
cfg_file.replace_version(current_version, new_version, get_context(conf))
274+
275+
# Assert
276+
out = version_path.read_text()
277+
assert out == "Kröt1.3.1"
278+
279+
280+
def test_multi_line_search_is_found(tmp_path: Path) -> None:
281+
"""A multiline search string is found and replaced."""
282+
# Arrange
283+
alphabet_path = tmp_path / "the_alphabet.txt"
284+
alphabet_path.write_text("A\nB\nC\n")
285+
286+
overrides = {
287+
"current_version": "9.8.7",
288+
"search": "A\nB\nC",
289+
"replace": "A\nB\nC\n{new_version}",
290+
"files": [{"filename": str(alphabet_path)}],
291+
}
292+
with inside_dir(tmp_path):
293+
conf, version_config, current_version = get_config_data(overrides)
294+
new_version = current_version.bump("major", version_config.order)
295+
296+
# Act
297+
for file_cfg in conf.files:
298+
cfg_file = files.ConfiguredFile(file_cfg, version_config)
299+
cfg_file.replace_version(current_version, new_version, get_context(conf))
300+
301+
# Assert
302+
assert alphabet_path.read_text() == "A\nB\nC\n10.0.0\n"

0 commit comments

Comments
 (0)