[Python-checkins] peps: Simplify test case example code

brett.cannon python-checkins at python.org
Sun Jan 27 19:24:37 CET 2013


http://hg.python.org/peps/rev/82a98c8abf48
changeset: 4693:82a98c8abf48
user: Brett Cannon <brett at python.org>
date: Sun Jan 27 13:24:31 2013 -0500
summary:
 Simplify test case example code
files:
 pep-0399.txt | 24 +++++-------------------
 1 files changed, 5 insertions(+), 19 deletions(-)
diff --git a/pep-0399.txt b/pep-0399.txt
--- a/pep-0399.txt
+++ b/pep-0399.txt
@@ -116,8 +116,7 @@
 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 @@
 
 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__':
-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /