Skip to content

Commit 9b6dea0

Browse files
test: add tests for parse_site_location edge cases
Added unit tests to `tests/unit/test_cli/test_http/test_api/test_site_location.py` to cover `parse_site_location`. The tests cover standard string format, string containing spaces, exceptions handling incorrect lengths (too few or too many parameters), incorrect coordinate formats (non-float characters), and empty strings. Co-authored-by: rnovatorov <20299819+rnovatorov@users.noreply.github.com>
1 parent 4e14276 commit 9b6dea0

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import argparse
2+
3+
import pytest
4+
5+
from enapter.cli.http.api.site_location import parse_site_location
6+
7+
8+
def test_parse_site_location_valid():
9+
assert parse_site_location("Berlin,52.52,13.405") == ("Berlin", 52.52, 13.405)
10+
11+
12+
def test_parse_site_location_with_spaces():
13+
# Note: name keeps whitespace, float() handles surrounding whitespace
14+
assert parse_site_location(" Berlin , 52.52 , 13.405 ") == (
15+
" Berlin ",
16+
52.52,
17+
13.405,
18+
)
19+
20+
21+
def test_parse_site_location_too_few_parts():
22+
with pytest.raises(argparse.ArgumentTypeError) as exc_info:
23+
parse_site_location("Berlin,52.52")
24+
assert "Location must be in the format NAME,LATITUDE,LONGITUDE" in str(
25+
exc_info.value
26+
)
27+
28+
29+
def test_parse_site_location_too_many_parts():
30+
with pytest.raises(argparse.ArgumentTypeError) as exc_info:
31+
parse_site_location("Berlin,52.52,13.405,extra")
32+
assert "Location must be in the format NAME,LATITUDE,LONGITUDE" in str(
33+
exc_info.value
34+
)
35+
36+
37+
def test_parse_site_location_invalid_latitude():
38+
with pytest.raises(argparse.ArgumentTypeError) as exc_info:
39+
parse_site_location("Berlin,invalid,13.405")
40+
assert "Location must be in the format NAME,LATITUDE,LONGITUDE" in str(
41+
exc_info.value
42+
)
43+
44+
45+
def test_parse_site_location_invalid_longitude():
46+
with pytest.raises(argparse.ArgumentTypeError) as exc_info:
47+
parse_site_location("Berlin,52.52,invalid")
48+
assert "Location must be in the format NAME,LATITUDE,LONGITUDE" in str(
49+
exc_info.value
50+
)
51+
52+
53+
def test_parse_site_location_empty():
54+
with pytest.raises(argparse.ArgumentTypeError) as exc_info:
55+
parse_site_location("")
56+
assert "Location must be in the format NAME,LATITUDE,LONGITUDE" in str(
57+
exc_info.value
58+
)

0 commit comments

Comments
 (0)