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

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

Issue 16510: Using appropriate checks in tests
Patch Set: Created 6 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_bz2.py ('k') | Lib/test/test_cgi.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 from __future__ import with_statement 4 from __future__ import with_statement
5 import os 5 import os
6 import pickle 6 import pickle
7 import random 7 import random
8 import subprocess 8 import subprocess
9 import sys 9 import sys
10 import time 10 import time
(...skipping 16 matching lines...) Expand all
27 27
28 class InstanceMethod: 28 class InstanceMethod:
29 id = _testcapi.instancemethod(id) 29 id = _testcapi.instancemethod(id)
30 testfunction = _testcapi.instancemethod(testfunction) 30 testfunction = _testcapi.instancemethod(testfunction)
31 31
32 class CAPITest(unittest.TestCase): 32 class CAPITest(unittest.TestCase):
33 33
34 def test_instancemethod(self): 34 def test_instancemethod(self):
35 inst = InstanceMethod() 35 inst = InstanceMethod()
36 self.assertEqual(id(inst), inst.id()) 36 self.assertEqual(id(inst), inst.id())
37 self.assertTrue(inst.testfunction() is inst) 37 self.assertIs(inst.testfunction(), inst)
38 self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__) 38 self.assertEqual(inst.testfunction.__doc__, testfunction.__doc__)
39 self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc __) 39 self.assertEqual(InstanceMethod.testfunction.__doc__, testfunction.__doc __)
40 40
41 InstanceMethod.testfunction.attribute = "test" 41 InstanceMethod.testfunction.attribute = "test"
42 self.assertEqual(testfunction.attribute, "test") 42 self.assertEqual(testfunction.attribute, "test")
43 self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute ", "test") 43 self.assertRaises(AttributeError, setattr, inst.testfunction, "attribute ", "test")
44 44
45 @unittest.skipUnless(threading, 'Threading required for this test.') 45 @unittest.skipUnless(threading, 'Threading required for this test.')
46 def test_no_FatalError_infinite_loop(self): 46 def test_no_FatalError_infinite_loop(self):
47 p = subprocess.Popen([sys.executable, "-c", 47 p = subprocess.Popen([sys.executable, "-c",
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 #this busy loop is where we expect to be interrupted to 134 #this busy loop is where we expect to be interrupted to
135 #run our callbacks. Note that callbacks are only run on the 135 #run our callbacks. Note that callbacks are only run on the
136 #main thread 136 #main thread
137 if False and support.verbose: 137 if False and support.verbose:
138 print("(%i)"%(len(l),),) 138 print("(%i)"%(len(l),),)
139 for i in range(1000): 139 for i in range(1000):
140 a = i*i 140 a = i*i
141 if context and not context.event.is_set(): 141 if context and not context.event.is_set():
142 continue 142 continue
143 count += 1 143 count += 1
144 self.assertTrue(count < 10000, 144 self.assertLess(count, 10000,
145 "timeout waiting for %i callbacks, got %i"%(n, len(l))) 145 "timeout waiting for %i callbacks, got %i"%(n, len(l)))
146 if False and support.verbose: 146 if False and support.verbose:
147 print("(%i)"%(len(l),)) 147 print("(%i)"%(len(l),))
148 148
149 def test_pendingcalls_threaded(self): 149 def test_pendingcalls_threaded(self):
150 150
151 #do every callback on a separate thread 151 #do every callback on a separate thread
152 n = 32 #total callbacks 152 n = 32 #total callbacks
153 threads = [] 153 threads = []
154 class foo(object):pass 154 class foo(object):pass
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 if threading: 359 if threading:
360 import time 360 import time
361 TestThreadState() 361 TestThreadState()
362 t = threading.Thread(target=TestThreadState) 362 t = threading.Thread(target=TestThreadState)
363 t.start() 363 t.start()
364 t.join() 364 t.join()
365 365
366 366
367 if __name__ == "__main__": 367 if __name__ == "__main__":
368 test_main() 368 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_bz2.py ('k') | Lib/test/test_cgi.py » ('j') | no next file with comments »

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