mirror of https://github.com/xemu-project/xemu.git
iotests/118: Create test classes dynamically
We're getting a ridiculous number of child classes of TestInitiallyFilled and TestInitiallyEmpty that differ only in a few attributes that we want to test in all combinations. Instead of explicitly writing down every combination, let's use a loop and create those classes dynamically. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
dfa26a110c
commit
dfc828941c
|
@ -294,15 +294,15 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
|
||||||
class TestInitiallyFilled(GeneralChangeTestsBaseClass):
|
class TestInitiallyFilled(GeneralChangeTestsBaseClass):
|
||||||
was_empty = False
|
was_empty = False
|
||||||
|
|
||||||
def setUp(self, media, interface):
|
def setUp(self):
|
||||||
qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
|
qemu_img('create', '-f', iotests.imgfmt, old_img, '1440k')
|
||||||
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
|
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
|
||||||
self.vm = iotests.VM()
|
self.vm = iotests.VM()
|
||||||
self.vm.add_drive(old_img, 'media=%s' % media, 'none')
|
self.vm.add_drive(old_img, 'media=%s' % self.media, 'none')
|
||||||
if interface == 'scsi':
|
if self.interface == 'scsi':
|
||||||
self.vm.add_device('virtio-scsi-pci')
|
self.vm.add_device('virtio-scsi-pci')
|
||||||
self.vm.add_device('%s,drive=drive0,id=%s' %
|
self.vm.add_device('%s,drive=drive0,id=%s' %
|
||||||
(interface_to_device_name(interface),
|
(interface_to_device_name(self.interface),
|
||||||
self.device_name))
|
self.device_name))
|
||||||
self.vm.launch()
|
self.vm.launch()
|
||||||
|
|
||||||
|
@ -331,13 +331,13 @@ class TestInitiallyFilled(GeneralChangeTestsBaseClass):
|
||||||
class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
|
class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
|
||||||
was_empty = True
|
was_empty = True
|
||||||
|
|
||||||
def setUp(self, media, interface):
|
def setUp(self):
|
||||||
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
|
qemu_img('create', '-f', iotests.imgfmt, new_img, '1440k')
|
||||||
self.vm = iotests.VM().add_drive(None, 'media=%s' % media, 'none')
|
self.vm = iotests.VM().add_drive(None, 'media=%s' % self.media, 'none')
|
||||||
if interface == 'scsi':
|
if self.interface == 'scsi':
|
||||||
self.vm.add_device('virtio-scsi-pci')
|
self.vm.add_device('virtio-scsi-pci')
|
||||||
self.vm.add_device('%s,drive=drive0,id=%s' %
|
self.vm.add_device('%s,drive=drive0,id=%s' %
|
||||||
(interface_to_device_name(interface),
|
(interface_to_device_name(self.interface),
|
||||||
self.device_name))
|
self.device_name))
|
||||||
self.vm.launch()
|
self.vm.launch()
|
||||||
|
|
||||||
|
@ -355,50 +355,23 @@ class TestInitiallyEmpty(GeneralChangeTestsBaseClass):
|
||||||
# Should be a no-op
|
# Should be a no-op
|
||||||
self.assert_qmp(result, 'return', {})
|
self.assert_qmp(result, 'return', {})
|
||||||
|
|
||||||
class TestCDInitiallyFilled(TestInitiallyFilled):
|
# Do this in a function to avoid leaking variables like case into the global
|
||||||
TestInitiallyFilled = TestInitiallyFilled
|
# name space (otherwise tests would be run for the abstract base classes)
|
||||||
has_real_tray = True
|
def create_basic_test_classes():
|
||||||
|
for (media, interface, has_real_tray) in [ ('cdrom', 'ide', True),
|
||||||
|
('cdrom', 'scsi', True),
|
||||||
|
('disk', 'floppy', False) ]:
|
||||||
|
|
||||||
def setUp(self):
|
for case in [ TestInitiallyFilled, TestInitiallyEmpty ]:
|
||||||
self.TestInitiallyFilled.setUp(self, 'cdrom', 'ide')
|
|
||||||
|
|
||||||
class TestCDInitiallyEmpty(TestInitiallyEmpty):
|
attr = { 'media': media,
|
||||||
TestInitiallyEmpty = TestInitiallyEmpty
|
'interface': interface,
|
||||||
has_real_tray = True
|
'has_real_tray': has_real_tray }
|
||||||
|
|
||||||
def setUp(self):
|
name = '%s_%s_%s' % (case.__name__, media, interface)
|
||||||
self.TestInitiallyEmpty.setUp(self, 'cdrom', 'ide')
|
globals()[name] = type(name, (case, ), attr)
|
||||||
|
|
||||||
class TestSCSICDInitiallyFilled(TestInitiallyFilled):
|
create_basic_test_classes()
|
||||||
TestInitiallyFilled = TestInitiallyFilled
|
|
||||||
has_real_tray = True
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.TestInitiallyFilled.setUp(self, 'cdrom', 'scsi')
|
|
||||||
|
|
||||||
class TestSCSICDInitiallyEmpty(TestInitiallyEmpty):
|
|
||||||
TestInitiallyEmpty = TestInitiallyEmpty
|
|
||||||
has_real_tray = True
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.TestInitiallyEmpty.setUp(self, 'cdrom', 'scsi')
|
|
||||||
|
|
||||||
class TestFloppyInitiallyFilled(TestInitiallyFilled):
|
|
||||||
TestInitiallyFilled = TestInitiallyFilled
|
|
||||||
has_real_tray = False
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.TestInitiallyFilled.setUp(self, 'disk', 'floppy')
|
|
||||||
|
|
||||||
class TestFloppyInitiallyEmpty(TestInitiallyEmpty):
|
|
||||||
TestInitiallyEmpty = TestInitiallyEmpty
|
|
||||||
has_real_tray = False
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
self.TestInitiallyEmpty.setUp(self, 'disk', 'floppy')
|
|
||||||
# FDDs not having a real tray and there not being a medium inside the
|
|
||||||
# tray at startup means the tray will be considered open
|
|
||||||
self.has_opened = True
|
|
||||||
|
|
||||||
class TestChangeReadOnly(ChangeBaseClass):
|
class TestChangeReadOnly(ChangeBaseClass):
|
||||||
device_name = 'qdev0'
|
device_name = 'qdev0'
|
||||||
|
|
Loading…
Reference in New Issue