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

Delta Between Two Patch Sets: Lib/test/test_capi.py

Issue 16510: Using appropriate checks in tests
Left Patch Set: Created 5 years, 9 months ago
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « Lib/test/test_bz2.py ('k') | Lib/test/test_cmd_line.py » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
11 from test import support 11 from test import support
12 from test.support import MISSING_C_DOCSTRINGS
12 try: 13 try:
13 import _posixsubprocess 14 import _posixsubprocess
14 except ImportError: 15 except ImportError:
15 _posixsubprocess = None 16 _posixsubprocess = None
16 try: 17 try:
17 import threading 18 import threading
18 except ImportError: 19 except ImportError:
19 threading = None 20 threading = None
20 import _testcapi 21 # Skip this test if the _testcapi module isn't available.
22 _testcapi = support.import_module('_testcapi')
21 23
22 24
23 def testfunction(self): 25 def testfunction(self):
24 """some doc""" 26 """some doc"""
25 return self 27 return self
26 28
27 class InstanceMethod: 29 class InstanceMethod:
28 id = _testcapi.instancemethod(id) 30 id = _testcapi.instancemethod(id)
29 testfunction = _testcapi.instancemethod(testfunction) 31 testfunction = _testcapi.instancemethod(testfunction)
30 32
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 103
102 @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this t est.') 104 @unittest.skipUnless(_posixsubprocess, '_posixsubprocess required for this t est.')
103 def test_subprocess_fork_exec(self): 105 def test_subprocess_fork_exec(self):
104 class Z(object): 106 class Z(object):
105 def __len__(self): 107 def __len__(self):
106 return 1 108 return 1
107 109
108 # Issue #15738: crash in subprocess_fork_exec() 110 # Issue #15738: crash in subprocess_fork_exec()
109 self.assertRaises(TypeError, _posixsubprocess.fork_exec, 111 self.assertRaises(TypeError, _posixsubprocess.fork_exec,
110 Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17) 112 Z(),[b'1'],3,[1, 2],5,6,7,8,9,10,11,12,13,14,15,16,17)
113
114 @unittest.skipIf(MISSING_C_DOCSTRINGS,
115 "Signature information for builtins requires docstrings")
116 def test_docstring_signature_parsing(self):
117
118 self.assertEqual(_testcapi.no_docstring.__doc__, None)
119 self.assertEqual(_testcapi.no_docstring.__text_signature__, None)
120
121 self.assertEqual(_testcapi.docstring_empty.__doc__, "")
122 self.assertEqual(_testcapi.docstring_empty.__text_signature__, None)
123
124 self.assertEqual(_testcapi.docstring_no_signature.__doc__,
125 "This docstring has no signature.")
126 self.assertEqual(_testcapi.docstring_no_signature.__text_signature__, No ne)
127
128 self.assertEqual(_testcapi.docstring_with_invalid_signature.__doc__,
129 "sig= (module, boo)\n"
130 "\n"
131 "This docstring has an invalid signature."
132 )
133 self.assertEqual(_testcapi.docstring_with_invalid_signature.__text_signa ture__, None)
134
135 self.assertEqual(_testcapi.docstring_with_signature.__doc__,
136 "This docstring has a valid signature.")
137 self.assertEqual(_testcapi.docstring_with_signature.__text_signature__, "(module, sig)")
138
139 self.assertEqual(_testcapi.docstring_with_signature_and_extra_newlines._ _doc__,
140 "This docstring has a valid signature and some extra newlines.")
141 self.assertEqual(_testcapi.docstring_with_signature_and_extra_newlines._ _text_signature__,
142 "(module, parameter)")
143
111 144
112 @unittest.skipUnless(threading, 'Threading required for this test.') 145 @unittest.skipUnless(threading, 'Threading required for this test.')
113 class TestPendingCalls(unittest.TestCase): 146 class TestPendingCalls(unittest.TestCase):
114 147
115 def pendingcalls_submit(self, l, n): 148 def pendingcalls_submit(self, l, n):
116 def callback(): 149 def callback():
117 #this function can be interrupted by thread switching so let's 150 #this function can be interrupted by thread switching so let's
118 #use an atomic operation 151 #use an atomic operation
119 l.append(None) 152 l.append(None)
120 153
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 def test_subinterps(self): 231 def test_subinterps(self):
199 import builtins 232 import builtins
200 r, w = os.pipe() 233 r, w = os.pipe()
201 code = """if 1: 234 code = """if 1:
202 import sys, builtins, pickle 235 import sys, builtins, pickle
203 with open({:d}, "wb") as f: 236 with open({:d}, "wb") as f:
204 pickle.dump(id(sys.modules), f) 237 pickle.dump(id(sys.modules), f)
205 pickle.dump(id(builtins), f) 238 pickle.dump(id(builtins), f)
206 """.format(w) 239 """.format(w)
207 with open(r, "rb") as f: 240 with open(r, "rb") as f:
208 ret = _testcapi.run_in_subinterp(code) 241 ret = support.run_in_subinterp(code)
209 self.assertEqual(ret, 0) 242 self.assertEqual(ret, 0)
210 self.assertNotEqual(pickle.load(f), id(sys.modules)) 243 self.assertNotEqual(pickle.load(f), id(sys.modules))
211 self.assertNotEqual(pickle.load(f), id(builtins)) 244 self.assertNotEqual(pickle.load(f), id(builtins))
212 245
213 246
214 # Bug #6012 247 # Bug #6012
215 class Test6012(unittest.TestCase): 248 class Test6012(unittest.TestCase):
216 def test(self): 249 def test(self):
217 self.assertEqual(_testcapi.argparsing("Hello", "World"), 1) 250 self.assertEqual(_testcapi.argparsing("Hello", "World"), 1)
218 251
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 class Test_testcapi(unittest.TestCase): 451 class Test_testcapi(unittest.TestCase):
419 def test__testcapi(self): 452 def test__testcapi(self):
420 for name in dir(_testcapi): 453 for name in dir(_testcapi):
421 if name.startswith('test_'): 454 if name.startswith('test_'):
422 with self.subTest("internal", name=name): 455 with self.subTest("internal", name=name):
423 test = getattr(_testcapi, name) 456 test = getattr(_testcapi, name)
424 test() 457 test()
425 458
426 if __name__ == "__main__": 459 if __name__ == "__main__":
427 unittest.main() 460 unittest.main()
LEFTRIGHT

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