2018-04-04 16:35:41 +03:00
# This work is licensed under the GNU GPLv2 or later.
2018-03-20 22:00:02 +03:00
# See the COPYING file in the top-level directory.
2015-04-22 03:12:37 +03:00
import traceback
import unittest
import virtinst
2019-06-17 04:12:39 +03:00
from virtinst import log
2015-04-22 03:12:37 +03:00
2019-05-15 20:36:41 +03:00
_do_skip = None
2015-04-22 03:12:37 +03:00
class CheckPropsTest ( unittest . TestCase ) :
2015-04-22 21:44:52 +03:00
maxDiff = None
2019-05-15 20:36:41 +03:00
def _skipIfTestsFailed ( self ) :
2015-04-22 03:12:37 +03:00
# pylint: disable=protected-access
# Access to protected member, needed to unittest stuff
2019-05-15 20:36:41 +03:00
global _do_skip
if _do_skip is None :
_do_skip = False
try :
# Accessing an internal detail of unittest, but it's only
# to prevent incorrect output in the case that other tests
# failed or were skipped, which can give a false positive here
result = self . _outcome . result
_do_skip = bool (
result . errors or result . failures or result . skipped )
except Exception :
2019-06-17 04:12:39 +03:00
log . debug ( " unittest skip hack failed " , exc_info = True )
2015-04-22 03:12:37 +03:00
2019-05-15 20:36:41 +03:00
if _do_skip :
2018-02-22 22:57:10 +03:00
self . skipTest ( " skipping as other tests failed/skipped " )
2019-05-15 20:36:41 +03:00
def testCheckXMLBuilderProps ( self ) :
"""
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 .
If no tests failed or were skipped , we check to ensure the
test suite is tickling every XML property
"""
self . _skipIfTestsFailed ( )
# pylint: disable=protected-access
2015-04-22 03:12:37 +03:00
fail = [ p for p in virtinst . xmlbuilder . _allprops
if p not in virtinst . xmlbuilder . _seenprops ]
2018-02-22 22:57:10 +03:00
msg = None
2015-04-22 03:12:37 +03:00
try :
2017-05-05 18:39:59 +03:00
self . assertEqual ( [ ] , fail )
2015-04-22 03:12:37 +03:00
except AssertionError :
msg = " " . join ( traceback . format_exc ( ) ) + " \n \n "
msg + = ( " This means that there are XML properties that are \n "
" untested in the test suite. This could be caused \n "
" by a previous test suite failure, or if you added \n "
" a new property and didn ' t extend the test suite. \n "
2020-01-27 02:29:39 +03:00
" Look into extending test_cli.py and/or test_xmlparse.py. " )
2018-02-22 22:57:10 +03:00
if msg :
2015-04-22 03:12:37 +03:00
self . fail ( msg )
2019-05-15 20:36:41 +03:00
def testCheckCLISuboptions ( self ) :
"""
Track which command line suboptions and aliases we actually hit with
the test suite .
"""
self . _skipIfTestsFailed ( )
# pylint: disable=protected-access
from virtinst import cli
unchecked = cli . _SuboptChecker . get_unseen ( )
if unchecked :
msg = " \n \n "
msg + = " \n " . join ( sorted ( a for a in unchecked ) ) + " \n \n "
msg + = ( " These command line arguments or aliases are not checked \n "
" in the test suite. Please test them. \n "
" Total unchecked arguments: %s " % len ( unchecked ) )
self . fail ( msg )