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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 7 years, 2 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_import.py ('k') | Lib/test/test_int.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 re 1 import re
2 import sys 2 import sys
3 import types 3 import types
4 import unittest 4 import unittest
5 import inspect 5 import inspect
6 import linecache 6 import linecache
7 import datetime 7 import datetime
8 import collections 8 import collections
9 import os 9 import os
10 import shutil 10 import shutil
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 def __init__(self, *args, **kwargs): 154 def __init__(self, *args, **kwargs):
155 unittest.TestCase.__init__(self, *args, **kwargs) 155 unittest.TestCase.__init__(self, *args, **kwargs)
156 156
157 git.abuse(7, 8, 9) 157 git.abuse(7, 8, 9)
158 158
159 def test_abuse_done(self): 159 def test_abuse_done(self):
160 self.istest(inspect.istraceback, 'git.ex[2]') 160 self.istest(inspect.istraceback, 'git.ex[2]')
161 self.istest(inspect.isframe, 'mod.fr') 161 self.istest(inspect.isframe, 'mod.fr')
162 162
163 def test_stack(self): 163 def test_stack(self):
164 self.assertTrue(len(mod.st) >= 5) 164 self.assertGreaterEqual(len(mod.st), 5)
165 self.assertEqual(revise(*mod.st[0][1:]), 165 self.assertEqual(revise(*mod.st[0][1:]),
166 (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0)) 166 (modfile, 16, 'eggs', [' st = inspect.stack()\n'], 0))
167 self.assertEqual(revise(*mod.st[1][1:]), 167 self.assertEqual(revise(*mod.st[1][1:]),
168 (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0)) 168 (modfile, 9, 'spam', [' eggs(b + d, c + f)\n'], 0))
169 self.assertEqual(revise(*mod.st[2][1:]), 169 self.assertEqual(revise(*mod.st[2][1:]),
170 (modfile, 43, 'argue', [' spam(a, b, c)\n'], 0)) 170 (modfile, 43, 'argue', [' spam(a, b, c)\n'], 0))
171 self.assertEqual(revise(*mod.st[3][1:]), 171 self.assertEqual(revise(*mod.st[3][1:]),
172 (modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0)) 172 (modfile, 39, 'abuse', [' self.argue(a, b, c)\n'], 0))
173 173
174 def test_trace(self): 174 def test_trace(self):
(...skipping 1743 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 test.__signature__ = sig.replace(parameters=new_params) 1918 test.__signature__ = sig.replace(parameters=new_params)
1919 self.assertEqual(str(inspect.signature(test)), 1919 self.assertEqual(str(inspect.signature(test)),
1920 '(<0>, *, b, **kwargs)') 1920 '(<0>, *, b, **kwargs)')
1921 1921
1922 def test_signature_replace_anno(self): 1922 def test_signature_replace_anno(self):
1923 def test() -> 42: 1923 def test() -> 42:
1924 pass 1924 pass
1925 1925
1926 sig = inspect.signature(test) 1926 sig = inspect.signature(test)
1927 sig = sig.replace(return_annotation=None) 1927 sig = sig.replace(return_annotation=None)
1928 self.assertIs(sig.return_annotation, None) 1928 self.assertIsNone(sig.return_annotation)
1929 sig = sig.replace(return_annotation=sig.empty) 1929 sig = sig.replace(return_annotation=sig.empty)
1930 self.assertIs(sig.return_annotation, sig.empty) 1930 self.assertIs(sig.return_annotation, sig.empty)
1931 sig = sig.replace(return_annotation=42) 1931 sig = sig.replace(return_annotation=42)
1932 self.assertEqual(sig.return_annotation, 42) 1932 self.assertEqual(sig.return_annotation, 42)
1933 self.assertEqual(sig, inspect.signature(test)) 1933 self.assertEqual(sig, inspect.signature(test))
1934 1934
1935 1935
1936 class TestParameterObject(unittest.TestCase): 1936 class TestParameterObject(unittest.TestCase):
1937 def test_signature_parameter_kinds(self): 1937 def test_signature_parameter_kinds(self):
1938 P = inspect.Parameter 1938 P = inspect.Parameter
1939 self.assertTrue(P.POSITIONAL_ONLY < P.POSITIONAL_OR_KEYWORD < \ 1939 self.assertTrue(P.POSITIONAL_ONLY < P.POSITIONAL_OR_KEYWORD < \
1940 P.VAR_POSITIONAL < P.KEYWORD_ONLY < P.VAR_KEYWORD) 1940 P.VAR_POSITIONAL < P.KEYWORD_ONLY < P.VAR_KEYWORD)
1941 1941
1942 self.assertEqual(str(P.POSITIONAL_ONLY), 'POSITIONAL_ONLY') 1942 self.assertEqual(str(P.POSITIONAL_ONLY), 'POSITIONAL_ONLY')
1943 self.assertTrue('POSITIONAL_ONLY' in repr(P.POSITIONAL_ONLY)) 1943 self.assertIn('POSITIONAL_ONLY', repr(P.POSITIONAL_ONLY))
1944 1944
1945 def test_signature_parameter_object(self): 1945 def test_signature_parameter_object(self):
1946 p = inspect.Parameter('foo', default=10, 1946 p = inspect.Parameter('foo', default=10,
1947 kind=inspect.Parameter.POSITIONAL_ONLY) 1947 kind=inspect.Parameter.POSITIONAL_ONLY)
1948 self.assertEqual(p.name, 'foo') 1948 self.assertEqual(p.name, 'foo')
1949 self.assertEqual(p.default, 10) 1949 self.assertEqual(p.default, 10)
1950 self.assertIs(p.annotation, p.empty) 1950 self.assertIs(p.annotation, p.empty)
1951 self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY) 1951 self.assertEqual(p.kind, inspect.Parameter.POSITIONAL_ONLY)
1952 1952
1953 with self.assertRaisesRegex(ValueError, 'invalid value'): 1953 with self.assertRaisesRegex(ValueError, 'invalid value'):
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
2005 self.assertEqual(p, p2) 2005 self.assertEqual(p, p2)
2006 2006
2007 p2 = p2.replace(name='bar') 2007 p2 = p2.replace(name='bar')
2008 self.assertEqual(p2.name, 'bar') 2008 self.assertEqual(p2.name, 'bar')
2009 self.assertNotEqual(p2, p) 2009 self.assertNotEqual(p2, p)
2010 2010
2011 with self.assertRaisesRegex(ValueError, 'not a valid parameter name'): 2011 with self.assertRaisesRegex(ValueError, 'not a valid parameter name'):
2012 p2 = p2.replace(name=p2.empty) 2012 p2 = p2.replace(name=p2.empty)
2013 2013
2014 p2 = p2.replace(name='foo', default=None) 2014 p2 = p2.replace(name='foo', default=None)
2015 self.assertIs(p2.default, None) 2015 self.assertIsNone(p2.default)
2016 self.assertNotEqual(p2, p) 2016 self.assertNotEqual(p2, p)
2017 2017
2018 p2 = p2.replace(name='foo', default=p2.empty) 2018 p2 = p2.replace(name='foo', default=p2.empty)
2019 self.assertIs(p2.default, p2.empty) 2019 self.assertIs(p2.default, p2.empty)
2020 2020
2021 2021
2022 p2 = p2.replace(default=42, kind=p2.POSITIONAL_OR_KEYWORD) 2022 p2 = p2.replace(default=42, kind=p2.POSITIONAL_OR_KEYWORD)
2023 self.assertEqual(p2.kind, p2.POSITIONAL_OR_KEYWORD) 2023 self.assertEqual(p2.kind, p2.POSITIONAL_OR_KEYWORD)
2024 self.assertNotEqual(p2, p) 2024 self.assertNotEqual(p2, p)
2025 2025
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2273 TestDecorators, TestRetrievingSourceCode, TestOneliners, TestBuggyCases, 2273 TestDecorators, TestRetrievingSourceCode, TestOneliners, TestBuggyCases,
2274 TestInterpreterStack, TestClassesAndFunctions, TestPredicates, 2274 TestInterpreterStack, TestClassesAndFunctions, TestPredicates,
2275 TestGetcallargsFunctions, TestGetcallargsMethods, 2275 TestGetcallargsFunctions, TestGetcallargsMethods,
2276 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState, 2276 TestGetcallargsUnboundMethods, TestGetattrStatic, TestGetGeneratorState,
2277 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject, 2277 TestNoEOL, TestSignatureObject, TestSignatureBind, TestParameterObject,
2278 TestBoundArguments, TestGetClosureVars 2278 TestBoundArguments, TestGetClosureVars
2279 ) 2279 )
2280 2280
2281 if __name__ == "__main__": 2281 if __name__ == "__main__":
2282 test_main() 2282 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_import.py ('k') | Lib/test/test_int.py » ('j') | no next file with comments »

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