Simplify test case example code
This commit is contained in:
parent
5bbeffbeb0
commit
d5f14bd374
24
pep-0399.txt
24
pep-0399.txt
|
@ -116,8 +116,7 @@ possible.
|
|||
As an example, to write tests which exercise both the pure Python and
|
||||
C accelerated versions of a module, a basic idiom can be followed::
|
||||
|
||||
import collections.abc
|
||||
from test.support import import_fresh_module, run_unittest
|
||||
from test.support import import_fresh_module
|
||||
import unittest
|
||||
|
||||
c_heapq = import_fresh_module('heapq', fresh=['_heapq'])
|
||||
|
@ -126,30 +125,17 @@ C accelerated versions of a module, a basic idiom can be followed::
|
|||
|
||||
class ExampleTest:
|
||||
|
||||
def test_heappop_exc_for_non_MutableSequence(self):
|
||||
# Raise TypeError when heap is not a
|
||||
# collections.abc.MutableSequence.
|
||||
class Spam:
|
||||
"""Test class lacking many ABC-required methods
|
||||
(e.g., pop())."""
|
||||
def __len__(self):
|
||||
return 0
|
||||
|
||||
heap = Spam()
|
||||
self.assertIsInstance(heap, collections.abc.MutableSequence)
|
||||
with self.assertRaises(TypeError):
|
||||
self.heapq.heappop(heap)
|
||||
def test_example(self):
|
||||
self.assertTrue(hasattr(self.module, 'heapify'))
|
||||
|
||||
|
||||
class PyExampleTest(ExampleTest, unittest.TestCase):
|
||||
"""Test with just the pure Python code."""
|
||||
heapq = py_heapq
|
||||
module = py_heapq
|
||||
|
||||
|
||||
@unittest.skipUnless(c_heapq, 'requires the C _heapq module')
|
||||
class CExampleTest(ExampleTest, unittest.TestCase):
|
||||
"""Test using the accelerated code."""
|
||||
heapq = c_heapq
|
||||
module = c_heapq
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue