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

Side by Side Diff: Lib/test/test_memoryview.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_logging.py ('k') | Lib/test/test_minidom.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 """Unit tests for the memoryview 1 """Unit tests for the memoryview
2 2
3 Some tests are in test_bytes. Many tests that require _testbuffer.ndarray 3 Some tests are in test_bytes. Many tests that require _testbuffer.ndarray
4 are in test_buffer. 4 are in test_buffer.
5 """ 5 """
6 6
7 import unittest 7 import unittest
8 import test.support 8 import test.support
9 import sys 9 import sys
10 import gc 10 import gc
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 # This exercises mbuf_clear(). 230 # This exercises mbuf_clear().
231 b = MySource(tp(b'abc')) 231 b = MySource(tp(b'abc'))
232 m = self._view(b) 232 m = self._view(b)
233 o = MyObject() 233 o = MyObject()
234 b.m = m 234 b.m = m
235 b.o = o 235 b.o = o
236 wr = weakref.ref(o) 236 wr = weakref.ref(o)
237 b = m = o = None 237 b = m = o = None
238 # The cycle must be broken 238 # The cycle must be broken
239 gc.collect() 239 gc.collect()
240 self.assertTrue(wr() is None, wr()) 240 self.assertIsNone(wr())
241 241
242 # This exercises memory_clear(). 242 # This exercises memory_clear().
243 m = MyView(tp(b'abc')) 243 m = MyView(tp(b'abc'))
244 o = MyObject() 244 o = MyObject()
245 m.x = m 245 m.x = m
246 m.o = o 246 m.o = o
247 wr = weakref.ref(o) 247 wr = weakref.ref(o)
248 m = o = None 248 m = o = None
249 # The cycle must be broken 249 # The cycle must be broken
250 gc.collect() 250 gc.collect()
251 self.assertTrue(wr() is None, wr()) 251 self.assertIsNone(wr())
252 252
253 def _check_released(self, m, tp): 253 def _check_released(self, m, tp):
254 check = self.assertRaisesRegex(ValueError, "released") 254 check = self.assertRaisesRegex(ValueError, "released")
255 with check: bytes(m) 255 with check: bytes(m)
256 with check: m.tobytes() 256 with check: m.tobytes()
257 with check: m.tolist() 257 with check: m.tolist()
258 with check: m[0] 258 with check: m[0]
259 with check: m[0] = b'x' 259 with check: m[0] = b'x'
260 with check: len(m) 260 with check: len(m)
261 with check: m.format 261 with check: m.format
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 for tp in self._types: 342 for tp in self._types:
343 b = tp(self._source) 343 b = tp(self._source)
344 m = self._view(b) 344 m = self._view(b)
345 L = [] 345 L = []
346 def callback(wr, b=b): 346 def callback(wr, b=b):
347 L.append(b) 347 L.append(b)
348 wr = weakref.ref(m, callback) 348 wr = weakref.ref(m, callback)
349 self.assertIs(wr(), m) 349 self.assertIs(wr(), m)
350 del m 350 del m
351 test.support.gc_collect() 351 test.support.gc_collect()
352 self.assertIs(wr(), None) 352 self.assertIsNone(wr())
353 self.assertIs(L[0], b) 353 self.assertIs(L[0], b)
354 354
355 def test_reversed(self): 355 def test_reversed(self):
356 for tp in self._types: 356 for tp in self._types:
357 b = tp(self._source) 357 b = tp(self._source)
358 m = self._view(b) 358 m = self._view(b)
359 aslist = list(reversed(m.tolist())) 359 aslist = list(reversed(m.tolist()))
360 self.assertEqual(list(reversed(m)), aslist) 360 self.assertEqual(list(reversed(m)), aslist)
361 self.assertEqual(list(reversed(m)), list(m[::-1])) 361 self.assertEqual(list(reversed(m)), list(m[::-1]))
362 362
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 class ArrayMemorySliceSliceTest(unittest.TestCase, 469 class ArrayMemorySliceSliceTest(unittest.TestCase,
470 BaseMemorySliceSliceTests, BaseArrayMemoryTests): 470 BaseMemorySliceSliceTests, BaseArrayMemoryTests):
471 pass 471 pass
472 472
473 473
474 def test_main(): 474 def test_main():
475 test.support.run_unittest(__name__) 475 test.support.run_unittest(__name__)
476 476
477 if __name__ == "__main__": 477 if __name__ == "__main__":
478 test_main() 478 test_main()
OLDNEW
« no previous file with comments | « Lib/test/test_logging.py ('k') | Lib/test/test_minidom.py » ('j') | no next file with comments »

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