tests: Drop most unittest usage from virtinst tests

Kill usage of the TestCase class, move more to pytest standard
style

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2020-09-18 16:26:28 -04:00
parent b79ee9565f
commit fa322588b4
12 changed files with 1770 additions and 1733 deletions

View File

@ -4,7 +4,6 @@
# See the COPYING file in the top-level directory.
import os
import unittest
import pytest
@ -17,18 +16,18 @@ from virtinst import DomainCapabilities
DATADIR = utils.DATADIR + "/capabilities"
class TestCapabilities(unittest.TestCase):
def _buildCaps(self, filename):
def _buildCaps(filename):
path = os.path.join(DATADIR, filename)
conn = utils.URIs.open_testdefault_cached()
return Capabilities(conn, open(path).read())
def testCapsCPUFeaturesNewSyntax(self):
def testCapsCPUFeaturesNewSyntax():
filename = "test-qemu-with-kvm.xml"
host_feature_list = ['lahf_lm', 'xtpr', 'cx16', 'tm2', 'est', 'vmx',
'ds_cpl', 'pbe', 'tm', 'ht', 'ss', 'acpi', 'ds']
caps = self._buildCaps(filename)
caps = _buildCaps(filename)
for f in host_feature_list:
assert f in [feat.name for feat in caps.host.cpu.features]
@ -38,10 +37,11 @@ class TestCapabilities(unittest.TestCase):
assert caps.host.cpu.topology.cores == 5
assert caps.host.cpu.topology.sockets == 7
def testCapsUtilFuncs(self):
caps_with_kvm = self._buildCaps("test-qemu-with-kvm.xml")
caps_no_kvm = self._buildCaps("test-qemu-no-kvm.xml")
caps_empty = self._buildCaps("test-empty.xml")
def testCapsUtilFuncs():
caps_with_kvm = _buildCaps("test-qemu-with-kvm.xml")
caps_no_kvm = _buildCaps("test-qemu-no-kvm.xml")
caps_empty = _buildCaps("test-empty.xml")
def test_utils(caps, has_guests, is_kvm):
assert caps.has_install_options() == has_guests
@ -52,14 +52,15 @@ class TestCapabilities(unittest.TestCase):
test_utils(caps_with_kvm, True, True)
test_utils(caps_no_kvm, True, False)
# Small test for extra unittest coverage
# Small test for extra coverage
with pytest.raises(ValueError, match=r".*virtualization type 'xen'.*"):
caps_empty.guest_lookup(os_type="linux")
with pytest.raises(ValueError, match=r".*not support any.*"):
caps_empty.guest_lookup()
def testCapsNuma(self):
cells = self._buildCaps("lxc.xml").host.topology.cells
def testCapsNuma():
cells = _buildCaps("lxc.xml").host.topology.cells
assert len(cells) == 1
assert len(cells[0].cpus) == 8
assert cells[0].cpus[3].id == '3'
@ -69,7 +70,8 @@ class TestCapabilities(unittest.TestCase):
# domcapabilities.py testing #
##############################
def testDomainCapabilities(self):
def testDomainCapabilities():
xml = open(DATADIR + "/test-domcaps.xml").read()
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
@ -79,7 +81,8 @@ class TestCapabilities(unittest.TestCase):
assert caps.os.loader.get_enum("type").get_values() == [
"rom", "pflash"]
def testDomainCapabilitiesx86(self):
def testDomainCapabilitiesx86():
xml = open(DATADIR + "/kvm-x86_64-domcaps.xml").read()
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)
@ -102,7 +105,8 @@ class TestCapabilities(unittest.TestCase):
assert "Custom:" in caps.label_for_firmware_path("/foobar")
assert "UEFI" in caps.label_for_firmware_path("OVMF")
def testDomainCapabilitiesAArch64(self):
def testDomainCapabilitiesAArch64():
xml = open(DATADIR + "/kvm-aarch64-domcaps.xml").read()
caps = DomainCapabilities(utils.URIs.open_testdriver_cached(), xml)

View File

