Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(197815)

Side by Side Diff: Lib/test/test_inspect.py

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/test/test_hmac.py ('k') | Lib/test/test_iter.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import collections 1 import collections
2 import datetime 2 import datetime
3 import functools 3 import functools
4 import importlib 4 import importlib
5 import inspect 5 import inspect
6 import io 6 import io
7 import linecache 7 import linecache
8 import os 8 import os
9 from os.path import normcase 9 from os.path import normcase
10 import _pickle 10 import _pickle
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 def __init__(self, *args, **kwargs): 162 def __init__(self, *args, **kwargs):
163 unittest.TestCase.__init__(self, *args, **kwargs) 163 unittest.TestCase.__init__(self, *args, **kwargs)
164 164
165 git.abuse(7, 8, 9) 165 git.abuse(7, 8, 9)
166 166
167 def test_abuse_done(self): 167 def test_abuse_done(self):
168 self.istest(inspect.istraceback, 'git.ex[2]') 168 self.istest(inspect.istraceback, 'git.ex[2]')
169 self.istest(inspect.isframe, 'mod.fr') 169 self.istest(inspect.isframe, 'mod.fr')
170 170
171 def test_stack(self): 171 def test_stack(self):
172 self.assertTrue(len(mod.st) >= 5) 172 self.assertGreaterEqual(len(mod.st), 5)
173 self.assertEqual(revise(*mod.st[0][1:]), 173 self.assertEqual(revise(*mod.st[0][1:]),
174 (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0)) 174 (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0))
175 self.assertEqual(revise(*mod.st[1][1:]), 175 self.assertEqual(revise(*mod.st[1][1:]),
176 (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0)) 176 (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0))
177 self.assertEqual(revise(*mod.st[2][1:]), 177 self.assertEqual(revise(*mod.st[2][1:]),
178 (modfile, 43, 'argue', [' spam(a, b, c)\n'], 0)) 178 (modfile, 43, 'argue', [' spam(a, b, c)\n'], 0))
179 self.assertEqual(revise(*mod.st[3][1:]), 179 self.assertEqual(revise(*mod.st[3][1:]),
180 (modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0)) 180 (modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0))
181 181
182 def test_trace(self): 182 def test_trace(self):
(...skipping 2191 matching lines...) Expand 10 before | Expand all | Expand 10 after
2374 P('foo', P.POSITIONAL_ONLY), 2374 P('foo', P.POSITIONAL_ONLY),
2375 P('bar', P.VAR_POSITIONAL)])), 2375 P('bar', P.VAR_POSITIONAL)])),
2376 '(foo, /, *bar)') 2376 '(foo, /, *bar)')
2377 2377
2378 def test_signature_replace_anno(self): 2378 def test_signature_replace_anno(self):
2379 def test() -> 42: 2379 def test() -> 42:
2380 pass 2380 pass
2381 2381
2382 sig = inspect.signature(test) 2382 sig = inspect.signature(test)
2383 sig = sig.replace(return_annotation=None) 2383 sig = sig.replace(return_annotation=None)
2384 self.assertIs(sig.return_annotation, None) 2384 self.assertIsNone(sig.return_annotation)
2385 sig = sig.replace(return_annotation=sig.empty) 2385 sig = sig.replace(return_annotation=sig.empty)
2386 self.assertIs(sig.return_annotation, sig.empty) 2386 self.assertIs(sig.return_annotation, sig.empty)
2387 sig = sig.replace(return_annotation=42) 2387 sig = sig.replace(return_annotation=42)
2388 self.assertEqual(sig.return_annotation, 42) 2388 self.assertEqual(sig.return_annotation, 42)
2389 self.assertEqual(sig, inspect.signature(test)) 2389 self.assertEqual(sig, inspect.signature(test))
2390 2390
2391 2391
2392 class TestParameterObject(unittest.TestCase): 2392 class TestParameterObject(unittest.TestCase):
2393 def test_signature_parameter_kinds(self): 2393 def test_signature_parameter_kinds(self):
2394 P = inspect.Parameter 2394 P = inspect.Parameter
2395 self.assertTrue(P.POSITIONAL_ONLY < P.POSITIONAL_OR_KEYWORD < \ 2395 self.assertTrue(P.POSITIONAL_ONLY < P.POSITIONAL_OR_KEYWORD < \
2396 P.VAR_POSITIONAL < P.KEYWORD_ONLY < P.VAR_KEYWORD) 2396 P.VAR_POSITIONAL < P.KEYWORD_ONLY < P.VAR_KEYWORD)
2397 2397
2398 self.assertEqual(str(P.POSITIONAL_ONLY), 'POSITIONAL_ONLY') 2398 self.assertEqual(str(P.POSITIONAL_ONLY), 'POSITIONAL_ONLY')
2399 self.assertTrue('POSITIONAL_ONLY' in repr(P.POSITIONAL_ONLY)) 2399 self.assertIn('POSITIONAL_ONLY', repr(P.POSITIONAL_ONLY))
2400 2400
2401 def test_signature_parameter_object(self): 2401 def test_signature_parameter_object(self):
2402 p = inspect.Parameter('foo', default=10, 2402 p = inspect.Parameter('foo', default=10,
2403 kind=inspect.Parameter.POSITIONAL_ONLY) 2403 kind=inspect.Parameter.POSITIONAL_ONLY)
2404 self.assertEqual(p.name, 'foo') 2404 self.assertEqual(p.name, 'foo')
2405 self.assertEqual(p.default, 10) 2405 self.assertEqual(p.default, 10)
2406 self.assertIs(p.annotation, p.empty) 2406 self.assertIs(p.annotation, p.empty)
2407 self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY) 2407 self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
2408 2408
2409 with self.assertRaisesRegex(ValueError, 'invalid value'): 2409 with self.assertRaisesRegex(ValueError, 'invalid value'):
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
2465 2465
2466 p2 = p2.replace(name='bar') 2466 p2 = p2.replace(name='bar')
2467 self.assertEqual(p2.name, 'bar') 2467 self.assertEqual(p2.name, 'bar')
2468 self.assertNotEqual(p2, p) 2468 self.assertNotEqual(p2, p)
2469 2469
2470 with self.assertRaisesRegex(ValueError, 2470 with self.assertRaisesRegex(ValueError,
2471 'name is a required attribute'): 2471 'name is a required attribute'):
2472 p2 = p2.replace(name=p2.empty) 2472 p2 = p2.replace(name=p2.empty)
2473 2473
2474 p2 = p2.replace(name='foo', default=None) 2474 p2 = p2.replace(name='foo', default=None)
2475 self.assertIs(p2.default, None) 2475 self.assertIsNone(p2.default)
2476 self.assertNotEqual(p2, p) 2476 self.assertNotEqual(p2, p)
2477 2477
2478 p2 = p2.replace(name='foo', default=p2.empty) 2478 p2 = p2.replace(name='foo', default=p2.empty)
2479 self.assertIs(p2.default, p2.empty) 2479 self.assertIs(p2.default, p2.empty)
2480 2480
2481 2481
2482 p2 = p2.replace(default=42, kind=p2.POSITIONAL_OR_KEYWORD) 2482 p2 = p2.replace(default=42, kind=p2.POSITIONAL_OR_KEYWORD)
2483 self.assertEqual(p2.kind, p2.POSITIONAL_OR_KEYWORD) 2483 self.assertEqual(p2.kind, p2.POSITIONAL_OR_KEYWORD)
2484 self.assertNotEqual(p2, p) 2484 self.assertNotEqual(p2, p)
2485 2485
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after
2873 TestInterpreterStack, TestClassesAndFunctions, TestPredicates, 2873 TestInterpreterStack, TestClassesAndFunctions, TestPredicates,
2874 TestGetcallargsFunctions, TestGetcallargsMethods, 2874 TestGetcallargsFunctions, TestGetcallargsMethods,
2875 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState, 2875 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
2876 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject, 2876 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
2877 TestBoundArguments, TestSignaturePrivateHelpers, TestGetClosureVars, 2877 TestBoundArguments, TestSignaturePrivateHelpers, TestGetClosureVars,
2878 TestUnwrap, TestMain 2878 TestUnwrap, TestMain
2879 ) 2879 )
2880 2880
2881 if __name__ == "__main__": 2881 if __name__ == "__main__":
2882 test_main() 2882 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_hmac.py ('k') | Lib/test/test_iter.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+