Skip to content

Commit

Permalink
Fix reading java array type (#216)
Browse files Browse the repository at this point in the history
* fix reading java array type

* update CHANGELOG.md
  • Loading branch information
KasiaKoz authored Feb 2, 2024
1 parent 127fcf0 commit 2aaab56
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Fixed summary report:
* Intermodal Access/Egress reporting is more general (not expecting just car and bike mode access to PT) [#204](https://github.com/arup-group/genet/pull/204)
* Node/Links numbers were reported incorrectly (switched) [#207](https://github.com/arup-group/genet/pull/207)
* Fixed reading `java.lang.Array` types in MATSim xml files [#216](https://github.com/arup-group/genet/pull/216)

### Changed
* GeNet's pre-baked python scripts have been retired in favour of CLI [#194](https://github.com/arup-group/genet/pull/194)
Expand Down
2 changes: 1 addition & 1 deletion genet/input/matsim_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def _read_additional_attrib_text(elem):
f"Elem {elem.attrib['name']} is being read as None. Defaulting value to empty string."
)
elif ("," in elem.text) and elem.attrib["name"] != "geometry":
t = set(elem.text.split(","))
t = set(elem.text.strip("{}").replace(("'"), "").replace(" ", "").split(","))
else:
t = elem.text
return t
Expand Down
22 changes: 22 additions & 0 deletions tests/test_input_matsim_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -1038,3 +1038,25 @@ def make_network_with_elevations_xml_string(nodes_with_elevations_dict, link_dic
network_xml += " </attributes> </link>"
network_xml += " </links> </network>"
return network_xml


class ElemWithText:
def __init__(self, text):
self.text = text
self.attrib = {"name": "doesn't matter"}


@pytest.mark.parametrize(
"case,input_elem_text,expected_output",
[
("is_just_a_string", "hello", "hello"),
("is_a_java_array", "{'hello', 'yes'}", {"hello", "yes"}),
("is_none", None, ""),
],
)
def test_read_additional_attrib_text(case, input_elem_text, expected_output):
elem = ElemWithText(input_elem_text)
output = matsim_reader._read_additional_attrib_text(elem=elem)
assert output == expected_output, AssertionError(
f"Elem for case {case} did not produce the expected result"
)

0 comments on commit 2aaab56

Please sign in to comment.