Skip to content

Commit a36c7af

Browse files
committed
Refactor: new-style objects
1 parent d01272f commit a36c7af

File tree

12 files changed

+80
-80
lines changed

12 files changed

+80
-80
lines changed

Lib/test/test_unittest/support.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import unittest
22

33

4-
class TestEquality(object):
4+
class TestEquality:
55
"""Used as a mixin for TestCase"""
66

77
# Check for a valid __eq__ implementation
@@ -16,7 +16,7 @@ def test_ne(self):
1616
self.assertNotEqual(obj_1, obj_2)
1717
self.assertNotEqual(obj_2, obj_1)
1818

19-
class TestHashing(object):
19+
class TestHashing:
2020
"""Used as a mixin for TestCase"""
2121

2222
# Check for a valid __hash__ implementation
@@ -107,7 +107,7 @@ def addSubTest(self, test, subtest, err):
107107
super().addSubTest(test, subtest, err)
108108

109109

110-
class ResultWithNoStartTestRunStopTestRun(object):
110+
class ResultWithNoStartTestRunStopTestRun:
111111
"""An object honouring TestResult before startTestRun/stopTestRun."""
112112

113113
def __init__(self):

Lib/test/test_unittest/test_break.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ def testMainInstallsHandler(self):
217217
result = object()
218218
default_handler = signal.getsignal(signal.SIGINT)
219219

220-
class FakeRunner(object):
220+
class FakeRunner:
221221
initArgs = []
222222
runArgs = []
223223
def __init__(self, *args, **kwargs):

Lib/test/test_unittest/test_case.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
log_quux = logging.getLogger('quux')
2828

2929

30-
class Test(object):
30+
class Test:
3131
"Keep these TestCase classes out of the main namespace"
3232

3333
class Foo(unittest.TestCase):
@@ -41,7 +41,7 @@ class LoggingTestCase(unittest.TestCase):
4141
"""A test case which logs its calls."""
4242

4343
def __init__(self, events):
44-
super(Test.LoggingTestCase, self).__init__('test')
44+
super().__init__('test')
4545
self.events = events
4646

4747
def setUp(self):
@@ -157,7 +157,7 @@ def test_run_call_order__error_in_setUp(self):
157157

158158
class Foo(Test.LoggingTestCase):
159159
def setUp(self):
160-
super(Foo, self).setUp()
160+
super().setUp()
161161
raise RuntimeError('raised by Foo.setUp')
162162

163163
Foo(events).run(result)
@@ -173,7 +173,7 @@ def defaultTestResult(self):
173173
return LoggingResult(self.events)
174174

175175
def setUp(self):
176-
super(Foo, self).setUp()
176+
super().setUp()
177177
raise RuntimeError('raised by Foo.setUp')
178178

179179
Foo(events).run()
@@ -194,7 +194,7 @@ def test_run_call_order__error_in_test(self):
194194

195195
class Foo(Test.LoggingTestCase):
196196
def test(self):
197-
super(Foo, self).test()
197+
super().test()
198198
raise RuntimeError('raised by Foo.test')
199199

