tests: Add run_without_testsuite_hacks decorator

This commit is contained in:
Cole Robinson 2019-06-08 09:11:00 -04:00
parent e9dcb4056d
commit f3b0830cf3
3 changed files with 31 additions and 24 deletions

View File

@ -144,15 +144,12 @@ class AddHardware(uiutils.UITestCase):
uiutils.check_in_loop(lambda: not addhw.showing)
uiutils.check_in_loop(lambda: details.active)
@tests.utils.run_without_testsuite_hacks
def testQemuSearchCheck(self):
os.environ.pop("VIRTINST_TEST_SUITE")
try:
with tempfile.TemporaryDirectory() as tmpdir:
with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile:
os.chmod(tmpdir, 0o700)
self._testQemuSearchCheck(tmpfile.name)
finally:
os.environ["VIRTINST_TEST_SUITE"] = "1"
with tempfile.TemporaryDirectory() as tmpdir:
with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile:
os.chmod(tmpdir, 0o700)
self._testQemuSearchCheck(tmpfile.name)
def testAddDisks(self):
"""

View File

@ -225,3 +225,17 @@ def diff_compare(actual_out, filename=None, expect_out=None):
tofile="Generated Output"))
if diff:
raise AssertionError("Conversion outputs did not match.\n%s" % diff)
def run_without_testsuite_hacks(cb):
"""
Decorator for unsetting the test suite env variable
"""
def wrapper_cb(*args, **kwargs):
origval = os.environ.pop("VIRTINST_TEST_SUITE", None)
try:
return cb(*args, **kwargs)
finally:
if origval:
os.environ["VIRTINST_TEST_SUITE"] = origval
return wrapper_cb

View File

@ -193,28 +193,24 @@ class TestXMLMisc(unittest.TestCase):
g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access
self.assertEqual(g.osinfo.name, "generic")
@utils.run_without_testsuite_hacks
def test_dir_searchable(self):
# Normally the dir searchable test is skipped in the unittest,
# but let's contrive an example that should trigger all the code
# to ensure it isn't horribly broken
from virtinst import diskbackend
oldtest = os.environ.pop("VIRTINST_TEST_SUITE")
try:
uid = -1
username = "fakeuser-zzzz"
with tempfile.TemporaryDirectory() as tmpdir:
fixlist = diskbackend.is_path_searchable(tmpdir, uid, username)
self.assertTrue(bool(fixlist))
errdict = diskbackend.set_dirs_searchable(fixlist, username)
self.assertTrue(not bool(errdict))
uid = -1
username = "fakeuser-zzzz"
with tempfile.TemporaryDirectory() as tmpdir:
fixlist = diskbackend.is_path_searchable(tmpdir, uid, username)
self.assertTrue(bool(fixlist))
errdict = diskbackend.set_dirs_searchable(fixlist, username)
self.assertTrue(not bool(errdict))
import getpass
fixlist = diskbackend.is_path_searchable(
os.getcwd(), os.getuid(), getpass.getuser())
self.assertTrue(not bool(fixlist))
finally:
os.environ["VIRTINST_TEST_SUITE"] = oldtest
import getpass
fixlist = diskbackend.is_path_searchable(
os.getcwd(), os.getuid(), getpass.getuser())
self.assertTrue(not bool(fixlist))
def test_nonpredicatble_generate(self):
realconn = virtinst.cli.getConnection("test:///default")