@ -10,7 +10,8 @@ import shlex
import shutil
import sys
import traceback
import unittest
import pytest
try:
import argcomplete
@ -155,7 +156,7 @@ class SkipChecks:
msg = "Skipping check due to version < %s" % check
if skip:
raise unittest.case.SkipTest(msg)
raise pytest.skip(msg)
def prerun_skip(self, conn):
self._check(conn, self.prerun_check)
@ -338,15 +339,8 @@ class Command(object):
if self.compare_file:
self._check_compare_file(conn, output)
def run(self, tests):
err = None
try:
def run(self):
self._run()
except AssertionError as e:
err = self.cmdstr + "\n" + str(e)
if err:
tests.fail(err)
class _CategoryProxy(object):
@ -1453,9 +1447,8 @@ _add_argcomplete_cmd("virt-xml --sound mode", "model")
##############
class CLIMiscTests(unittest.TestCase):
@utils.run_without_testsuite_hacks
def test_virtinstall_no_testsuite(self):
def test_virtinstall_no_testsuite():
"""
Run virt-install stub command without the testsuite hacks, to test
some code paths like proper logging etc.
@ -1464,21 +1457,25 @@ class CLIMiscTests(unittest.TestCase):
"virt-install --connect %s "
"--test-stub-command --noautoconsole" %
(utils.URIs.test_suite))
cmd.run(self)
cmd.run()
#########################
# Test runner functions #
#########################
newidx = 0
curtest = 0
_CURTEST = 0
def setup():
"""
Create initial test files/dirs
"""
global _CURTEST
_CURTEST += 1
if _CURTEST != 1:
return
for i in EXIST_FILES:
open(i, "a")
@ -1500,40 +1497,41 @@ def cleanup(clean_all=True):
os.unlink(i)
class CLITests(unittest.TestCase):
def setUp(self):
global curtest
curtest += 1
# Only run this for first test
if curtest == 1:
def _create_testfunc(cmd, do_setup):
def cmdtemplate():
if do_setup:
setup()
def tearDown(self):
# Only run this on the last test
if curtest == newidx:
cleanup()
cmd.run()
return cmdtemplate
def maketest(cmd):
def cmdtemplate(self, _cmdobj):
_cmdobj.run(self)
return lambda s: cmdtemplate(s, cmd)
def _make_testcases():
"""
Turn all the registered cli strings into test functions that
the test runner can scoop up
"""
cmdlist = []
cmdlist += vinst.cmds
cmdlist += vclon.cmds
cmdlist += vixml.cmds
cmdlist += ARGCOMPLETE_CMDS
_cmdlist = []
_cmdlist += vinst.cmds
_cmdlist += vclon.cmds
_cmdlist += vixml.cmds
_cmdlist += ARGCOMPLETE_CMDS
# Generate numbered names like testCLI%d
for _cmd in _cmdlist:
newidx = 0
for cmd in cmdlist:
newidx += 1
_name = "testCLI%.4d" % newidx
if _cmd.compare_file:
_base = os.path.splitext(os.path.basename(_cmd.compare_file))[0]
_name += _base.replace("-", "_")
else:
_name += os.path.basename(_cmd.app.replace("-", "_"))
setattr(CLITests, _name, maketest(_cmd))
# Generate numbered names like testCLI%d
name = "testCLI%.4d" % newidx
if cmd.compare_file:
base = os.path.splitext(os.path.basename(cmd.compare_file))[0]
name += base.replace("-", "_")
else:
name += os.path.basename(cmd.app.replace("-", "_"))
do_setup = newidx == 1
testfunc = _create_testfunc(cmd, do_setup)
globals()[name] = testfunc
_make_testcases()
atexit.register(cleanup)

View File

@ -2,8 +2,6 @@
# See the COPYING file in the top-level directory.
import os
import unittest
import unittest.mock
import pytest
@ -13,11 +11,11 @@ from virtinst import StoragePool
from virtinst import URI
class TestConn(unittest.TestCase):
"""
VirtinstConnection tests
"""
def test_misc(self):
############################
# VirtinstConnection tests #
############################
def test_misc():
# Misc API checks
conn = cli.getConnection("test:///default")
conn.invalidate_caps()
@ -49,16 +47,17 @@ class TestConn(unittest.TestCase):
with pytest.raises(RuntimeError):
cli.getConnection(fakeuri + ",qemu")
@unittest.mock.patch.dict(os.environ,
{"LIBVIRT_DEFAULT_URI": "test:///default"})
def test_default_uri(self):
def test_default_uri(monkeypatch):
monkeypatch.setitem(os.environ, "LIBVIRT_DEFAULT_URI", "test:///default")
# Handle connecting to None conn
conn = cli.getConnection(None)
assert conn.getURI() == "test:///default"
conn.close()
def test_poll(self):
def test_poll():
# Add coverage for conn fetch_* handling, and pollhelpers
conn = cli.getConnection("test:///default")
objmap = {}

View File

@ -5,7 +5,6 @@
import os
import tempfile
import unittest
import pytest
@ -50,8 +49,8 @@ def test_disk_numtotarget():
assert disk.generate_target(['hda', 'hdd']) == 'hdb'
def test_disk_dir_searchable():
# Normally the dir searchable test is skipped in the unittest,
def test_disk_dir_searchable(monkeypatch):
# Normally the dir searchable test is skipped in the test suite,
# but let's contrive an example that should trigger all the code
# to ensure it isn't horribly broken
conn = utils.URIs.open_kvm()
@ -87,8 +86,8 @@ def test_disk_dir_searchable():
assert not bool(errdict)
# Mock setfacl to definitely fail
with unittest.mock.patch("virtinst.diskbackend.SETFACL",
"getfacl"):
with monkeypatch.context() as m:
m.setattr("virtinst.diskbackend.SETFACL", "getfacl")
errdict = virtinst.DeviceDisk.fix_path_search(searchdata)
finally:

View File

@ -5,7 +5,6 @@
import os
import sys
import unittest
_alldistros = {}
@ -89,15 +88,7 @@ def _test_distro(distro):
os.system(cmd)
_printinitrd = False
class InjectTests(unittest.TestCase):
def setUp(self):
global _printinitrd
if _printinitrd:
return
def _print_intro():
print("""
@ -109,17 +100,25 @@ failure pattern to confirm that initrd injections are working as expected.
""")
prompt()
_printinitrd = True
def _build_testfunc(dobj, do_setup):
def testfunc():
if do_setup:
_print_intro()
_test_distro(dobj)
return testfunc
def _make_tests():
def _make_check_cb(_d):
return lambda s: _test_distro(_d)
idx = 0
for dname, dobj in _alldistros.items():
idx += 1
setattr(InjectTests, "testInitrd%.3d_%s" %
(idx, dname.replace("-", "_")), _make_check_cb(dobj))
name = "testInitrd%.3d_%s" % (idx, dname.replace("-", "_"))
do_setup = idx == 1
testfunc = _build_testfunc(dobj, do_setup)
globals()[name] = testfunc
_make_tests()

View File

@ -6,7 +6,6 @@
# See the COPYING file in the top-level directory.
import os.path
import unittest
import pytest
@ -27,86 +26,98 @@ funky_chars_xml = """
DATADIR = utils.DATADIR + "/nodedev/"
class TestNodeDev(unittest.TestCase):
@property
def conn(self):
return utils.URIs.open_testdriver_cached()
def _nodeDevFromName(self, devname):
node = self.conn.nodeDeviceLookupByName(devname)
def _nodeDevFromName(conn, devname):
node = conn.nodeDeviceLookupByName(devname)
xml = node.XMLDesc(0)
return NodeDevice(self.conn, xml)
return NodeDevice(conn, xml)
def _testNode2DeviceCompare(self, nodename, devfile, nodedev=None):
def _testNode2DeviceCompare(conn, nodename, devfile, nodedev=None):
devfile = os.path.join(DATADIR, "devxml", devfile)
if not nodedev:
nodedev = self._nodeDevFromName(nodename)
nodedev = _nodeDevFromName(conn, nodename)
dev = DeviceHostdev(self.conn)
dev = DeviceHostdev(conn)
dev.set_from_nodedev(nodedev)
dev.set_defaults(Guest(self.conn))
dev.set_defaults(Guest(conn))
utils.diff_compare(dev.get_xml() + "\n", devfile)
def testFunkyChars(self):
def testFunkyChars():
# Ensure parsing doesn't fail
dev = NodeDevice(self.conn, funky_chars_xml)
conn = utils.URIs.open_testdriver_cached()
dev = NodeDevice(conn, funky_chars_xml)
assert dev.name == "L3B2616"
assert dev.device_type == "LENOVO"
def testNetDevice(self):
def testNetDevice():
conn = utils.URIs.open_testdriver_cached()
devname = "net_00_1c_25_10_b1_e4"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.name == devname
assert dev.parent == "pci_8086_1049"
assert dev.device_type == "net"
assert dev.interface == "eth0"
def testPCIDevice(self):
def testPCIDevice():
conn = utils.URIs.open_testdriver_cached()
nodename = "pci_8086_10fb"
obj = self._nodeDevFromName(nodename)
obj = _nodeDevFromName(conn, nodename)
assert obj.is_pci_sriov() is True
nodename = "pci_8086_2448"
obj = self._nodeDevFromName(nodename)
obj = _nodeDevFromName(conn, nodename)
assert obj.is_pci_bridge() is True
def testUSBDevDevice(self):
def testUSBDevDevice():
conn = utils.URIs.open_testdriver_cached()
devname = "usb_device_781_5151_2004453082054CA1BEEE"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.vendor_name == "SanDisk Corp."
assert dev.product_name == "Cruzer Micro 256/512MB Flash Drive"
devname = "usb_device_1d6b_1_0000_00_1a_0"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.is_usb_linux_root_hub() is True
def testSCSIDevice(self):
def testSCSIDevice():
conn = utils.URIs.open_testdriver_cached()
devname = "pci_8086_2829_scsi_host_scsi_device_lun0"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.host == "0"
assert dev.bus == "0"
assert dev.target == "0"
def testStorageDevice(self):
def testStorageDevice():
conn = utils.URIs.open_testdriver_cached()
devname = "storage_serial_SATA_WDC_WD1600AAJS__WD_WCAP95119685"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.block == "/dev/sda"
assert dev.drive_type == "disk"
assert dev.media_available is None
devname = "storage_model_DVDRAM_GSA_U1200N"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.media_label == "Fedora12_media"
assert dev.media_available == 1
def testSCSIBus(self):
def testSCSIBus():
conn = utils.URIs.open_testdriver_cached()
devname = "pci_8086_2829_scsi_host_1"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.host == "2"
def testDRMDevice(self):
def testDRMDevice():
conn = utils.URIs.open_testdriver_cached()
devname = "drm_renderD129"
dev = self._nodeDevFromName(devname)
dev = _nodeDevFromName(conn, devname)
assert dev.devnodes[0].path == "/dev/dri/renderD129"
assert dev.devnodes[0].node_type == "dev"
assert dev.devnodes[1].path == "/dev/dri/by-path/pci-0000:00:02.0-render"
@ -116,28 +127,36 @@ class TestNodeDev(unittest.TestCase):
# NodeDevice 2 Device XML tests
def testNodeDev2USB1(self):
def testNodeDev2USB1():
conn = utils.URIs.open_testdriver_cached()
nodename = "usb_device_781_5151_2004453082054CA1BEEE"
devfile = "usbdev1.xml"
self._testNode2DeviceCompare(nodename, devfile)
_testNode2DeviceCompare(conn, nodename, devfile)
def testNodeDev2USB2(self):
def testNodeDev2USB2():
conn = utils.URIs.open_testdriver_cached()
nodename = "usb_device_1d6b_2_0000_00_1d_7"
devfile = "usbdev2.xml"
nodedev = self._nodeDevFromName(nodename)
nodedev = _nodeDevFromName(conn, nodename)
self._testNode2DeviceCompare(nodename, devfile, nodedev=nodedev)
_testNode2DeviceCompare(conn, nodename, devfile, nodedev=nodedev)
def testNodeDev2PCI(self):
def testNodeDev2PCI():
conn = utils.URIs.open_testdriver_cached()
nodename = "pci_1180_592"
devfile = "pcidev.xml"
self._testNode2DeviceCompare(nodename, devfile)
_testNode2DeviceCompare(conn, nodename, devfile)
def testNodeDevFail(self):
def testNodeDevFail():
conn = utils.URIs.open_testdriver_cached()
nodename = "usb_device_1d6b_1_0000_00_1d_1_if0"
devfile = ""
# This should exist, since usbbus is not a valid device to
# pass to a guest.
pytest.raises(ValueError,
self._testNode2DeviceCompare, nodename, devfile)
with pytest.raises(ValueError):
_testNode2DeviceCompare(conn, nodename, devfile)

