MCPcopy Index your code
hub / github.com/python/cpython / _test_one_class

Method _test_one_class

Lib/test/test_threading_local.py:126–160  ·  view source on GitHub ↗
(self, c)

Source from the content-addressed store, hash-verified

124 self.assertRaises(TypeError, self._local, 1)
125
126 def _test_one_class(self, c):
127 self._failed = "No error message set or cleared."
128 obj = c()
129 e1 = threading.Event()
130 e2 = threading.Event()
131
132 def f1():
133 obj.x = 'foo'
134 obj.y = 'bar'
135 del obj.y
136 e1.set()
137 e2.wait()
138
139 def f2():
140 try:
141 foo = obj.x
142 except AttributeError:
143 # This is expected -- we haven't set obj.x in this thread yet!
144 self._failed = "" # passed
145 else:
146 self._failed = ('Incorrectly got value %r from class %r\n' %
147 (foo, c))
148 sys.stderr.write(self._failed)
149
150 t1 = threading.Thread(target=f1)
151 t1.start()
152 e1.wait()
153 t2 = threading.Thread(target=f2)
154 t2.start()
155 t2.join()
156 # The test is done; just let t1 know it can exit, and wait for it.
157 e2.set()
158 t1.join()
159
160 self.assertFalse(self._failed, self._failed)
161
162 def test_threading_local(self):
163 self._test_one_class(self._local)

Callers 2

test_threading_localMethod · 0.95

Calls 7

startMethod · 0.95
waitMethod · 0.95
joinMethod · 0.95
setMethod · 0.95
EventMethod · 0.80
assertFalseMethod · 0.80
cClass · 0.70

Tested by

no test coverage detected