mirror of https://github.com/xemu-project/xemu.git
qemu-iotests: Support varargs syntax in FilePaths
Accept variable number of names instead of a sequence: with FilePaths("a", "b", "c") as (a, b, c): The disadvantage is that base_dir must be used as kwarg: with FilePaths("a", "b", base_dir=soc_dir) as (sock1, sock2): But this is more clear and calling optional argument as positional arguments is bad idea anyway. Signed-off-by: Nir Soffer <nsoffer@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Message-Id: <20200828232152.205833-4-nsoffer@redhat.com> Signed-off-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
f765af87c2
commit
a242b19e80
|
@ -26,8 +26,8 @@ iotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'],
|
||||||
|
|
||||||
with iotests.FilePath('source.img') as source_img_path, \
|
with iotests.FilePath('source.img') as source_img_path, \
|
||||||
iotests.FilePath('dest.img') as dest_img_path, \
|
iotests.FilePath('dest.img') as dest_img_path, \
|
||||||
iotests.FilePaths(['migration.sock', 'nbd.sock'], iotests.sock_dir) as \
|
iotests.FilePaths('migration.sock', 'nbd.sock', base_dir=iotests.sock_dir) \
|
||||||
[migration_sock_path, nbd_sock_path], \
|
as (migration_sock_path, nbd_sock_path), \
|
||||||
iotests.VM('source') as source_vm, \
|
iotests.VM('source') as source_vm, \
|
||||||
iotests.VM('dest') as dest_vm:
|
iotests.VM('dest') as dest_vm:
|
||||||
|
|
||||||
|
|
|
@ -275,10 +275,9 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None):
|
||||||
an incomplete backup. Testing limitations prevent
|
an incomplete backup. Testing limitations prevent
|
||||||
testing competing writes.
|
testing competing writes.
|
||||||
"""
|
"""
|
||||||
with iotests.FilePaths(['img', 'bsync1', 'bsync2',
|
with iotests.FilePaths(
|
||||||
'fbackup0', 'fbackup1', 'fbackup2']) as \
|
'img', 'bsync1', 'bsync2', 'fbackup0', 'fbackup1', 'fbackup2') as \
|
||||||
(img_path, bsync1, bsync2,
|
(img_path, bsync1, bsync2, fbackup0, fbackup1, fbackup2), \
|
||||||
fbackup0, fbackup1, fbackup2), \
|
|
||||||
iotests.VM() as vm:
|
iotests.VM() as vm:
|
||||||
|
|
||||||
mode = "Mode {:s}; Bitmap Sync {:s}".format(msync_mode, bsync_mode)
|
mode = "Mode {:s}; Bitmap Sync {:s}".format(msync_mode, bsync_mode)
|
||||||
|
@ -441,8 +440,7 @@ def test_backup_api():
|
||||||
"""
|
"""
|
||||||
Test malformed and prohibited invocations of the backup API.
|
Test malformed and prohibited invocations of the backup API.
|
||||||
"""
|
"""
|
||||||
with iotests.FilePaths(['img', 'bsync1']) as \
|
with iotests.FilePaths('img', 'bsync1') as (img_path, backup_path), \
|
||||||
(img_path, backup_path), \
|
|
||||||
iotests.VM() as vm:
|
iotests.VM() as vm:
|
||||||
|
|
||||||
log("\n=== API failure tests ===\n")
|
log("\n=== API failure tests ===\n")
|
||||||
|
|
|
@ -455,7 +455,7 @@ class FilePaths:
|
||||||
|
|
||||||
Example usage:
|
Example usage:
|
||||||
|
|
||||||
with FilePaths(['a.img', 'b.img']) as (img_a, img_b):
|
with FilePaths('a.img', 'b.img') as (img_a, img_b):
|
||||||
# Use img_a and img_b here...
|
# Use img_a and img_b here...
|
||||||
|
|
||||||
# a.img and b.img are automatically removed here.
|
# a.img and b.img are automatically removed here.
|
||||||
|
@ -463,10 +463,10 @@ class FilePaths:
|
||||||
By default images are created in iotests.test_dir. To create sockets use
|
By default images are created in iotests.test_dir. To create sockets use
|
||||||
iotests.sock_dir:
|
iotests.sock_dir:
|
||||||
|
|
||||||
with FilePaths(['a.sock'], base_dir=iotests.sock_dir) as (sock,):
|
with FilePaths('a.sock', base_dir=iotests.sock_dir) as (sock,):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, names, base_dir=test_dir):
|
def __init__(self, *names, base_dir=test_dir):
|
||||||
self.paths = []
|
self.paths = []
|
||||||
for name in names:
|
for name in names:
|
||||||
self.paths.append(os.path.join(base_dir, file_pattern(name)))
|
self.paths.append(os.path.join(base_dir, file_pattern(name)))
|
||||||
|
@ -487,7 +487,7 @@ class FilePath(FilePaths):
|
||||||
FilePath is a specialization of FilePaths that takes a single filename.
|
FilePath is a specialization of FilePaths that takes a single filename.
|
||||||
"""
|
"""
|
||||||
def __init__(self, name, base_dir=test_dir):
|
def __init__(self, name, base_dir=test_dir):
|
||||||
super(FilePath, self).__init__([name], base_dir)
|
super(FilePath, self).__init__(name, base_dir=base_dir)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
return self.paths[0]
|
return self.paths[0]
|
||||||
|
|
Loading…
Reference in New Issue