View File

@ -3,7 +3,7 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import unittest
import pytest
from virtinst import Guest
from virtinst import OSDB
@ -13,11 +13,12 @@ from virtinst.install import urldetect
from tests import utils
class TestOSDB(unittest.TestCase):
"""
Test osdict/OSDB
"""
def test_osdict_aliases_ro(self):
##################
# Test osdict.py #
##################
def test_osdict_aliases_ro():
aliases = getattr(OSDB, "_aliases")
if len(aliases) != 42:
@ -25,10 +26,12 @@ class TestOSDB(unittest.TestCase):
"should never be extended, since it is only for back "
"compat with pre-libosinfo osdict.py"))
def test_list_os(self):
def test_list_os():
OSDB.list_os()
def test_recommended_resources(self):
def test_recommended_resources():
conn = utils.URIs.open_testdefault_cached()
guest = Guest(conn)
res = OSDB.lookup_os("generic").get_recommended_resources()
@ -37,7 +40,8 @@ class TestOSDB(unittest.TestCase):
res = OSDB.lookup_os("fedora21").get_recommended_resources()
assert res.get_recommended_ncpus(guest.os.arch) == 2
def test_urldetct_matching_distros(self):
def test_urldetct_matching_distros():
# pylint: disable=protected-access
allstores = urldetect._build_distro_list(OSDB.lookup_os("generic"))
@ -50,7 +54,8 @@ class TestOSDB(unittest.TestCase):
(store.PRETTY_NAME, distro))
seen_distro.append(distro)
def test_tree_url(self):
def test_tree_url():
f26 = OSDB.lookup_os("fedora26")
f29 = OSDB.lookup_os("fedora29")
winxp = OSDB.lookup_os("winxp")
@ -82,11 +87,12 @@ class TestOSDB(unittest.TestCase):
# Trigger an error path for code coverage
assert OSDB.guess_os_by_tree(utils.TESTDIR) is None
def test_kernel_url(self):
def test_kernel_url():
def _c(name):
osobj = OSDB.lookup_os(name)
if not osobj:
self.skipTest("osinfo-db doesn't have '%s'" % name)
pytest.skip("osinfo-db doesn't have '%s'" % name)
return osobj.get_kernel_url_arg()
assert _c("rhel7-unknown") == "inst.repo"
@ -97,14 +103,16 @@ class TestOSDB(unittest.TestCase):
assert _c("win10") is None
assert _c("sle15") == "install"
def test_related_to(self):
def test_related_to():
# pylint: disable=protected-access
win10 = OSDB.lookup_os("win10")
assert win10._is_related_to("winxp") is True
assert win10._is_related_to("win10") is True
assert win10._is_related_to("fedora26") is False
def test_drivers(self):
def test_drivers():
win7 = OSDB.lookup_os("win7")
generic = OSDB.lookup_os("generic")
assert generic.supports_unattended_drivers("x86_64") is False

