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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 5 years, 6 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_bz2.py ('k') | Lib/test/test_cmd_line.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 # Run the _testcapi module tests (tests for the Python/C API): by defn, 1 # Run the _testcapi module tests (tests for the Python/C API): by defn,
2 # these are all functions _testcapi exports whose name begins with 'test_'. 2 # these are all functions _testcapi exports whose name begins with 'test_'.
3 3
4 import os 4 import os
5 import pickle 5 import pickle
6 import random 6 import random
7 import subprocess 7 import subprocess
8 import sys 8 import sys
9 import time 9 import time
10 import unittest 10 import unittest
(...skipping 17 matching lines...) Expand all
28 28
29 class InstanceMethod: 29 class InstanceMethod:
30 id = _testcapi.instancemethod(id) 30 id = _testcapi.instancemethod(id)
31 testfunction = _testcapi.instancemethod(testfunction) 31 testfunction = _testcapi.instancemethod(testfunction)
32 32
33 class CAPITest(unittest.TestCase): 33 class CAPITest(unittest.TestCase):
34 34
35 def test_instancemethod(self): 35 def test_instancemethod(self):
36 inst = InstanceMethod() 36 inst = InstanceMethod()
37 self.assertEqual(id(inst), inst.id()) 37 self.assertEqual(id(inst), inst.id())
38 self.assertTrue(inst.testfunction() is inst) 38 self.assertIs(inst.testfunction(), inst)
39 self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__) 39 self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__)
40 self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc __) 40 self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc __)
41 41
42 InstanceMethod.testfunction.attribute = "test" 42 InstanceMethod.testfunction.attribute = "test"
43 self.assertEqual(testfunction.attribute, "test") 43 self.assertEqual(testfunction.attribute, "test")
44 self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute ", "test") 44 self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute ", "test")
45 45
46 @unittest.skipUnless(threading, 'Threading required for this test.') 46 @unittest.skipUnless(threading, 'Threading required for this test.')
47 def test_no_FatalError_infinite_loop(self): 47 def test_no_FatalError_infinite_loop(self):
48 with support.SuppressCrashReport(): 48 with support.SuppressCrashReport():
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 #this busy loop is where we expect to be interrupted to 167 #this busy loop is where we expect to be interrupted to
168 #run our callbacks. Note that callbacks are only run on the 168 #run our callbacks. Note that callbacks are only run on the
169 #main thread 169 #main thread
170 if False and support.verbose: 170 if False and support.verbose:
171 print("(%i)"%(len(l),),) 171 print("(%i)"%(len(l),),)
172 for i in range(1000): 172 for i in range(1000):
173 a = i*i 173 a = i*i
174 if context and not context.event.is_set(): 174 if context and not context.event.is_set():
175 continue 175 continue
176 count += 1 176 count += 1
177 self.assertTrue(count < 10000, 177 self.assertLess(count, 10000,
178 "timeout waiting for %i callbacks, got %i"%(n, len(l))) 178 "timeout waiting for %i callbacks, got %i"%(n, len(l)))
179 if False and support.verbose: 179 if False and support.verbose:
180 print("(%i)"%(len(l),)) 180 print("(%i)"%(len(l),))
181 181
182 def test_pendingcalls_threaded(self): 182 def test_pendingcalls_threaded(self):
183 183
184 #do every callback on a separate thread 184 #do every callback on a separate thread
185 n = 32 #total callbacks 185 n = 32 #total callbacks
186 threads = [] 186 threads = []
187 class foo(object):pass 187 class foo(object):pass
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 class Test_testcapi(unittest.TestCase): 451 class Test_testcapi(unittest.TestCase):
452 def test__testcapi(self): 452 def test__testcapi(self):
453 for name in dir(_testcapi): 453 for name in dir(_testcapi):
454 if name.startswith('test_'): 454 if name.startswith('test_'):
455 with self.subTest("internal", name=name): 455 with self.subTest("internal", name=name):
456 test = getattr(_testcapi, name) 456 test = getattr(_testcapi, name)
457 test() 457 test()
458 458
459 if __name__ == "__main__": 459 if __name__ == "__main__":
460 unittest.main() 460 unittest.main()
OLDNEW
« no previous file with comments | « Lib/test/test_bz2.py ('k') | Lib/test/test_cmd_line.py » ('j') | no next file with comments »

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