tests: Verify that every new style XML prop is exercised

coverage isn't going to help us much here, so add some hacky infrastructure
to ensure that xmlparse.py is touching every new style xmlprop.
This commit is contained in:
Cole Robinson 2013-07-12 15:16:29 -04:00
parent dcd632da80
commit ce243314c0
3 changed files with 52 additions and 10 deletions

View File

@ -17,6 +17,8 @@
import logging
import os
os.environ["VIRTINST_TEST_TRACKPROPS"] = "1"
import virtinst
from tests import utils

View File

@ -14,9 +14,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301 USA.
import unittest
import glob
import traceback
import unittest
import virtinst
@ -89,6 +89,11 @@ class XMLParseTest(unittest.TestCase):
parsexml=file(infile).read())
return guest, outfile
def test000ClearProps(self):
# pylint: disable=W0212
# Access to protected member, needed to unittest stuff
virtinst.XMLBuilderDomain._seenprops = []
def testAlterGuest(self):
"""
Test changing Guest() parameters after parsing
@ -748,5 +753,22 @@ class XMLParseTest(unittest.TestCase):
self._alter_compare(guest.get_xml_config(), outfile)
def testzzzzCheckProps(self):
# pylint: disable=W0212
# Access to protected member, needed to unittest stuff
# If a certain environment variable is set, XMLBuilder tracks
# every property registered and every one of those that is
# actually altered. The test suite sets that env variable.
#
# test000ClearProps resets the 'set' list, and this test
# ensures that every property we know about has been touched
# by one of the above tests.
from virtinst import XMLBuilderDomain
fail = [p for p in XMLBuilderDomain._allprops
if p not in XMLBuilderDomain._seenprops]
self.assertEquals(fail, [])
if __name__ == "__main__":
unittest.main()

View File

@ -20,12 +20,18 @@
# MA 02110-1301 USA.
import copy
import os
import libxml2
from virtinst import util
_trackprops = bool("VIRTINST_TEST_TRACKPROPS" in os.environ)
_allprops = []
_seenprops = []
class _DocCleanupWrapper(object):
def __init__(self, doc):
self._doc = doc
@ -205,7 +211,19 @@ def _remove_xpath_node(ctx, xpath, dofree=True):
node.freeNode()
def _xml_property(fget=None, fset=None, fdel=None, doc=None,
class _XMLProperty(property):
def __init__(self, fget, fset, doc, xpath):
property.__init__(self, fget=fget, fset=fset, doc=doc)
self._xpath = xpath
def __repr__(self):
ret = property.__repr__(self)
if self._xpath:
ret = "<XMLProperty %s>" % str(self._xpath)
return ret
def _xml_property(fget=None, fset=None, doc=None,
xpath=None, get_converter=None, set_converter=None,
xml_get_xpath=None, xml_set_xpath=None,
xml_set_list=None, is_bool=False, is_multi=False,
@ -223,7 +241,6 @@ def _xml_property(fget=None, fset=None, fdel=None, doc=None,
@param fget: typical getter function for the property
@param fset: typical setter function for the property
@param fdel: typical deleter function for the property
@param doc: option doc string for the property
@param xpath: xpath string which maps to the associated property
in a typical XML document
@ -254,6 +271,8 @@ def _xml_property(fget=None, fset=None, fdel=None, doc=None,
raise RuntimeError("Didn't find expected property")
def _default_fset(self, val, *args, **kwargs):
if _trackprops and retprop not in _seenprops:
_seenprops.append(retprop)
ignore = args
ignore = kwargs
propname = _findpropname(self)
@ -267,10 +286,11 @@ def _xml_property(fget=None, fset=None, fdel=None, doc=None,
ignore = kwargs
return self._propstore.get(_findpropname(self), None)
isdefault = False
if not fget:
fget = _default_fget
if not fset:
fset = _default_fset
isdefault = True
def new_getter(self, *args, **kwargs):
val = None
@ -355,12 +375,10 @@ def _xml_property(fget=None, fset=None, fdel=None, doc=None,
else:
_remove_xpath_node(self._xml_node, use_xpath)
if fdel:
# Not tested
raise RuntimeError("XML deleter not yet supported.")
retprop = property(fget=new_getter, fset=new_setter, doc=doc)
retprop = _XMLProperty(new_getter, new_setter, doc,
(xpath or xml_set_xpath or xml_get_xpath))
if _trackprops and isdefault:
_allprops.append(retprop)
return retprop