Skip to content

Commit dacb1a1

Browse files
hugovkstub42
authored andcommitted
Upgrade unittest asserts
1 parent d1abcdd commit dacb1a1

File tree

3 files changed

+46
-43
lines changed

3 files changed

+46
-43
lines changed

src/pytz/tests/test_lazy.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ def test_binary_ops(self):
6262
self.assertEqual(3 * self.lazy, 3 * self.base)
6363

6464
# Contains
65-
self.assertTrue(2 in self.lazy)
66-
self.assertFalse(42 in self.lazy)
65+
self.assertIn(2, self.lazy)
66+
self.assertNotIn(42, self.lazy)
6767

6868
def test_iadd(self):
6969
self.lazy += [1]
@@ -79,8 +79,8 @@ def test_hash(self):
7979
self.assertRaises(TypeError, hash, self.lazy)
8080

8181
def test_isinstance(self):
82-
self.assertTrue(isinstance(self.lazy, list))
83-
self.assertFalse(isinstance(self.lazy, tuple))
82+
self.assertIsInstance(self.lazy, list)
83+
self.assertNotIsInstance(self.lazy, tuple)
8484

8585
def test_callable(self):
8686
try:
@@ -231,8 +231,8 @@ def test_binary_ops(self):
231231
op(self.base, self.base), str(op))
232232

233233
# Contains
234-
self.assertTrue(2 in self.lazy)
235-
self.assertFalse(42 in self.lazy)
234+
self.assertIn(2, self.lazy)
235+
self.assertNotIn(42, self.lazy)
236236

237237
def test_iops(self):
238238
try:
@@ -256,7 +256,7 @@ def test_hash(self):
256256
self.assertRaises(TypeError, hash, self.lazy)
257257

258258
def test_isinstance(self):
259-
self.assertTrue(isinstance(self.lazy, set))
259+
self.assertIsInstance(self.lazy, set)
260260

261261
def test_callable(self):
262262
try:

src/pytz/tests/test_tzinfo.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,16 @@ def testVersion(self):
8383

8484
def testGMT(self):
8585
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))
9090

9191
def testReferenceUTC(self):
9292
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())
9696

9797
def testUnknownOffsets(self):
9898
# This tzinfo behavior is required to make
@@ -102,8 +102,8 @@ def testUnknownOffsets(self):
102102

103103
# This information is not known when we don't have a date,
104104
# 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))
107107
# We don't know the abbreviation, but this is still a valid
108108
# tzname per the Python documentation.
109109
self.assertEqual(dst_tz.tzname(None), 'US/Eastern')
@@ -117,25 +117,25 @@ def testUnicodeTimezone(self):
117117
# returned.
118118
self.clearCache()
119119
eastern = pytz.timezone(unicode('US/Eastern'))
120-
self.assertTrue(eastern is pytz.timezone('US/Eastern'))
120+
self.assertIs(eastern, pytz.timezone('US/Eastern'))
121121

122122
self.clearCache()
123123
eastern = pytz.timezone('US/Eastern')
124-
self.assertTrue(eastern is pytz.timezone(unicode('US/Eastern')))
124+
self.assertIs(eastern, pytz.timezone(unicode('US/Eastern')))
125125

126126
def testStaticTzInfo(self):
127127
# Ensure that static timezones are correctly detected,
128128
# per lp:1602807
129129
static = pytz.timezone('Etc/GMT-4')
130-
self.assertTrue(isinstance(static, StaticTzInfo))
130+
self.assertIsInstance(static, StaticTzInfo)
131131

132132

133133
class PicklingTest(unittest.TestCase):
134134

135135
def _roundtrip_tzinfo(self, tz):
136136
p = pickle.dumps(tz)
137137
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)
139139

140140
def _roundtrip_datetime(self, dt):
141141
# Ensure that the tzinfo attached to a datetime instance
@@ -145,7 +145,7 @@ def _roundtrip_datetime(self, dt):
145145
p = pickle.dumps(dt)
146146
unpickled_dt = pickle.loads(p)
147147
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)
149149

150150
def testDst(self):
151151
tz = pytz.timezone('Europe/Amsterdam')
@@ -173,7 +173,7 @@ def testDatabaseFixes(self):
173173
)
174174
self.assertNotEqual(p, hacked_p)
175175
unpickled_tz = pickle.loads(hacked_p)
176-
self.assertTrue(tz is unpickled_tz)
176+
self.assertIs(tz, unpickled_tz)
177177

178178
# Simulate a database correction. In this case, the incorrect
179179
# data will continue to be used.
@@ -196,7 +196,7 @@ def testDatabaseFixes(self):
196196
self.assertNotEqual(p, hacked_p)
197197
unpickled_tz = pickle.loads(hacked_p)
198198
self.assertEqual(unpickled_tz._utcoffset.seconds, new_utcoffset)
199-
self.assertTrue(tz is not unpickled_tz)
199+
self.assertIsNot(tz, unpickled_tz)
200200

