Skip to content

Commit f260875

Browse files
fix: strip whitespace from site location name
When parsing site location strings, the `name` is now stripped of extra whitespace to prevent leading and trailing spaces from remaining if passed incorrectly. Updated corresponding unit tests. Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
1 parent 5a706cb commit f260875

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/enapter/cli/http/api/site_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
def parse_site_location(location_str: str) -> tuple[str, float, float]:
55
try:
66
name, lat_str, lon_str = location_str.split(",")
7-
return name, float(lat_str), float(lon_str)
7+
return name.strip(), float(lat_str), float(lon_str)
88
except ValueError:
99
raise argparse.ArgumentTypeError(
1010
"Location must be in the format NAME,LATITUDE,LONGITUDE"

tests/unit/test_cli/test_http/test_api/test_site_location.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ def test_parse_site_location_valid():
1010

1111

1212
def test_parse_site_location_with_spaces():
13-
# Note: name keeps whitespace, float() handles surrounding whitespace
13+
# Note: name strips whitespace, float() handles surrounding whitespace
1414
assert parse_site_location(" Berlin , 52.52 , 13.405 ") == (
15-
" Berlin ",
15+
"Berlin",
1616
52.52,
1717
13.405,
1818
)

0 commit comments

Comments
 (0)