Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug that caused incorrect data. #38

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/osmdiff/osmchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def __init__(
self.modify = []
self.delete = []
if file:
with open(file, "r") as fh:
xml = ElementTree.iterparse(fh, events=("start", "end"))
with open(file, "r", encoding="utf-8") as fh:
xml = ElementTree.iterparse(fh)
self._parse_xml(xml)
else:
self._frequency = frequency
Expand Down Expand Up @@ -98,7 +98,7 @@ def retrieve(self, clear_cache=False, timeout=30) -> int:
if r.status_code != 200:
return r.status_code
gzfile = GzipFile(fileobj=r.raw)
xml = ElementTree.iterparse(gzfile, events=("start", "end"))
xml = ElementTree.iterparse(gzfile)
self._parse_xml(xml)
return r.status_code
except ConnectionError:
Expand Down Expand Up @@ -135,8 +135,8 @@ def from_xml_file(cls, path) -> "OSMChange":
:return: OSMChange object
:rtype: OSMChange
"""
with open(path, "r") as fh:
xml = ElementTree.iterparse(fh, events=("start", "end"))
with open(path, "r", encoding="utf-8") as fh:
xml = ElementTree.iterparse(fh)
return cls.from_xml(xml)

@property
Expand Down
10 changes: 5 additions & 5 deletions tests/test_osmchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ def test_set_sequencenumber(self):
def test_read_changeset_from_xml_file(self, osmchange_file_path):
"Test initializing from an XML object"
osmchange = OSMChange.from_xml_file(osmchange_file_path)
assert len(osmchange.create) == 1004
assert len(osmchange.modify) == 585
assert len(osmchange.delete) == 3800
assert len(osmchange.create) == 831
assert len(osmchange.modify) == 368
assert len(osmchange.delete) == 3552
nodes_created = [o for o in osmchange.create if isinstance(o, Node)]
ways_created = [o for o in osmchange.create if isinstance(o, Way)]
rels_created = [o for o in osmchange.create if isinstance(o, Relation)]
assert len(nodes_created) == 858
assert len(ways_created) == 146
assert len(nodes_created) == 699
assert len(ways_created) == 132
assert len(rels_created) == 0
assert len(nodes_created + ways_created + rels_created) == len(osmchange.create)