From: Nir Soffer <nirsof@gmail.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, John Snow <jsnow@redhat.com>,
Max Reitz <mreitz@redhat.com>, Nir Soffer <nsoffer@redhat.com>
Subject: [PATCH v2 4/5] qemu-iotests: Merge FilePaths and FilePath
Date: Fri, 21 Aug 2020 02:54:26 +0300 [thread overview]
Message-ID: <20200820235427.374645-5-nsoffer@redhat.com> (raw)
In-Reply-To: <20200820235427.374645-1-nsoffer@redhat.com>
FilePath creates now one temporary file:
with FilePath("a") as a:
Or more:
with FilePath("a", "b", "c") as (a, b, c):
This is also the behavior of the file_path() helper, used by some of the
tests. Now we have only 2 helpers for creating temporary files instead
of 3.
Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
tests/qemu-iotests/194 | 2 +-
tests/qemu-iotests/208 | 2 +-
tests/qemu-iotests/222 | 2 +-
tests/qemu-iotests/257 | 4 ++--
tests/qemu-iotests/iotests.py | 23 +++++++++++------------
5 files changed, 16 insertions(+), 17 deletions(-)
diff --git a/tests/qemu-iotests/194 b/tests/qemu-iotests/194
index 08389f474e..7a4863ab18 100755
--- a/tests/qemu-iotests/194
+++ b/tests/qemu-iotests/194
@@ -26,7 +26,7 @@ iotests.script_initialize(supported_fmts=['qcow2', 'qed', 'raw'],
with iotests.FilePath('source.img') as source_img_path, \
iotests.FilePath('dest.img') as dest_img_path, \
- iotests.FilePaths('migration.sock', 'nbd.sock', base_dir=iotests.sock_dir) \
+ iotests.FilePath('migration.sock', 'nbd.sock', base_dir=iotests.sock_dir) \
as (migration_sock_path, nbd_sock_path), \
iotests.VM('source') as source_vm, \
iotests.VM('dest') as dest_vm:
diff --git a/tests/qemu-iotests/208 b/tests/qemu-iotests/208
index 6cb642f821..54aa4be273 100755
--- a/tests/qemu-iotests/208
+++ b/tests/qemu-iotests/208
@@ -26,7 +26,7 @@ iotests.script_initialize(supported_fmts=['generic'])
with iotests.FilePath('disk.img') as disk_img_path, \
iotests.FilePath('disk-snapshot.img') as disk_snapshot_img_path, \
- iotests.FilePath('nbd.sock', iotests.sock_dir) as nbd_sock_path, \
+ iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \
iotests.VM() as vm:
img_size = '10M'
diff --git a/tests/qemu-iotests/222 b/tests/qemu-iotests/222
index 6602f6b4ba..14d67c875b 100755
--- a/tests/qemu-iotests/222
+++ b/tests/qemu-iotests/222
@@ -49,7 +49,7 @@ remainder = [("0xd5", "0x108000", "32k"), # Right-end of partial-left [1]
with iotests.FilePath('base.img') as base_img_path, \
iotests.FilePath('fleece.img') as fleece_img_path, \
- iotests.FilePath('nbd.sock', iotests.sock_dir) as nbd_sock_path, \
+ iotests.FilePath('nbd.sock', base_dir=iotests.sock_dir) as nbd_sock_path, \
iotests.VM() as vm:
log('--- Setting up images ---')
diff --git a/tests/qemu-iotests/257 b/tests/qemu-iotests/257
index a9aa65bbe3..c80e06ae28 100755
--- a/tests/qemu-iotests/257
+++ b/tests/qemu-iotests/257
@@ -275,7 +275,7 @@ def test_bitmap_sync(bsync_mode, msync_mode='bitmap', failure=None):
an incomplete backup. Testing limitations prevent
testing competing writes.
"""
- with iotests.FilePaths(
+ with iotests.FilePath(
'img', 'bsync1', 'bsync2', 'fbackup0', 'fbackup1', 'fbackup2') as \
(img_path, bsync1, bsync2, fbackup0, fbackup1, fbackup2), \
iotests.VM() as vm:
@@ -440,7 +440,7 @@ def test_backup_api():
"""
Test malformed and prohibited invocations of the backup API.
"""
- with iotests.FilePaths('img', 'bsync1') as (img_path, backup_path), \
+ with iotests.FilePath('img', 'bsync1') as (img_path, backup_path), \
iotests.VM() as vm:
log("\n=== API failure tests ===\n")
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index cdcdc2ad8b..1b5cdd493e 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -448,18 +448,23 @@ class Timeout:
def file_pattern(name):
return "{0}-{1}".format(os.getpid(), name)
-class FilePaths:
+class FilePath:
"""
Context manager generating multiple file names. The generated files are
removed when exiting the context.
Example usage:
- with FilePaths('test.img', 'test.sock') as (img_path, sock_path):
+ with FilePath('test.img', 'test.sock') as (img_path, sock_path):
# Use img_path and sock_path here...
# img_path and sock_path are automatically removed here.
+ For convenience, calling with one argument yields a single file instead of
+ a tuple with one item:
+
+ with FilePath("a") as a:
+
"""
def __init__(self, *names, base_dir=test_dir):
self.paths = []
@@ -467,7 +472,10 @@ class FilePaths:
self.paths.append(os.path.join(base_dir, file_pattern(name)))
def __enter__(self):
- return self.paths
+ if len(self.paths) == 1:
+ return self.paths[0]
+ else:
+ return self.paths
def __exit__(self, exc_type, exc_val, exc_tb):
for path in self.paths:
@@ -477,15 +485,6 @@ class FilePaths:
pass
return False
-class FilePath(FilePaths):
- """
- FilePath is a specialization of FilePaths that takes a single filename.
- """
- def __init__(self, name, base_dir=test_dir):
- super(FilePath, self).__init__(name, base_dir=base_dir)
-
- def __enter__(self):
- return self.paths[0]
def file_path_remover():
for path in reversed(file_path_remover.paths):
--
2.26.2
next prev parent reply other threads:[~2020-08-20 23:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-20 23:54 [PATCH v2 0/5] iotest.FilePath fixes and cleanups Nir Soffer
2020-08-20 23:54 ` [PATCH v2 1/5] qemu-iotests: Fix FilePaths cleanup Nir Soffer
2020-08-25 10:27 ` Max Reitz
2020-08-20 23:54 ` [PATCH v2 2/5] qemu-iotests: Fix FilePaths docstring Nir Soffer
2020-08-25 10:39 ` Max Reitz
2020-08-25 10:48 ` Max Reitz
2020-08-25 11:17 ` Nir Soffer
2020-08-20 23:54 ` [PATCH v2 3/5] qemu-iotests: Support varargs syntax in FilePaths Nir Soffer
2020-08-25 10:48 ` Max Reitz
2020-08-20 23:54 ` Nir Soffer [this message]
2020-08-25 10:57 ` [PATCH v2 4/5] qemu-iotests: Merge FilePaths and FilePath Max Reitz
2020-08-20 23:54 ` [PATCH v2 5/5] qemu-iotests: Simplify FilePath __init__ Nir Soffer
2020-08-25 10:58 ` Max Reitz
2020-08-25 11:37 ` [PATCH v2 0/5] iotest.FilePath fixes and cleanups Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200820235427.374645-5-nsoffer@redhat.com \
--to=nirsof@gmail.com \
--cc=jsnow@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=nsoffer@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.