diff options
author | Eli Bendersky <eliben@gmail.com> | 2013-05-20 00:49:54 (GMT) |
---|---|---|
committer | Eli Bendersky <eliben@gmail.com> | 2013-05-20 00:49:54 (GMT) |
commit | e26fa1bdcbbffd5986630144a2e15795c5f83a19 (patch) | |
tree | b8365d25c370b85ec782458f273d3595dc4416f0 /Lib/test | |
parent | 3a36756ba102724bb2771ca9c4dfd9eb3e9dd85b (diff) | |
download | cpython-e26fa1bdcbbffd5986630144a2e15795c5f83a19.zip cpython-e26fa1bdcbbffd5986630144a2e15795c5f83a19.tar.gz cpython-e26fa1bdcbbffd5986630144a2e15795c5f83a19.tar.bz2 |
Add some testing to verify which module was imported in ET tests.
This is useful when mucking with import_fresh_module to either force or block
importing of the _elementtree accelerator. These tests in place provide an
immediate indication whether the accelerator was actually imported and overrode
the classes it should have.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_xml_etree.py | 8 | ||||
-rw-r--r-- | Lib/test/test_xml_etree_c.py | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/Lib/test/test_xml_etree.py b/Lib/test/test_xml_etree.py index 2222c86..9d61ed7 100644 --- a/Lib/test/test_xml_etree.py +++ b/Lib/test/test_xml_etree.py @@ -10,6 +10,7 @@ import io import operator import pickle import sys +import types import unittest import weakref @@ -2398,8 +2399,11 @@ class NoAcceleratorTest(unittest.TestCase): # Test that the C accelerator was not imported for pyET def test_correct_import_pyET(self): - self.assertEqual(pyET.Element.__module__, 'xml.etree.ElementTree') - self.assertEqual(pyET.SubElement.__module__, 'xml.etree.ElementTree') + # The type of methods defined in Python code is types.FunctionType, + # while the type of methods defined inside _elementtree is + # <class 'wrapper_descriptor'> + self.assertIsInstance(pyET.Element.__init__, types.FunctionType) + self.assertIsInstance(pyET.XMLParser.__init__, types.FunctionType) # -------------------------------------------------------------------- diff --git a/Lib/test/test_xml_etree_c.py b/Lib/test/test_xml_etree_c.py index bcaa724..b3ff7ae 100644 --- a/Lib/test/test_xml_etree_c.py +++ b/Lib/test/test_xml_etree_c.py @@ -2,6 +2,7 @@ import sys, struct from test import support from test.support import import_fresh_module +import types import unittest cET = import_fresh_module('xml.etree.ElementTree', @@ -33,14 +34,22 @@ class TestAliasWorking(unittest.TestCase): @unittest.skipUnless(cET, 'requires _elementtree') +@support.cpython_only class TestAcceleratorImported(unittest.TestCase): # Test that the C accelerator was imported, as expected def test_correct_import_cET(self): + # SubElement is a function so it retains _elementtree as its module. self.assertEqual(cET.SubElement.__module__, '_elementtree') def test_correct_import_cET_alias(self): self.assertEqual(cET_alias.SubElement.__module__, '_elementtree') + def test_parser_comes_from_C(self): + # The type of methods defined in Python code is types.FunctionType, + # while the type of methods defined inside _elementtree is + # <class 'wrapper_descriptor'> + self.assertNotIsInstance(cET.Element.__init__, types.FunctionType) + @unittest.skipUnless(cET, 'requires _elementtree') @support.cpython_only |