@@ -679,6 +679,15 @@ def test_duration_is_exact(duration: Duration, expected: bool):
679
679
assert duration .is_exact () is expected
680
680
681
681
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
+
682
691
def test_timepoint_comparison ():
683
692
"""Test the TimePoint rich comparison methods and hashing."""
684
693
run_comparison_tests (data .TimePoint , get_timepoint_comparison_tests ())
@@ -703,14 +712,25 @@ def test_timepoint_plus_float_time_duration_day_of_month_type():
703
712
assert isinstance (time_point .day_of_month , int )
704
713
705
714
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 ):
707
719
"""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 )
714
734
715
735
716
736
@pytest .mark .parametrize ('test' , get_duration_subtract_tests ())
@@ -875,6 +895,11 @@ def test_timepoint_duration_subtract(test):
875
895
),
876
896
data .TimePoint (year = 3200 , month_of_year = 2 , day_of_month = 29 ),
877
897
),
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
+ ),
878
903
],
879
904
)
880
905
def test_timepoint_add (
0 commit comments