diff mbox series

[9/9] iotests.py: use io.StringIO with python3

Message ID 20171219173425.8113-10-f4bug@amsat.org
State New
Headers show
Series iotests: python3 compatibility | expand

Commit Message

Philippe Mathieu-Daudé Dec. 19, 2017, 5:34 p.m. UTC
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
 tests/qemu-iotests/iotests.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Janosch Frank Dec. 20, 2017, 6:48 a.m. UTC | #1
On 19.12.2017 18:34, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  tests/qemu-iotests/iotests.py | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 4c515d2e6c..0e1b8ab6e6 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -459,13 +459,16 @@ def main(supported_fmts=[], supported_oses=['linux']):
> 
>      # We need to filter out the time taken from the output so that qemu-iotest
>      # can reliably diff the results against master output.
> -    import StringIO
>      if debug:
>          output = sys.stdout
>          verbosity = 2
>          sys.argv.remove('-d')
>      else:
> -        output = StringIO.StringIO()
> +        try:
> +            from StringIO import StringIO
> +        except ImportError:
> +            from io import StringIO
> +        output = StringIO()

*Please* make a commit message that mentions that StringIO was moved
into the io package for py3. It took me way too long to make any sense
of this change until I read the except statement.
Maybe also add a comment.
Daniel P. Berrangé Dec. 20, 2017, 10:10 a.m. UTC | #2
On Tue, Dec 19, 2017 at 02:34:25PM -0300, Philippe Mathieu-Daudé wrote:
> Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
> ---
>  tests/qemu-iotests/iotests.py | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)

Reviewed-by: Daniel P. Berrange <berrange@redhat.com>


> 
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 4c515d2e6c..0e1b8ab6e6 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -459,13 +459,16 @@ def main(supported_fmts=[], supported_oses=['linux']):
>  
>      # We need to filter out the time taken from the output so that qemu-iotest
>      # can reliably diff the results against master output.
> -    import StringIO
>      if debug:
>          output = sys.stdout
>          verbosity = 2
>          sys.argv.remove('-d')
>      else:
> -        output = StringIO.StringIO()
> +        try:
> +            from StringIO import StringIO
> +        except ImportError:
> +            from io import StringIO
> +        output = StringIO()

If it was nit-picking I'd put the py3 'io' import first and the py2
'StringIO' as the fallback, but doesn't honestly matter

>  
>      logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))
>  
> -- 
> 2.15.1
> 

Regards,
Daniel
diff mbox series

Patch

diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 4c515d2e6c..0e1b8ab6e6 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -459,13 +459,16 @@  def main(supported_fmts=[], supported_oses=['linux']):
 
     # We need to filter out the time taken from the output so that qemu-iotest
     # can reliably diff the results against master output.
-    import StringIO
     if debug:
         output = sys.stdout
         verbosity = 2
         sys.argv.remove('-d')
     else:
-        output = StringIO.StringIO()
+        try:
+            from StringIO import StringIO
+        except ImportError:
+            from io import StringIO
+        output = StringIO()
 
     logging.basicConfig(level=(logging.DEBUG if debug else logging.WARN))