iotests.py: Add is_str()
authorMax Reitz <mreitz@redhat.com>
Sun, 10 Feb 2019 14:57:32 +0000 (15:57 +0100)
committerMax Reitz <mreitz@redhat.com>
Mon, 25 Feb 2019 14:11:28 +0000 (15:11 +0100)
On Python 2.x, strings are not always unicode strings.  This function
checks whether a given value is a plain string, or a unicode string (if
there is a difference).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: John Snow <jsnow@redhat.com>
Message-id: 20190210145736.1486-7-mreitz@redhat.com
Signed-off-by: Max Reitz <mreitz@redhat.com>
tests/qemu-iotests/iotests.py

index 82dd096c6e2affc89e3a97c0414d5d7ca69d22bc..52fc77563c73eb4e2cf15685321cb3d38d6b36e1 100644 (file)
@@ -236,6 +236,12 @@ def image_size(img):
     r = qemu_img_pipe('info', '--output=json', '-f', imgfmt, img)
     return json.loads(r)['virtual-size']
 
+def is_str(val):
+    if sys.version_info.major >= 3:
+        return isinstance(val, str)
+    else:
+        return isinstance(val, str) or isinstance(val, unicode)
+
 test_dir_re = re.compile(r"%s" % test_dir)
 def filter_test_dir(msg):
     return test_dir_re.sub("TEST_DIR", msg)