@@ -31,6 +31,51 @@ def test_hash_replacement(self):
31
31
self .assertEqual (u , expected )
32
32
33
33
34
+ class Test_change_calendar (unittest .TestCase ):
35
+ def test_modern_standard_to_proleptic_gregorian (self ):
36
+ u = Unit ("hours since 1970-01-01 00:00:00" , calendar = "standard" )
37
+ expected = Unit (
38
+ "hours since 1970-01-01 00:00:00" , calendar = "proleptic_gregorian"
39
+ )
40
+ result = u .change_calendar ("proleptic_gregorian" )
41
+ self .assertEqual (result , expected )
42
+
43
+ def test_ancient_standard_to_proleptic_gregorian (self ):
44
+ u = Unit ("hours since 1500-01-01 00:00:00" , calendar = "standard" )
45
+ expected = Unit (
46
+ "hours since 1500-01-10 00:00:00" , calendar = "proleptic_gregorian"
47
+ )
48
+ result = u .change_calendar ("proleptic_gregorian" )
49
+ self .assertEqual (result , expected )
50
+
51
+ def test_no_change (self ):
52
+ u = Unit ("hours since 1500-01-01 00:00:00" , calendar = "standard" )
53
+ result = u .change_calendar ("standard" )
54
+ self .assertEqual (result , u )
55
+ # Docstring states that a new unit is returned, so check these are not
56
+ # the same object.
57
+ self .assertIsNot (result , u )
58
+
59
+ def test_long_time_interval (self ):
60
+ u = Unit ("months since 1970-01-01" , calendar = "standard" )
61
+ with self .assertRaisesRegex (ValueError , "cannot be processed" ):
62
+ u .change_calendar ("proleptic_gregorian" )
63
+
64
+ def test_wrong_calendar (self ):
65
+ u = Unit ("days since 1900-01-01" , calendar = "360_day" )
66
+ with self .assertRaisesRegex (
67
+ ValueError , "change_calendar only works for real-world calendars"
68
+ ):
69
+ u .change_calendar ("standard" )
70
+
71
+ def test_non_time_unit (self ):
72
+ u = Unit ("m" )
73
+ with self .assertRaisesRegex (
74
+ ValueError , "unit is not a time reference"
75
+ ):
76
+ u .change_calendar ("standard" )
77
+
78
+
34
79
class Test_convert__calendar (unittest .TestCase ):
35
80
class MyStr (str ):
36
81
pass
0 commit comments