Skip to content

Commit

Permalink
Fix commas in legacy multiline options
Browse files Browse the repository at this point in the history
  • Loading branch information
ziima committed Mar 12, 2024
1 parent e13b0f0 commit 62dfe8e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
7 changes: 5 additions & 2 deletions bumpversion/autocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@ def listify(s: str) -> list:
Returns:
List of homogenous basic types.
"""
if "," not in s and "\n" not in s:
if "\n" in s:
str_list = s.strip().split("\n")
elif "," in s:
str_list = s.strip().split(",")
else:
raise ValueError("Not a List")

# derive the type of the variable
str_list = s.strip().split(",") if "," in s else s.strip().split("\n")
element_caster = str
for caster in (boolify, int, float, noneify, element_caster):
with contextlib.suppress(ValueError):
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/legacy_multiline_search_comma.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[bumpversion]
current_version = 1.0.0

[bumpversion:file:MULTILINE_SEARCH.md]
search = **unreleased**,
**v{current_version}**,
replace = **unreleased**,
**v{new_version}**,
11 changes: 11 additions & 0 deletions tests/fixtures/legacy_multiline_search_comma_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"current_version": "1.0.0",
"files": [
{
"filename": "MULTILINE_SEARCH.md",
"search": "**unreleased**,\n**v{current_version}**,",
"replace": "**unreleased**,\n**v{new_version}**,"
}
],
"parts": {}
}
2 changes: 2 additions & 0 deletions tests/test_autocast.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def test_noneify():
param("1,2,3,4", [1, 2, 3, 4], id="int"),
param("1\n2\n3\n4", [1, 2, 3, 4], id="int"),
param("s,t,r", ["s", "t", "r"], id="str"),
param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str_newline"),
param("1.1,2,3.14", [1.1, 2.0, 3.14], id="float"),
param("True,False,true,false", [True, False, True, False], id="bool"),
param("None,None,None", [None, None, None], id="none"),
Expand Down Expand Up @@ -75,6 +76,7 @@ def test_listify_invalid():
param("False", False, id="False"),
param("1,2,3,4", [1, 2, 3, 4], id="int-list"),
param("s,t,r", ["s", "t", "r"], id="str-list"),
param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str-list-newline"),
param("1", 1, id="int"),
param("1.0", 1.0, id="float"),
param(1, 1, id="real-int"),
Expand Down
5 changes: 5 additions & 0 deletions tests/test_config/test_files_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def cfg_file(request) -> str:
[
param("basic_cfg.cfg", "basic_cfg_expected.json", id="ini basic cfg"),
param("legacy_multiline_search.cfg", "legacy_multiline_search_expected.json", id="multiline search cfg"),
param(
"legacy_multiline_search_comma.cfg",
"legacy_multiline_search_comma_expected.json",
id="multiline search comma cfg",
),
],
)
def test_read_ini_file(conf_file: str, expected_file: str, fixtures_path: Path) -> None:
Expand Down

0 comments on commit 62dfe8e

Please sign in to comment.