@@ -83,16 +83,16 @@ def testVersion(self):
83
83
84
84
def testGMT (self ):
85
85
now = datetime .now (tz = GMT )
86
- self .assertTrue (now .utcoffset () == NOTIME )
87
- self .assertTrue (now .dst () == NOTIME )
88
- self .assertTrue (now .timetuple () == now .utctimetuple ())
89
- self .assertTrue (now == now .replace (tzinfo = UTC ))
86
+ self .assertEqual (now .utcoffset (), NOTIME )
87
+ self .assertEqual (now .dst (), NOTIME )
88
+ self .assertEqual (now .timetuple (), now .utctimetuple ())
89
+ self .assertEqual (now , now .replace (tzinfo = UTC ))
90
90
91
91
def testReferenceUTC (self ):
92
92
now = datetime .now (tz = UTC )
93
- self .assertTrue (now .utcoffset () == NOTIME )
94
- self .assertTrue (now .dst () == NOTIME )
95
- self .assertTrue (now .timetuple () == now .utctimetuple ())
93
+ self .assertEqual (now .utcoffset (), NOTIME )
94
+ self .assertEqual (now .dst (), NOTIME )
95
+ self .assertEqual (now .timetuple (), now .utctimetuple ())
96
96
97
97
def testUnknownOffsets (self ):
98
98
# This tzinfo behavior is required to make
@@ -102,8 +102,8 @@ def testUnknownOffsets(self):
102
102
103
103
# This information is not known when we don't have a date,
104
104
# so return None per API.
105
- self .assertTrue (dst_tz .utcoffset (None ) is None )
106
- self .assertTrue (dst_tz .dst (None ) is None )
105
+ self .assertIsNone (dst_tz .utcoffset (None ))
106
+ self .assertIsNone (dst_tz .dst (None ))
107
107
# We don't know the abbreviation, but this is still a valid
108
108
# tzname per the Python documentation.
109
109
self .assertEqual (dst_tz .tzname (None ), 'US/Eastern' )
@@ -117,25 +117,25 @@ def testUnicodeTimezone(self):
117
117
# returned.
118
118
self .clearCache ()
119
119
eastern = pytz .timezone (unicode ('US/Eastern' ))
120
- self .assertTrue (eastern is pytz .timezone ('US/Eastern' ))
120
+ self .assertIs (eastern , pytz .timezone ('US/Eastern' ))
121
121
122
122
self .clearCache ()
123
123
eastern = pytz .timezone ('US/Eastern' )
124
- self .assertTrue (eastern is pytz .timezone (unicode ('US/Eastern' )))
124
+ self .assertIs (eastern , pytz .timezone (unicode ('US/Eastern' )))
125
125
126
126
def testStaticTzInfo (self ):
127
127
# Ensure that static timezones are correctly detected,
128
128
# per lp:1602807
129
129
static = pytz .timezone ('Etc/GMT-4' )
130
- self .assertTrue ( isinstance ( static , StaticTzInfo ) )
130
+ self .assertIsInstance ( static , StaticTzInfo )
131
131
132
132
133
133
class PicklingTest (unittest .TestCase ):
134
134
135
135
def _roundtrip_tzinfo (self , tz ):
136
136
p = pickle .dumps (tz )
137
137
unpickled_tz = pickle .loads (p )
138
- self .assertTrue (tz is unpickled_tz , '%s did not roundtrip' % tz .zone )
138
+ self .assertIs (tz , unpickled_tz , '%s did not roundtrip' % tz .zone )
139
139
140
140
def _roundtrip_datetime (self , dt ):
141
141
# Ensure that the tzinfo attached to a datetime instance
@@ -145,7 +145,7 @@ def _roundtrip_datetime(self, dt):
145
145
p = pickle .dumps (dt )
146
146
unpickled_dt = pickle .loads (p )
147
147
unpickled_tz = unpickled_dt .tzinfo
148
- self .assertTrue (tz is unpickled_tz , '%s did not roundtrip' % tz .zone )
148
+ self .assertIs (tz , unpickled_tz , '%s did not roundtrip' % tz .zone )
149
149
150
150
def testDst (self ):
151
151
tz = pytz .timezone ('Europe/Amsterdam' )
@@ -173,7 +173,7 @@ def testDatabaseFixes(self):
173
173
)
174
174
self .assertNotEqual (p , hacked_p )
175
175
unpickled_tz = pickle .loads (hacked_p )
176
- self .assertTrue (tz is unpickled_tz )
176
+ self .assertIs (tz , unpickled_tz )
177
177
178
178
# Simulate a database correction. In this case, the incorrect
179
179
# data will continue to be used.
@@ -196,7 +196,7 @@ def testDatabaseFixes(self):
196
196
self .assertNotEqual (p , hacked_p )
197
197
unpickled_tz = pickle .loads (hacked_p )
198
198
self .assertEqual (unpickled_tz ._utcoffset .seconds , new_utcoffset )
199
- self .assertTrue (tz is not unpickled_tz )
199
+ self .assertIsNot (tz , unpickled_tz )
200
200
201
201
def testOldPickles (self ):
202
202
# Ensure that applications serializing pytz instances as pickles
@@ -210,7 +210,7 @@ def testOldPickles(self):
210
210
)
211
211
east2 = pytz .timezone ('US/Eastern' ).localize (
212
212
datetime (2006 , 1 , 1 )).tzinfo
213
- self .assertTrue (east1 is east2 )
213
+ self .assertIs (east1 , east2 )
214
214
215
215
# Confirm changes in name munging between 2006j and 2007c cause
216
216
# no problems.
@@ -219,12 +219,12 @@ def testOldPickles(self):
219
219
"\n p2\n I-17340\n I0\n S'PPMT'\n p3\n tRp4\n ." ))
220
220
pap2 = pytz .timezone ('America/Port-au-Prince' ).localize (
221
221
datetime (1910 , 1 , 1 )).tzinfo
222
- self .assertTrue (pap1 is pap2 )
222
+ self .assertIs (pap1 , pap2 )
223
223
224
224
gmt1 = pickle .loads (_byte_string (
225
225
"cpytz\n _p\n p1\n (S'Etc/GMT_plus_10'\n p2\n tRp3\n ." ))
226
226
gmt2 = pytz .timezone ('Etc/GMT+10' )
227
- self .assertTrue (gmt1 is gmt2 )
227
+ self .assertIs (gmt1 , gmt2 )
228
228
229
229
230
230
class USEasternDSTStartTestCase (unittest .TestCase ):
@@ -703,17 +703,17 @@ def test_bratislava(self):
703
703
# but I'm hesitant to pay the startup cost as loading the list
704
704
# on demand whilst remaining backwards compatible seems
705
705
# difficult.
706
- self .assertTrue ('Europe/Bratislava' in pytz .common_timezones )
707
- self .assertTrue ('Europe/Bratislava' in pytz .common_timezones_set )
706
+ self .assertIn ('Europe/Bratislava' , pytz .common_timezones )
707
+ self .assertIn ('Europe/Bratislava' , pytz .common_timezones_set )
708
708
709
709
def test_us_eastern (self ):
710
- self .assertTrue ('US/Eastern' in pytz .common_timezones )
711
- self .assertTrue ('US/Eastern' in pytz .common_timezones_set )
710
+ self .assertIn ('US/Eastern' , pytz .common_timezones )
711
+ self .assertIn ('US/Eastern' , pytz .common_timezones_set )
712
712
713
713
def test_belfast (self ):
714
- self .assertTrue ('Europe/Belfast' in pytz .all_timezones_set )
715
- self .assertFalse ('Europe/Belfast' in pytz .common_timezones )
716
- self .assertFalse ('Europe/Belfast' in pytz .common_timezones_set )
714
+ self .assertIn ('Europe/Belfast' , pytz .all_timezones_set )
715
+ self .assertNotIn ('Europe/Belfast' , pytz .common_timezones )
716
+ self .assertNotIn ('Europe/Belfast' , pytz .common_timezones_set )
717
717
718
718
719
719
class ZoneCaseInsensitivityTestCase (unittest .TestCase ):
@@ -737,7 +737,7 @@ class BaseTzInfoTestCase:
737
737
tz_class = None # override
738
738
739
739
def test_expectedclass (self ):
740
- self .assertTrue ( isinstance ( self .tz , self .tz_class ) )
740
+ self .assertIsInstance ( self .tz , self .tz_class )
741
741
742
742
def test_fromutc (self ):
743
743
# naive datetime.
@@ -755,33 +755,33 @@ def test_fromutc(self):
755
755
756
756
# localized datetime, different timezone.
757
757
new_tz = pytz .timezone ('Europe/Paris' )
758
- self .assertTrue (self .tz is not new_tz )
758
+ self .assertIsNot (self .tz , new_tz )
759
759
dt3 = new_tz .localize (dt1 )
760
760
self .assertRaises (ValueError , self .tz .fromutc , dt3 )
761
761
762
762
def test_normalize (self ):
763
763
other_tz = pytz .timezone ('Europe/Paris' )
764
- self .assertTrue (self .tz is not other_tz )
764
+ self .assertIsNot (self .tz , other_tz )
765
765
766
766
dt = datetime (2012 , 3 , 26 , 12 , 0 )
767
767
other_dt = other_tz .localize (dt )
768
768
769
769
local_dt = self .tz .normalize (other_dt )
770
770
771
- self .assertTrue (local_dt .tzinfo is not other_dt .tzinfo )
771
+ self .assertIsNot (local_dt .tzinfo , other_dt .tzinfo )
772
772
self .assertNotEqual (
773
773
local_dt .replace (tzinfo = None ), other_dt .replace (tzinfo = None ))
774
774
775
775
def test_astimezone (self ):
776
776
other_tz = pytz .timezone ('Europe/Paris' )
777
- self .assertTrue (self .tz is not other_tz )
777
+ self .assertIsNot (self .tz , other_tz )
778
778
779
779
dt = datetime (2012 , 3 , 26 , 12 , 0 )
780
780
other_dt = other_tz .localize (dt )
781
781
782
782
local_dt = other_dt .astimezone (self .tz )
783
783
784
- self .assertTrue (local_dt .tzinfo is not other_dt .tzinfo )
784
+ self .assertIsNot (local_dt .tzinfo , other_dt .tzinfo )
785
785
self .assertNotEqual (
786
786
local_dt .replace (tzinfo = None ), other_dt .replace (tzinfo = None ))
787
787
0 commit comments