Skip to content

Commit

Permalink
Updated testcases and added new testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-vd-aardweg committed Apr 17, 2023
1 parent 8f6b1f2 commit e6af25c
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions tests/dflowfm/test_xyn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_parse_xyn_file(self):
file_content = """
*This is a comment and should not be parsed.
1.1 2.2 'ObservationPoint_2D_01'
3.3 4.4 'ObservationPoint_2D_02'
3.3 4.4 "ObservationPoint_2D_02"
"""

expected_result = {
Expand All @@ -33,21 +33,41 @@ def test_parse_xyn_file(self):
parsed_contents = XYNParser.parse(xyn_file)
assert expected_result == parsed_contents

def test_parse_xyn_file_with_quoted_name_removes_quotes(self):
def test_parse_xyn_file_with_single_quoted_name_removes_quotes_and_keeps_spaces(
self,
):
file_content = """
1.1 2.2 'ObservationPoint_2D_01'
1.1 2.2 'ObservationPoint 2D 01'
"""

expected_result = {
"points": [
{"x": "1.1", "y": "2.2", "n": "ObservationPoint_2D_01"},
{"x": "1.1", "y": "2.2", "n": "ObservationPoint 2D 01"},
]
}

with create_temp_file(file_content, "test.xyn") as xyn_file:
parsed_contents = XYNParser.parse(xyn_file)
assert expected_result == parsed_contents

def test_parse_xyn_file_with_double_quoted_name_removes_quotes_and_keeps_spaces(
self,
):
file_content = """
1.1 2.2 "ObservationPoint 2D 01"
"""

expected_result = {
"points": [
{"x": "1.1", "y": "2.2", "n": "ObservationPoint 2D 01"},
]
}

with create_temp_file(file_content, "test.xyn") as xyn_file:
parsed_contents = XYNParser.parse(xyn_file)

assert expected_result == parsed_contents

def test_parse_xyn_file_with_too_many_columns_raises_error(self):
name = "'ObservationPoint_2D_01' This is too much content"
file_content = f"1.1 2.2 {name}"
Expand Down Expand Up @@ -79,7 +99,7 @@ def test_serialize_xyn_point(self):

with open(xyn_file) as file:
file_content = file.readlines()
assert file_content == expected_file_content
assert file_content == expected_file_content


class TestXYNModel:
Expand Down Expand Up @@ -131,7 +151,8 @@ class TestXYNPoint:
@pytest.mark.parametrize(
("name"),
[
pytest.param("'nameWithQuote", id="Name with quote"),
pytest.param("nameWith'SingleQuote", id="Name with single quote"),
pytest.param('nameWith"DoubleQuote', id="Name with single quote"),
pytest.param(None, id="None value"),
pytest.param("", id="Empty string"),
pytest.param(" ", id="Whitespace only"),
Expand Down

0 comments on commit e6af25c

Please sign in to comment.