Skip to content

Commit 96e7f06

Browse files
committed
Plug coverage holes
1 parent f2e769d commit 96e7f06

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

metomi/isodatetime/tests/test_01.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,15 @@ def test_duration_is_exact(duration: Duration, expected: bool):
679679
assert duration.is_exact() is expected
680680

681681

682+
def test_duration_neg():
683+
"""Test negating a Duration."""
684+
duration = Duration(years=1, months=2, days=3, hours=4, seconds=6)
685+
assert -duration == Duration(
686+
years=-1, months=-2, days=-3, hours=-4, seconds=-6
687+
)
688+
assert str(-duration) == "-P1Y2M3DT4H6S"
689+
690+
682691
def test_timepoint_comparison():
683692
"""Test the TimePoint rich comparison methods and hashing."""
684693
run_comparison_tests(data.TimePoint, get_timepoint_comparison_tests())
@@ -703,14 +712,25 @@ def test_timepoint_plus_float_time_duration_day_of_month_type():
703712
assert isinstance(time_point.day_of_month, int)
704713

705714

706-
def test_timepoint_subtract():
715+
@pytest.mark.parametrize(
716+
'test_props1, test_props2, ctrl_string', get_timepoint_subtract_tests()
717+
)
718+
def test_timepoint_subtract(test_props1, test_props2, ctrl_string):
707719
"""Test subtracting one time point from another."""
708-
for test_props1, test_props2, ctrl_string in (
709-
get_timepoint_subtract_tests()):
710-
point1 = data.TimePoint(**test_props1)
711-
point2 = data.TimePoint(**test_props2)
712-
test_string = str(point1 - point2)
713-
assert test_string == ctrl_string
720+
point1 = TimePoint(**test_props1)
721+
point2 = TimePoint(**test_props2)
722+
test_string = str(point1 - point2)
723+
assert test_string == ctrl_string
724+
725+
726+
def test_timepoint_subtract_truncated():
727+
"""Test an error is raised if subtracting a truncated TimePoint from
728+
a non-truncated one and vice versa."""
729+
msg = r"Invalid subtraction"
730+
with pytest.raises(ValueError, match=msg):
731+
TimePoint(year=2000) - TimePoint(day_of_month=2, truncated=True)
732+
with pytest.raises(ValueError, match=msg):
733+
TimePoint(day_of_month=2, truncated=True) - TimePoint(year=2000)
714734

715735

716736
@pytest.mark.parametrize('test', get_duration_subtract_tests())
@@ -875,6 +895,11 @@ def test_timepoint_duration_subtract(test):
875895
),
876896
data.TimePoint(year=3200, month_of_year=2, day_of_month=29),
877897
),
898+
add_param(
899+
data.TimePoint(year=3012, month_of_year=10, hour_of_day=9),
900+
data.TimePoint(day_of_year=63, truncated=True),
901+
data.TimePoint(year=3013, day_of_year=63),
902+
),
878903
],
879904
)
880905
def test_timepoint_add(

0 commit comments

Comments
 (0)