View File

@ -4,7 +4,6 @@
# See the COPYING file in the top-level directory.
import os
import unittest
from virtinst import StoragePool, StorageVolume
from virtinst import log
@ -12,7 +11,6 @@ from virtinst import log
from tests import utils
# pylint: disable=protected-access
# Access to protected member, needed to unittest stuff
BASEPATH = os.path.join(utils.DATADIR, "storage")
@ -97,104 +95,124 @@ def createVol(conn, poolobj, volname=None, input_vol=None, clone_vol=None):
return vol_inst.install(meter=False)
class TestStorage(unittest.TestCase):
@property
def conn(self):
return utils.URIs.open_testdefault_cached()
##############
# Test cases #
##############
def testDirPool(self):
poolobj = createPool(self.conn,
def testDirPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_DIR, "pool-dir")
invol = createVol(self.conn, poolobj)
createVol(self.conn, poolobj,
invol = createVol(conn, poolobj)
createVol(conn, poolobj,
volname=invol.name() + "input", input_vol=invol)
createVol(self.conn, poolobj,
createVol(conn, poolobj,
volname=invol.name() + "clone", clone_vol=invol)
removePool(poolobj)
def testFSPool(self):
poolobj = createPool(self.conn,
def testFSPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_FS, "pool-fs")
invol = createVol(self.conn, poolobj)
createVol(self.conn, poolobj,
invol = createVol(conn, poolobj)
createVol(conn, poolobj,
volname=invol.name() + "input", input_vol=invol)
createVol(self.conn, poolobj,
createVol(conn, poolobj,
volname=invol.name() + "clone", clone_vol=invol)
removePool(poolobj)
def testNetFSPool(self):
poolobj = createPool(self.conn,
def testNetFSPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_NETFS, "pool-netfs")
invol = createVol(self.conn, poolobj)
createVol(self.conn, poolobj,
invol = createVol(conn, poolobj)
createVol(conn, poolobj,
volname=invol.name() + "input", input_vol=invol)
createVol(self.conn, poolobj,
createVol(conn, poolobj,
volname=invol.name() + "clone", clone_vol=invol)
removePool(poolobj)
def testLVPool(self):
poolobj = createPool(self.conn,
def testLVPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_LOGICAL,
"pool-logical",
source_name="pool-logical")
invol = createVol(self.conn, poolobj)
createVol(self.conn, poolobj,
invol = createVol(conn, poolobj)
createVol(conn, poolobj,
volname=invol.name() + "input", input_vol=invol)
createVol(self.conn,
createVol(conn,
poolobj, volname=invol.name() + "clone", clone_vol=invol)
removePool(poolobj)
# Test parsing source name for target path
poolobj = createPool(self.conn, StoragePool.TYPE_LOGICAL,
poolobj = createPool(conn, StoragePool.TYPE_LOGICAL,
"pool-logical-target-srcname",
target_path="/dev/vgfoobar")
removePool(poolobj)
# Test with source name
poolobj = createPool(self.conn,
poolobj = createPool(conn,
StoragePool.TYPE_LOGICAL, "pool-logical-srcname",
source_name="vgname")
removePool(poolobj)
def testDiskPool(self):
poolobj = createPool(self.conn,
def testDiskPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_DISK,
"pool-disk", fmt="auto",
target_path="/some/target/path")
invol = createVol(self.conn, poolobj)
createVol(self.conn, poolobj,
invol = createVol(conn, poolobj)
createVol(conn, poolobj,
volname=invol.name() + "input", input_vol=invol)
createVol(self.conn, poolobj,
createVol(conn, poolobj,
volname=invol.name() + "clone", clone_vol=invol)
removePool(poolobj)
def testISCSIPool(self):
poolobj = createPool(self.conn,
def testISCSIPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_ISCSI, "pool-iscsi",
iqn="foo.bar.baz.iqn")
removePool(poolobj)
def testSCSIPool(self):
poolobj = createPool(self.conn, StoragePool.TYPE_SCSI, "pool-scsi")
def testSCSIPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn, StoragePool.TYPE_SCSI, "pool-scsi")
removePool(poolobj)
def testMpathPool(self):
poolobj = createPool(self.conn, StoragePool.TYPE_MPATH, "pool-mpath")
def testMpathPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn, StoragePool.TYPE_MPATH, "pool-mpath")
removePool(poolobj)
def testGlusterPool(self):
poolobj = createPool(self.conn,
def testGlusterPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_GLUSTER, "pool-gluster")
removePool(poolobj)
def testRBDPool(self):
poolobj = createPool(self.conn,
def testRBDPool():
conn = utils.URIs.open_testdefault_cached()
poolobj = createPool(conn,
StoragePool.TYPE_RBD, "pool-rbd")
removePool(poolobj)
def testMisc(self):
def testMisc():
conn = utils.URIs.open_testdefault_cached()
# Misc coverage testing
vol = StorageVolume(self.conn)
vol = StorageVolume(conn)
assert vol.is_size_conflict()[0] is False
fullconn = utils.URIs.open_testdriver_cached()
@ -216,7 +234,9 @@ class TestStorage(unittest.TestCase):
name = StoragePool.find_free_name(fullconn, "gluster-pool")
assert name == "gluster-pool-1"
def testEnumerateLogical(self):
lst = StoragePool.pool_list_from_sources(self.conn,
def testEnumerateLogical():
conn = utils.URIs.open_testdefault_cached()
lst = StoragePool.pool_list_from_sources(conn,
StoragePool.TYPE_LOGICAL)
assert lst == ["testvg1", "testvg2"]

View File

@ -3,8 +3,6 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
import unittest
import pytest
from virtinst import URI
@ -12,11 +10,11 @@ from virtinst import URI
import tests
class TestURI(unittest.TestCase):
"""
Test virtinst URI module
"""
def _compare(self, uri, scheme='',
############################
# Test virtinst URI module #
############################
def _compare(uri, scheme='',
transport='', port='', username='', path='',
hostname='', query='', fragment='',
is_ipv6=False, host_is_ipv4_string=False):
@ -32,33 +30,35 @@ class TestURI(unittest.TestCase):
assert is_ipv6 == uriinfo.is_ipv6
assert host_is_ipv4_string == uriinfo.host_is_ipv4_string
def testURIs(self):
self._compare("lxc://", scheme="lxc")
self._compare("qemu:///session", scheme="qemu", path="/session")
self._compare("http://foobar.com:5901/my/example.path#my-frag",
def testURIs():
_compare("lxc://", scheme="lxc")
_compare("qemu:///session", scheme="qemu", path="/session")
_compare("http://foobar.com:5901/my/example.path#my-frag",
scheme="http", hostname="foobar.com",
port="5901", path='/my/example.path',
fragment="my-frag")
self._compare(
_compare(
"gluster+tcp://[1:2:3:4:5:6:7:8]:24007/testvol/dir/a.img",
scheme="gluster", transport="tcp",
hostname="1:2:3:4:5:6:7:8", port="24007",
path="/testvol/dir/a.img", is_ipv6=True)
self._compare(
_compare(
"qemu+ssh://root@192.168.2.3/system?no_verify=1",
scheme="qemu", transport="ssh", username="root",
hostname="192.168.2.3", path="/system",
query="no_verify=1", host_is_ipv4_string=True)
self._compare(
_compare(
"qemu+ssh://foo%5Cbar@hostname/system",
scheme="qemu", path="/system", transport="ssh",
hostname="hostname", username="foo\\bar")
self._compare(
_compare(
"qemu+ssh://user%40domain.org@hostname/system",
scheme="qemu", path="/system", transport="ssh",
hostname="hostname", username="user@domain.org")
def test_magicuri_connver(self):
def test_magicuri_connver():
uri = tests.utils.URIs.test_default + ",connver=1,libver=2"
conn = tests.utils.URIs.openconn(uri)
assert conn.conn_version() == 1

View File

@ -6,7 +6,6 @@
import os
import re
import sys
import unittest
import pytest
@ -126,7 +125,7 @@ def _testGuest(testdata, guest):
msg = _skipmsg(testdata)
if msg:
raise unittest.SkipTest(msg)
raise pytest.skip(msg)
installer = Installer(guest.conn, location=url)
try:
@ -190,9 +189,7 @@ def _testURL(testdata):
_testGuest(testdata, xenguest)
# Register tests to be picked up by unittest
class URLTests(unittest.TestCase):
def test001BadURL(self):
def test001BadURL():
badurl = "http://aksdkakskdfa-idontexist.com/foo/tree"
with pytest.raises(ValueError, match=".*maybe you mistyped.*"):
@ -238,7 +235,7 @@ def _make_tests():
for key, testdata in sorted(urls.items()):
def _make_wrapper(d):
return lambda _self: _testURL(d)
methodname = "testURL%s" % key.replace("-", "_")
setattr(URLTests, methodname, _make_wrapper(testdata))
methodname = "test_URL%s" % key.replace("-", "_")
globals()[methodname] = _make_wrapper(testdata)
_make_tests()

File diff suppressed because it is too large Load Diff

View File

@ -5,9 +5,9 @@
import os
import sys
import unittest
import libvirt
import pytest
import virtinst
import virtinst.uri
@ -16,7 +16,6 @@ from virtinst import xmlutil
# pylint: disable=protected-access
# Access to protected member, needed to unittest stuff
class _TestConfig(object):
"""
@ -138,7 +137,7 @@ class _URIs(object):
print(self._testdriver_error, file=sys.stderr)
if is_testdriver_xml and self._testdriver_error:
raise unittest.SkipTest(self._testdriver_error)
pytest.skip(self._testdriver_error)
uri = conn._open_uri