201201
def testOldPickles(self):
202202
# Ensure that applications serializing pytz instances as pickles
@@ -210,7 +210,7 @@ def testOldPickles(self):
210210
)
211211
east2 = pytz.timezone('US/Eastern').localize(
212212
datetime(2006, 1, 1)).tzinfo
213-
self.assertTrue(east1 is east2)
213+
self.assertIs(east1, east2)
214214

215215
# Confirm changes in name munging between 2006j and 2007c cause
216216
# no problems.
@@ -219,12 +219,12 @@ def testOldPickles(self):
219219
"\np2\nI-17340\nI0\nS'PPMT'\np3\ntRp4\n."))
220220
pap2 = pytz.timezone('America/Port-au-Prince').localize(
221221
datetime(1910, 1, 1)).tzinfo
222-
self.assertTrue(pap1 is pap2)
222+
self.assertIs(pap1, pap2)
223223

224224
gmt1 = pickle.loads(_byte_string(
225225
"cpytz\n_p\np1\n(S'Etc/GMT_plus_10'\np2\ntRp3\n."))
226226
gmt2 = pytz.timezone('Etc/GMT+10')
227-
self.assertTrue(gmt1 is gmt2)
227+
self.assertIs(gmt1, gmt2)
228228

229229

230230
class USEasternDSTStartTestCase(unittest.TestCase):
@@ -703,17 +703,17 @@ def test_bratislava(self):
703703
# but I'm hesitant to pay the startup cost as loading the list
704704
# on demand whilst remaining backwards compatible seems
705705
# 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)
708708

709709
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)
712712

713713
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)
717717

718718

719719
class ZoneCaseInsensitivityTestCase(unittest.TestCase):
@@ -737,7 +737,7 @@ class BaseTzInfoTestCase:
737737
tz_class = None # override
738738

739739
def test_expectedclass(self):
740-
self.assertTrue(isinstance(self.tz, self.tz_class))
740+
self.assertIsInstance(self.tz, self.tz_class)
741741

742742
def test_fromutc(self):
743743
# naive datetime.
@@ -755,33 +755,33 @@ def test_fromutc(self):
755755

756756
# localized datetime, different timezone.
757757
new_tz = pytz.timezone('Europe/Paris')
758-
self.assertTrue(self.tz is not new_tz)
758+
self.assertIsNot(self.tz, new_tz)
759759
dt3 = new_tz.localize(dt1)
760760
self.assertRaises(ValueError, self.tz.fromutc, dt3)
761761

762762
def test_normalize(self):
763763
other_tz = pytz.timezone('Europe/Paris')
764-
self.assertTrue(self.tz is not other_tz)
764+
self.assertIsNot(self.tz, other_tz)
765765

766766
dt = datetime(2012, 3, 26, 12, 0)
767767
other_dt = other_tz.localize(dt)
768768

769769
local_dt = self.tz.normalize(other_dt)
770770

771-
self.assertTrue(local_dt.tzinfo is not other_dt.tzinfo)
771+
self.assertIsNot(local_dt.tzinfo, other_dt.tzinfo)
772772
self.assertNotEqual(
773773
local_dt.replace(tzinfo=None), other_dt.replace(tzinfo=None))
774774

775775
def test_astimezone(self):
776776
other_tz = pytz.timezone('Europe/Paris')
777-
self.assertTrue(self.tz is not other_tz)
777+
self.assertIsNot(self.tz, other_tz)
778778

779779
dt = datetime(2012, 3, 26, 12, 0)
780780
other_dt = other_tz.localize(dt)
781781

782782
local_dt = other_dt.astimezone(self.tz)
783783

784-
self.assertTrue(local_dt.tzinfo is not other_dt.tzinfo)
784+
self.assertIsNot(local_dt.tzinfo, other_dt.tzinfo)
785785
self.assertNotEqual(
786786
local_dt.replace(tzinfo=None), other_dt.replace(tzinfo=None))
787787

test_zdump.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@
1414
class ZdumpTestCase(unittest.TestCase):
1515
def utc_to_local_check(self, zone, utc_dt, loc_dt, loc_tzname, is_dst):
1616
loc_tz = pytz.timezone(zone)
17-
self.failUnlessEqual(
17+
self.assertEqual(
1818
utc_dt.astimezone(loc_tz).replace(tzinfo=None),
19-
loc_dt.replace(tzinfo=None))
19+
loc_dt.replace(tzinfo=None)
20+
)
2021

2122
def local_to_utc_check(self, zone, utc_dt, loc_dt, loc_tzname, is_dst):
22-
self.failUnlessEqual(
23+
self.assertEqual(
2324
loc_dt.astimezone(pytz.utc).replace(tzinfo=None),
24-
utc_dt.replace(tzinfo=None))
25+
utc_dt.replace(tzinfo=None)
26+
)
2527

2628

2729
def test_suite():
@@ -134,5 +136,6 @@ def test_local_to_utc(
134136
suite.addTest(unittest.makeSuite(testcases.pop()))
135137
return suite
136138

139+
137140
if __name__ == '__main__':
138141
unittest.main(defaultTest='test_suite')

0 commit comments

Comments
 (0)