mirror of
https://github.com/virt-manager/virt-manager.git
synced 2024-12-23 17:34:21 +03:00
tests: Add run_without_testsuite_hacks decorator
This commit is contained in:
parent
e9dcb4056d
commit
f3b0830cf3
@ -144,15 +144,12 @@ class AddHardware(uiutils.UITestCase):
|
|||||||
uiutils.check_in_loop(lambda: not addhw.showing)
|
uiutils.check_in_loop(lambda: not addhw.showing)
|
||||||
uiutils.check_in_loop(lambda: details.active)
|
uiutils.check_in_loop(lambda: details.active)
|
||||||
|
|
||||||
|
@tests.utils.run_without_testsuite_hacks
|
||||||
def testQemuSearchCheck(self):
|
def testQemuSearchCheck(self):
|
||||||
os.environ.pop("VIRTINST_TEST_SUITE")
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
try:
|
with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile:
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
os.chmod(tmpdir, 0o700)
|
||||||
with tempfile.NamedTemporaryFile(dir=tmpdir) as tmpfile:
|
self._testQemuSearchCheck(tmpfile.name)
|
||||||
os.chmod(tmpdir, 0o700)
|
|
||||||
self._testQemuSearchCheck(tmpfile.name)
|
|
||||||
finally:
|
|
||||||
os.environ["VIRTINST_TEST_SUITE"] = "1"
|
|
||||||
|
|
||||||
def testAddDisks(self):
|
def testAddDisks(self):
|
||||||
"""
|
"""
|
||||||
|
@ -225,3 +225,17 @@ def diff_compare(actual_out, filename=None, expect_out=None):
|
|||||||
tofile="Generated Output"))
|
tofile="Generated Output"))
|
||||||
if diff:
|
if diff:
|
||||||
raise AssertionError("Conversion outputs did not match.\n%s" % 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
|
||||||
|
@ -193,28 +193,24 @@ class TestXMLMisc(unittest.TestCase):
|
|||||||
g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access
|
g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access
|
||||||
self.assertEqual(g.osinfo.name, "generic")
|
self.assertEqual(g.osinfo.name, "generic")
|
||||||
|
|
||||||
|
@utils.run_without_testsuite_hacks
|
||||||
def test_dir_searchable(self):
|
def test_dir_searchable(self):
|
||||||
# Normally the dir searchable test is skipped in the unittest,
|
# Normally the dir searchable test is skipped in the unittest,
|
||||||
# but let's contrive an example that should trigger all the code
|
# but let's contrive an example that should trigger all the code
|
||||||
# to ensure it isn't horribly broken
|
# to ensure it isn't horribly broken
|
||||||
from virtinst import diskbackend
|
from virtinst import diskbackend
|
||||||
oldtest = os.environ.pop("VIRTINST_TEST_SUITE")
|
uid = -1
|
||||||
try:
|
username = "fakeuser-zzzz"
|
||||||
uid = -1
|
with tempfile.TemporaryDirectory() as tmpdir:
|
||||||
username = "fakeuser-zzzz"
|
fixlist = diskbackend.is_path_searchable(tmpdir, uid, username)
|
||||||
with tempfile.TemporaryDirectory() as tmpdir:
|
self.assertTrue(bool(fixlist))
|
||||||
fixlist = diskbackend.is_path_searchable(tmpdir, uid, username)
|
errdict = diskbackend.set_dirs_searchable(fixlist, username)
|
||||||
self.assertTrue(bool(fixlist))
|
self.assertTrue(not bool(errdict))
|
||||||
errdict = diskbackend.set_dirs_searchable(fixlist, username)
|
|
||||||
self.assertTrue(not bool(errdict))
|
|
||||||
|
|
||||||
|
import getpass
|
||||||
import getpass
|
fixlist = diskbackend.is_path_searchable(
|
||||||
fixlist = diskbackend.is_path_searchable(
|
os.getcwd(), os.getuid(), getpass.getuser())
|
||||||
os.getcwd(), os.getuid(), getpass.getuser())
|
self.assertTrue(not bool(fixlist))
|
||||||
self.assertTrue(not bool(fixlist))
|
|
||||||
finally:
|
|
||||||
os.environ["VIRTINST_TEST_SUITE"] = oldtest
|
|
||||||
|
|
||||||
def test_nonpredicatble_generate(self):
|
def test_nonpredicatble_generate(self):
|
||||||
realconn = virtinst.cli.getConnection("test:///default")
|
realconn = virtinst.cli.getConnection("test:///default")
|
||||||
|
Loading…
Reference in New Issue
Block a user