[Python-checkins] cpython: in the tests of ElementTree, verify that the C accelerator is imported or not

eli.bendersky python-checkins at python.org
Thu Feb 16 05:53:17 CET 2012


http://hg.python.org/cpython/rev/ce0e8d238157
changeset:   74973:ce0e8d238157
user:        Eli Bendersky <eliben at gmail.com>
date:        Thu Feb 16 06:52:39 2012 +0200
summary:
  in the tests of ElementTree, verify that the C accelerator is imported or not imported as expected

files:
  Lib/test/test_xml_etree.py   |  10 ++++++++++
  Lib/test/test_xml_etree_c.py |  12 +++++++++++-
  2 files changed, 21 insertions(+), 1 deletions(-)


diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py
--- a/Lib/test/test_xml_etree.py
+++ b/Lib/test/test_xml_etree.py
@@ -1904,12 +1904,22 @@
         self.checkwarnings.__exit__(*args)
 
 
+class TestAcceleratorNotImported(unittest.TestCase):
+    # Test that the C accelerator was not imported for pyET
+    def test_correct_import_pyET(self):
+        # In the C accelerator, Element is just a factory function, not an
+        # actual class. In the Python version it's a class.
+        self.assertIsInstance(pyET.Element, type)
+
+
 def test_main(module=pyET):
     from test import test_xml_etree
 
     # The same doctests are used for both the Python and the C implementations
     test_xml_etree.ET = module
 
+    support.run_unittest(TestAcceleratorNotImported)
+
     # XXX the C module should give the same warnings as the Python module
     with CleanContext(quiet=(module is not pyET)):
         support.run_doctest(test_xml_etree, verbosity=True)
diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py
--- a/Lib/test/test_xml_etree_c.py
+++ b/Lib/test/test_xml_etree_c.py
@@ -46,6 +46,16 @@
         finally:
             data = None
 
+class TestAcceleratorImported(unittest.TestCase):
+    # Test that the C accelerator was imported, as expected
+    def test_correct_import_cET(self):
+        # In the C accelerator, Element is just a factory function, not an
+        # actual class. In the Python version it's a class.
+        self.assertNotIsInstance(cET.Element, type)
+
+    def test_correct_import_cET_alias(self):
+        self.assertNotIsInstance(cET_alias.Element, type)
+
 
 def test_main():
     from test import test_xml_etree, test_xml_etree_c
@@ -53,7 +63,7 @@
     # Run the tests specific to the C implementation
     support.run_doctest(test_xml_etree_c, verbosity=True)
 
-    support.run_unittest(MiscTests)
+    support.run_unittest(MiscTests, TestAcceleratorImported)
 
     # Run the same test suite as the Python module
     test_xml_etree.test_main(module=cET)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list