Skip to content

Commit

Permalink
Tidy & add test
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Mar 2, 2022
1 parent a21669c commit e9314f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 3 additions & 5 deletions metomi/isodatetime/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,17 @@ def minutes(self): return self._minutes
@property
def seconds(self): return self._seconds

def _copy(self):
def _copy(self) -> 'Duration':
"""Return an (unlinked) copy of this instance."""
new = self.__class__(_is_empty_instance=True)
for attr in self.__slots__:
setattr(new, attr, getattr(self, attr))
return new

def is_exact(self):
def is_exact(self) -> bool:
"""Return True if the instance is defined in non-nominal/exact units
(weeks, days, hours, minutes or seconds) only."""
if self._years or self._months:
return False
return True
return not (self._years or self._months)

def get_days_and_seconds(self):
"""Return a roughly-converted duration in days and seconds.
Expand Down
7 changes: 7 additions & 0 deletions metomi/isodatetime/tests/test_01.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,13 @@ def test_duration_subtract(self):
self.assertEqual(test_subtract, end_point,
"%s - %s" % (start_point, test_duration))

def test_duration_is_exact(self):
"""Test Duration.is_exact()."""
duration = data.Duration(weeks=1, days=1)
assert duration.is_exact()
for duration in (data.Duration(months=1), data.Duration(years=1)):
assert not duration.is_exact()

def test_timepoint_comparison(self):
"""Test the TimePoint rich comparison methods and hashing."""
run_comparison_tests(data.TimePoint, get_timepoint_comparison_tests())
Expand Down

0 comments on commit e9314f1

Please sign in to comment.