200200
expected = ['startTest', 'setUp', 'test',
@@ -212,7 +212,7 @@ def defaultTestResult(self):
212212
return LoggingResult(self.events)
213213

214214
def test(self):
215-
super(Foo, self).test()
215+
super().test()
216216
raise RuntimeError('raised by Foo.test')
217217

218218
expected = ['startTestRun', 'startTest', 'setUp', 'test',
@@ -233,7 +233,7 @@ def test_run_call_order__failure_in_test(self):
233233

234234
class Foo(Test.LoggingTestCase):
235235
def test(self):
236-
super(Foo, self).test()
236+
super().test()
237237
self.fail('raised by Foo.test')
238238

239239
expected = ['startTest', 'setUp', 'test',
@@ -248,7 +248,7 @@ class Foo(Test.LoggingTestCase):
248248
def defaultTestResult(self):
249249
return LoggingResult(self.events)
250250
def test(self):
251-
super(Foo, self).test()
251+
super().test()
252252
self.fail('raised by Foo.test')
253253

254254
expected = ['startTestRun', 'startTest', 'setUp', 'test',
@@ -270,7 +270,7 @@ def test_run_call_order__error_in_tearDown(self):
270270

271271
class Foo(Test.LoggingTestCase):
272272
def tearDown(self):
273-
super(Foo, self).tearDown()
273+
super().tearDown()
274274
raise RuntimeError('raised by Foo.tearDown')
275275

276276
Foo(events).run(result)
@@ -285,7 +285,7 @@ class Foo(Test.LoggingTestCase):
285285
def defaultTestResult(self):
286286
return LoggingResult(self.events)
287287
def tearDown(self):
288-
super(Foo, self).tearDown()
288+
super().tearDown()
289289
raise RuntimeError('raised by Foo.tearDown')
290290

291291
events = []
@@ -360,7 +360,7 @@ async def test1(self):
360360
def _check_call_order__subtests(self, result, events, expected_events):
361361
class Foo(Test.LoggingTestCase):
362362
def test(self):
363-
super(Foo, self).test()
363+
super().test()
364364
for i in [1, 2, 3]:
365365
with self.subTest(i=i):
366366
if i == 1:
@@ -402,7 +402,7 @@ def test_run_call_order__subtests_legacy(self):
402402
def _check_call_order__subtests_success(self, result, events, expected_events):
403403
class Foo(Test.LoggingTestCase):
404404
def test(self):
405-
super(Foo, self).test()
405+
super().test()
406406
for i in [1, 2]:
407407
with self.subTest(i=i):
408408
for j in [2, 3]:
@@ -437,7 +437,7 @@ def test_run_call_order__subtests_failfast(self):
437437

438438
class Foo(Test.LoggingTestCase):
439439
def test(self):
440-
super(Foo, self).test()
440+
super().test()
441441
with self.subTest(i=1):
442442
self.fail('failure')
443443
with self.subTest(i=2):
@@ -674,7 +674,7 @@ def testShortDescriptionWhitespaceTrimming(self):
674674
'Tests shortDescription() whitespace is trimmed, so that the first')
675675

676676
def testAddTypeEqualityFunc(self):
677-
class SadSnake(object):
677+
class SadSnake:
678678
"""Dummy class for test_addTypeEqualityFunc."""
679679
s1, s2 = SadSnake(), SadSnake()
680680
self.assertFalse(s1 == s2)

Lib/test/test_unittest/test_discovery.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def restore_isdir():
157157
os.path.isfile = lambda path: os.path.basename(path) not in directories
158158
self.addCleanup(restore_isfile)
159159

160-
class Module(object):
160+
class Module:
161161
paths = []
162162
load_tests_args = []
163163

@@ -231,7 +231,7 @@ def restore_isdir():
231231
os.path.isfile = lambda path: os.path.basename(path) not in directories
232232
self.addCleanup(restore_isfile)
233233

234-
class Module(object):
234+
class Module:
235235
paths = []
236236
load_tests_args = []
237237

@@ -316,7 +316,7 @@ def list_dir(path):
316316
os.path.isdir = lambda path: not path.endswith('.py')
317317
os.path.isfile = lambda path: path.endswith('.py')
318318

319-
class Module(object):
319+
class Module:
320320
paths = []
321321
load_tests_args = []
322322

@@ -457,7 +457,7 @@ def list_dir(path):
457457
os.path.isdir = lambda path: not path.endswith('.py')
458458
self.addCleanup(sys.path.remove, abspath('/toplevel'))
459459

460-
class Module(object):
460+
class Module:
461461
paths = []
462462
load_tests_args = []
463463

@@ -657,7 +657,7 @@ def test_command_line_handling_do_discovery_uses_default_loader(self):
657657
program = object.__new__(unittest.TestProgram)
658658
program._initArgParsers()
659659

660-
class Loader(object):
660+
class Loader:
661661
args = []
662662
def discover(self, start_dir, pattern, top_level_dir):
663663
self.args.append((start_dir, pattern, top_level_dir))
@@ -670,7 +670,7 @@ def discover(self, start_dir, pattern, top_level_dir):
670670
def test_command_line_handling_do_discovery_calls_loader(self):
671671
program = TestableTestProgram()
672672

673-
class Loader(object):
673+
class Loader:
674674
args = []
675675
def discover(self, start_dir, pattern, top_level_dir):
676676
self.args.append((start_dir, pattern, top_level_dir))
@@ -742,7 +742,7 @@ def discover(self, start_dir, pattern, top_level_dir):
742742
self.assertTrue(program.catchbreak)
743743

744744
def setup_module_clash(self):
745-
class Module(object):
745+
class Module:
746746
__file__ = 'bar/foo.py'
747747
sys.modules['foo'] = Module
748748
full_path = os.path.abspath('foo')

Lib/test/test_unittest/test_loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class MyTestCase(unittest.TestCase):
173173
def test(self):
174174
pass
175175

176-
class NotAModule(object):
176+
class NotAModule:
177177
test_2 = MyTestCase
178178

179179
loader = unittest.TestLoader()
@@ -419,7 +419,7 @@ class MyTestCase(unittest.TestCase):
419419
def test(self):
420420
pass
421421

422-
class NotAModule(object):
422+
class NotAModule:
423423
test_2 = MyTestCase
424424

425425
loader = unittest.TestLoader()
@@ -843,7 +843,7 @@ class MyTestCase(unittest.TestCase):
843843
def test(self):
844844
pass
845845

846-
class NotAModule(object):
846+
class NotAModule:
847847
test_2 = MyTestCase
848848

849849
loader = unittest.TestLoader()

Lib/test/test_unittest/test_program.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def testNoExit(self):
3131
result = object()
3232
test = object()
3333

34-
class FakeRunner(object):
34+
class FakeRunner:
3535
def run(self, test):
3636
self.test = test
3737
return result
@@ -90,7 +90,7 @@ def loadTestsFromNames(self, names, module):
9090
[self.loadTestsFromTestCase(self.testcase)])
9191

9292
def test_defaultTest_with_string(self):
93-
class FakeRunner(object):
93+
class FakeRunner:
9494
def run(self, test):
9595
self.test = test
9696
return True
@@ -105,7 +105,7 @@ def run(self, test):
105105
self.assertEqual(('test.test_unittest',), program.testNames)
106106

107107
def test_defaultTest_with_iterable(self):
108-
class FakeRunner(object):
108+
class FakeRunner:
109109
def run(self, test):
110110
self.test = test
111111
return True
@@ -213,7 +213,7 @@ def __init__(self, *args):
213213

214214
RESULT = object()
215215

216-
class FakeRunner(object):
216+
class FakeRunner:
217217
initArgs = None
218218
test = None
219219
raiseError = 0

Lib/test/test_unittest/test_result.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from test.test_unittest.support import BufferedWriter
1212

1313

14-
class MockTraceback(object):
14+
class MockTraceback:
1515
class TracebackException:
1616
def __init__(self, *args, **kwargs):
1717
self.capture_locals = kwargs.get('capture_locals', False)
@@ -423,8 +423,8 @@ def test_1(self):
423423
self.assertIn("some recognizable failure", formatted_exc)
424424

425425
def testStackFrameTrimming(self):
426-
class Frame(object):
427-
class tb_frame(object):
426+
class Frame:
427+
class tb_frame:
428428
f_globals = {}
429429
result = unittest.TestResult()
430430
self.assertFalse(result._is_relevant_tb_level(Frame))
@@ -1224,7 +1224,7 @@ def testBufferSetUpModule(self):
12241224
class Foo(unittest.TestCase):
12251225
def test_foo(self):
12261226
pass
1227-
class Module(object):
1227+
class Module:
12281228
@staticmethod
12291229
def setUpModule():
12301230
print('set up module')
@@ -1252,7 +1252,7 @@ def testBufferTearDownModule(self):
12521252
class Foo(unittest.TestCase):
12531253
def test_foo(self):
12541254
pass
1255-
class Module(object):
1255+
class Module:
12561256
@staticmethod
12571257
def tearDownModule():
12581258
print('tear down module')
@@ -1280,7 +1280,7 @@ def testBufferDoModuleCleanups(self):
12801280
class Foo(unittest.TestCase):
12811281
def test_foo(self):
12821282
pass
1283-
class Module(object):
1283+
class Module:
12841284
@staticmethod
12851285
def setUpModule():
12861286
print('set up module')
@@ -1310,7 +1310,7 @@ def testBufferSetUpModule_DoModuleCleanups(self):
13101310
class Foo(unittest.TestCase):
13111311
def test_foo(self):
13121312
pass
1313-
class Module(object):
1313+
class Module:
13141314
@staticmethod
13151315
def setUpModule():
13161316
print('set up module')
@@ -1349,7 +1349,7 @@ def testBufferTearDownModule_DoModuleCleanups(self):
13491349
class Foo(unittest.TestCase):
13501350
def test_foo(self):
13511351
pass
1352-
class Module(object):
1352+
class Module:
13531353
@staticmethod
13541354
def setUpModule():
13551355
print('set up module')

0 commit comments

Comments
 (0)