Skip to content

Commit

Permalink
property trouble
Browse files Browse the repository at this point in the history
  • Loading branch information
mvexel committed May 25, 2024
1 parent b0d64b5 commit 4179e9e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/osmdiff/augmenteddiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ def remarks(self):
def timestamp(self):
return self._timestamp

@timestamp.setter
def timestamp(self, value):
self._timestamp = value

@property
def sequence_number(self):
return self._sequence_number

@sequence_number.setter
def sequence_number(self, value):
try:
# value can be none
if value is None:
self._sequence_number = None
return
self._sequence_number = int(value)
except ValueError:
raise ValueError(
Expand Down
4 changes: 4 additions & 0 deletions src/osmdiff/osmchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ def sequence_number(self) -> int:
@sequence_number.setter
def sequence_number(self, value):
try:
# value can be none
if value is None:
self._sequence_number = None
return
self._sequence_number = int(value)
except ValueError:
raise ValueError(
Expand Down
10 changes: 9 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import pytest
import xml.etree.ElementTree as ET


# Define a fixture to load the XML file
@pytest.fixture
def osmchange_xml_obj():
with open("tests/data/test_osmchange.xml", "r") as fh:
return ET.parse(fh)



# Path to the changeset XML file
@pytest.fixture
def osmchange_file_path():
return "tests/data/test_osmchange.xml"


# Path to the augmented diff XML file
@pytest.fixture
def adiff_file_path():
return "tests/data/test_adiff.xml"
31 changes: 31 additions & 0 deletions tests/test_adiff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from osmdiff import Node, AugmentedDiff, Relation, Way
from typing_extensions import assert_type


class TestAugmentedDiff:
"tests for AugmentedDiff class"

def test_init_augmenteddiff(self):
"Test AugmentedDiff init"
augmenteddiff = AugmentedDiff()
assert_type(augmenteddiff, AugmentedDiff)
assert_type(augmenteddiff.create, list)
assert_type(augmenteddiff.modify, list)
assert_type(augmenteddiff.delete, list)
assert len(augmenteddiff.create) == 0
assert len(augmenteddiff.modify) == 0
assert len(augmenteddiff.delete) == 0

def test_set_sequencenumber(self):
"Sequence number is not defined by default but can be set manually"
augmented_diff = AugmentedDiff()
assert not augmented_diff.sequence_number
augmented_diff.sequence_number = 12345
assert augmented_diff.sequence_number == 12345
augmented_diff.sequence_number = "12345"
assert augmented_diff.sequence_number == 12345

def test_read_changeset_from_xml_file(self, adiff_file_path):
"Test initializing from an XML object"
# not implemented yet
pass

0 comments on commit 4179e9e

Please sign in to comment.