Compatibility import for ElementTree

This commit is contained in:
Henrik Holmboe 2013-09-27 00:58:17 +02:00
parent a8d258cefc
commit 008a1b7fc9
2 changed files with 19 additions and 2 deletions

View File

@ -11,6 +11,23 @@ try:
import cPickle as pickle
except ImportError:
import pickle
try:
# Python >2.5
import xml.etree.cElementTree as ElementTree
except ImportError:
try:
# Python >2.5
import xml.etree.ElementTree as ElementTree
except ImportError:
try:
# normal cElementTree install
import cElementTree as ElementTree
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as ElementTree
except ImportError:
raise
# True if we are running on Python 3.

View File

@ -12,7 +12,7 @@ ensure_in_syspath('../../')
# Import salt libs
from salt.modules import virt
from salt._compat import StringIO as _StringIO
from salt._compat import StringIO as _StringIO, ElementTree as _ElementTree
virt.__salt__ = {}
@ -87,7 +87,7 @@ class VirtTestCase(TestCase):
'esxi',
eth1_mac='00:00:00:00:00:00',
)
tree = ElementTree.parse(_StringIO(xml_data))
tree = _ElementTree.parse(_StringIO(xml_data))
self.assertTrue(tree.getroot().attrib['type'] == 'vmware')
self.assertTrue(tree.find('vcpu').text == '1')
self.assertTrue(tree.find('memory').text == '524288')