All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes
@ 2018-11-20 17:22 Kevin Wolf
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout Kevin Wolf
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kevin Wolf @ 2018-11-20 17:22 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, mreitz, qemu-devel

Kevin Wolf (2):
  iotests: Replace time.clock() with Timeout
  iotests: Replace assertEquals() with assertEqual()

 tests/qemu-iotests/041        |  6 +++---
 tests/qemu-iotests/118        | 20 ++++++++------------
 tests/qemu-iotests/iotests.py |  2 +-
 3 files changed, 12 insertions(+), 16 deletions(-)

-- 
2.19.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout
  2018-11-20 17:22 [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf
@ 2018-11-20 17:22 ` Kevin Wolf
  2018-11-20 20:16   ` Philippe Mathieu-Daudé
  2018-11-20 21:36   ` [Qemu-devel] [Qemu-block] " John Snow
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual() Kevin Wolf
  2018-11-20 21:54 ` [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf
  2 siblings, 2 replies; 8+ messages in thread
From: Kevin Wolf @ 2018-11-20 17:22 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, mreitz, qemu-devel

time.clock() is deprecated since Python 3.3. Current Python versions
warn that the function will be removed in Python 3.8, and those warnings
make the test case 118 fail.

Replace it with the Timeout mechanism that is compatible with both
Python 2 and 3, and makes the code even a little nicer.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/118 | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
index ff3b2ae3e7..c4f4c213ca 100755
--- a/tests/qemu-iotests/118
+++ b/tests/qemu-iotests/118
@@ -53,21 +53,17 @@ class ChangeBaseClass(iotests.QMPTestCase):
         if not self.has_real_tray:
             return
 
-        timeout = time.clock() + 3
-        while not self.has_opened and time.clock() < timeout:
-            self.process_events()
-        if not self.has_opened:
-            self.fail('Timeout while waiting for the tray to open')
+        with iotests.Timeout(3, 'Timeout while waiting for the tray to open'):
+            while not self.has_opened:
+                self.process_events()
 
     def wait_for_close(self):
         if not self.has_real_tray:
             return
 
-        timeout = time.clock() + 3
-        while not self.has_closed and time.clock() < timeout:
-            self.process_events()
-        if not self.has_opened:
-            self.fail('Timeout while waiting for the tray to close')
+        with iotests.Timeout(3, 'Timeout while waiting for the tray to close'):
+            while not self.has_closed:
+                self.process_events()
 
 class GeneralChangeTestsBaseClass(ChangeBaseClass):
 
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual()
  2018-11-20 17:22 [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout Kevin Wolf
@ 2018-11-20 17:22 ` Kevin Wolf
  2018-11-20 20:17   ` Philippe Mathieu-Daudé
  2018-11-20 21:37   ` [Qemu-devel] [Qemu-block] " John Snow
  2018-11-20 21:54 ` [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf
  2 siblings, 2 replies; 8+ messages in thread
From: Kevin Wolf @ 2018-11-20 17:22 UTC (permalink / raw)
  To: qemu-block; +Cc: kwolf, mreitz, qemu-devel

TestCase.assertEquals() is deprecated since Python 2.7. Recent Python
versions print a warning when the function is called, which makes test
cases fail.

Replace it with the preferred spelling assertEqual().

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/041        | 6 +++---
 tests/qemu-iotests/118        | 4 ++--
 tests/qemu-iotests/iotests.py | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
index 3615011d98..26bf1701eb 100755
--- a/tests/qemu-iotests/041
+++ b/tests/qemu-iotests/041
@@ -469,7 +469,7 @@ new_state = "1"
             self.assert_qmp(event, 'data/id', 'drive0')
             event = self.vm.get_qmp_event(wait=True)
 
-        self.assertEquals(event['event'], 'BLOCK_JOB_ERROR')
+        self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
         self.assert_qmp(event, 'data/device', 'drive0')
         self.assert_qmp(event, 'data/operation', 'read')
         result = self.vm.qmp('query-block-jobs')
@@ -494,7 +494,7 @@ new_state = "1"
             self.assert_qmp(event, 'data/id', 'drive0')
             event = self.vm.get_qmp_event(wait=True)
 
-        self.assertEquals(event['event'], 'BLOCK_JOB_ERROR')
+        self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
         self.assert_qmp(event, 'data/device', 'drive0')
         self.assert_qmp(event, 'data/operation', 'read')
         result = self.vm.qmp('query-block-jobs')
@@ -625,7 +625,7 @@ new_state = "1"
         self.assert_qmp(result, 'return', {})
 
         event = self.vm.event_wait(name='BLOCK_JOB_ERROR')
-        self.assertEquals(event['event'], 'BLOCK_JOB_ERROR')
+        self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
         self.assert_qmp(event, 'data/device', 'drive0')
         self.assert_qmp(event, 'data/operation', 'write')
         result = self.vm.qmp('query-block-jobs')
diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
index c4f4c213ca..603e10e8a2 100755
--- a/tests/qemu-iotests/118
+++ b/tests/qemu-iotests/118
@@ -261,7 +261,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
         result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
         # Should be a no-op
         self.assert_qmp(result, 'return', {})
-        self.assertEquals(self.vm.get_qmp_events(wait=False), [])
+        self.assertEqual(self.vm.get_qmp_events(wait=False), [])
 
     def test_remove_on_closed(self):
         if not self.has_real_tray:
@@ -448,7 +448,7 @@ class TestChangeReadOnly(ChangeBaseClass):
                                                        read_only_mode='retain')
         self.assert_qmp(result, 'error/class', 'GenericError')
 
-        self.assertEquals(self.vm.get_qmp_events(wait=False), [])
+        self.assertEqual(self.vm.get_qmp_events(wait=False), [])
 
         result = self.vm.qmp('query-block')
         self.assert_qmp(result, 'return[0]/inserted/ro', False)
diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
index 27bb2b600c..d537538ba0 100644
--- a/tests/qemu-iotests/iotests.py
+++ b/tests/qemu-iotests/iotests.py
@@ -581,7 +581,7 @@ class QMPTestCase(unittest.TestCase):
     def wait_ready_and_cancel(self, drive='drive0'):
         self.wait_ready(drive=drive)
         event = self.cancel_and_wait(drive=drive)
-        self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED')
+        self.assertEqual(event['event'], 'BLOCK_JOB_COMPLETED')
         self.assert_qmp(event, 'data/type', 'mirror')
         self.assert_qmp(event, 'data/offset', event['data']['len'])
 
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout Kevin Wolf
@ 2018-11-20 20:16   ` Philippe Mathieu-Daudé
  2018-11-20 21:36   ` [Qemu-devel] [Qemu-block] " John Snow
  1 sibling, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-20 20:16 UTC (permalink / raw)
  To: Kevin Wolf, qemu-block; +Cc: qemu-devel, mreitz

On 20/11/18 18:22, Kevin Wolf wrote:
> time.clock() is deprecated since Python 3.3. Current Python versions
> warn that the function will be removed in Python 3.8, and those warnings
> make the test case 118 fail.
> 
> Replace it with the Timeout mechanism that is compatible with both
> Python 2 and 3, and makes the code even a little nicer.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   tests/qemu-iotests/118 | 16 ++++++----------
>   1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
> index ff3b2ae3e7..c4f4c213ca 100755
> --- a/tests/qemu-iotests/118
> +++ b/tests/qemu-iotests/118
> @@ -53,21 +53,17 @@ class ChangeBaseClass(iotests.QMPTestCase):
>           if not self.has_real_tray:
>               return
>   
> -        timeout = time.clock() + 3
> -        while not self.has_opened and time.clock() < timeout:
> -            self.process_events()
> -        if not self.has_opened:
> -            self.fail('Timeout while waiting for the tray to open')
> +        with iotests.Timeout(3, 'Timeout while waiting for the tray to open'):
> +            while not self.has_opened:
> +                self.process_events()
>   
>       def wait_for_close(self):
>           if not self.has_real_tray:
>               return
>   
> -        timeout = time.clock() + 3
> -        while not self.has_closed and time.clock() < timeout:
> -            self.process_events()
> -        if not self.has_opened:
> -            self.fail('Timeout while waiting for the tray to close')
> +        with iotests.Timeout(3, 'Timeout while waiting for the tray to close'):
> +            while not self.has_closed:
> +                self.process_events()
>   
>   class GeneralChangeTestsBaseClass(ChangeBaseClass):
>   
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual()
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual() Kevin Wolf
@ 2018-11-20 20:17   ` Philippe Mathieu-Daudé
  2018-11-20 21:37   ` [Qemu-devel] [Qemu-block] " John Snow
  1 sibling, 0 replies; 8+ messages in thread
From: Philippe Mathieu-Daudé @ 2018-11-20 20:17 UTC (permalink / raw)
  To: Kevin Wolf, qemu-block; +Cc: qemu-devel, mreitz

On 20/11/18 18:22, Kevin Wolf wrote:
> TestCase.assertEquals() is deprecated since Python 2.7. Recent Python
> versions print a warning when the function is called, which makes test
> cases fail.
> 
> Replace it with the preferred spelling assertEqual().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>

> ---
>   tests/qemu-iotests/041        | 6 +++---
>   tests/qemu-iotests/118        | 4 ++--
>   tests/qemu-iotests/iotests.py | 2 +-
>   3 files changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/tests/qemu-iotests/041 b/tests/qemu-iotests/041
> index 3615011d98..26bf1701eb 100755
> --- a/tests/qemu-iotests/041
> +++ b/tests/qemu-iotests/041
> @@ -469,7 +469,7 @@ new_state = "1"
>               self.assert_qmp(event, 'data/id', 'drive0')
>               event = self.vm.get_qmp_event(wait=True)
>   
> -        self.assertEquals(event['event'], 'BLOCK_JOB_ERROR')
> +        self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
>           self.assert_qmp(event, 'data/device', 'drive0')
>           self.assert_qmp(event, 'data/operation', 'read')
>           result = self.vm.qmp('query-block-jobs')
> @@ -494,7 +494,7 @@ new_state = "1"
>               self.assert_qmp(event, 'data/id', 'drive0')
>               event = self.vm.get_qmp_event(wait=True)
>   
> -        self.assertEquals(event['event'], 'BLOCK_JOB_ERROR')
> +        self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
>           self.assert_qmp(event, 'data/device', 'drive0')
>           self.assert_qmp(event, 'data/operation', 'read')
>           result = self.vm.qmp('query-block-jobs')
> @@ -625,7 +625,7 @@ new_state = "1"
>           self.assert_qmp(result, 'return', {})
>   
>           event = self.vm.event_wait(name='BLOCK_JOB_ERROR')
> -        self.assertEquals(event['event'], 'BLOCK_JOB_ERROR')
> +        self.assertEqual(event['event'], 'BLOCK_JOB_ERROR')
>           self.assert_qmp(event, 'data/device', 'drive0')
>           self.assert_qmp(event, 'data/operation', 'write')
>           result = self.vm.qmp('query-block-jobs')
> diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
> index c4f4c213ca..603e10e8a2 100755
> --- a/tests/qemu-iotests/118
> +++ b/tests/qemu-iotests/118
> @@ -261,7 +261,7 @@ class GeneralChangeTestsBaseClass(ChangeBaseClass):
>           result = self.vm.qmp('blockdev-close-tray', id=self.device_name)
>           # Should be a no-op
>           self.assert_qmp(result, 'return', {})
> -        self.assertEquals(self.vm.get_qmp_events(wait=False), [])
> +        self.assertEqual(self.vm.get_qmp_events(wait=False), [])
>   
>       def test_remove_on_closed(self):
>           if not self.has_real_tray:
> @@ -448,7 +448,7 @@ class TestChangeReadOnly(ChangeBaseClass):
>                                                          read_only_mode='retain')
>           self.assert_qmp(result, 'error/class', 'GenericError')
>   
> -        self.assertEquals(self.vm.get_qmp_events(wait=False), [])
> +        self.assertEqual(self.vm.get_qmp_events(wait=False), [])
>   
>           result = self.vm.qmp('query-block')
>           self.assert_qmp(result, 'return[0]/inserted/ro', False)
> diff --git a/tests/qemu-iotests/iotests.py b/tests/qemu-iotests/iotests.py
> index 27bb2b600c..d537538ba0 100644
> --- a/tests/qemu-iotests/iotests.py
> +++ b/tests/qemu-iotests/iotests.py
> @@ -581,7 +581,7 @@ class QMPTestCase(unittest.TestCase):
>       def wait_ready_and_cancel(self, drive='drive0'):
>           self.wait_ready(drive=drive)
>           event = self.cancel_and_wait(drive=drive)
> -        self.assertEquals(event['event'], 'BLOCK_JOB_COMPLETED')
> +        self.assertEqual(event['event'], 'BLOCK_JOB_COMPLETED')
>           self.assert_qmp(event, 'data/type', 'mirror')
>           self.assert_qmp(event, 'data/offset', event['data']['len'])
>   
> 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] iotests: Replace time.clock() with Timeout
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout Kevin Wolf
  2018-11-20 20:16   ` Philippe Mathieu-Daudé
@ 2018-11-20 21:36   ` John Snow
  1 sibling, 0 replies; 8+ messages in thread
From: John Snow @ 2018-11-20 21:36 UTC (permalink / raw)
  To: Kevin Wolf, qemu-block; +Cc: qemu-devel, mreitz



On 11/20/18 12:22 PM, Kevin Wolf wrote:
> time.clock() is deprecated since Python 3.3. Current Python versions
> warn that the function will be removed in Python 3.8, and those warnings
> make the test case 118 fail.
> 
> Replace it with the Timeout mechanism that is compatible with both
> Python 2 and 3, and makes the code even a little nicer.
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
> ---
>  tests/qemu-iotests/118 | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)
> 
> diff --git a/tests/qemu-iotests/118 b/tests/qemu-iotests/118
> index ff3b2ae3e7..c4f4c213ca 100755
> --- a/tests/qemu-iotests/118
> +++ b/tests/qemu-iotests/118
> @@ -53,21 +53,17 @@ class ChangeBaseClass(iotests.QMPTestCase):
>          if not self.has_real_tray:
>              return
>  
> -        timeout = time.clock() + 3
> -        while not self.has_opened and time.clock() < timeout:
> -            self.process_events()
> -        if not self.has_opened:
> -            self.fail('Timeout while waiting for the tray to open')
> +        with iotests.Timeout(3, 'Timeout while waiting for the tray to open'):
> +            while not self.has_opened:
> +                self.process_events()
>  
>      def wait_for_close(self):
>          if not self.has_real_tray:
>              return
>  
> -        timeout = time.clock() + 3
> -        while not self.has_closed and time.clock() < timeout:
> -            self.process_events()
> -        if not self.has_opened:
> -            self.fail('Timeout while waiting for the tray to close')
> +        with iotests.Timeout(3, 'Timeout while waiting for the tray to close'):
> +            while not self.has_closed:
> +                self.process_events()
>  
>  class GeneralChangeTestsBaseClass(ChangeBaseClass):
>  
> 

I love the way that reads. Very cool!

Reviewed-by: John Snow <jsnow@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual()
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual() Kevin Wolf
  2018-11-20 20:17   ` Philippe Mathieu-Daudé
@ 2018-11-20 21:37   ` John Snow
  1 sibling, 0 replies; 8+ messages in thread
From: John Snow @ 2018-11-20 21:37 UTC (permalink / raw)
  To: Kevin Wolf, qemu-block; +Cc: qemu-devel, mreitz



On 11/20/18 12:22 PM, Kevin Wolf wrote:
> TestCase.assertEquals() is deprecated since Python 2.7. Recent Python
> versions print a warning when the function is called, which makes test
> cases fail.
> 
> Replace it with the preferred spelling assertEqual().
> 
> Signed-off-by: Kevin Wolf <kwolf@redhat.com>

Reviewed-by: John Snow <jsnow@redhat.com>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes
  2018-11-20 17:22 [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout Kevin Wolf
  2018-11-20 17:22 ` [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual() Kevin Wolf
@ 2018-11-20 21:54 ` Kevin Wolf
  2 siblings, 0 replies; 8+ messages in thread
From: Kevin Wolf @ 2018-11-20 21:54 UTC (permalink / raw)
  To: qemu-block; +Cc: mreitz, qemu-devel

Am 20.11.2018 um 18:22 hat Kevin Wolf geschrieben:
> Kevin Wolf (2):
>   iotests: Replace time.clock() with Timeout
>   iotests: Replace assertEquals() with assertEqual()

Thanks for the quick reviews, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-11-20 21:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-11-20 17:22 [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf
2018-11-20 17:22 ` [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout Kevin Wolf
2018-11-20 20:16   ` Philippe Mathieu-Daudé
2018-11-20 21:36   ` [Qemu-devel] [Qemu-block] " John Snow
2018-11-20 17:22 ` [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual() Kevin Wolf
2018-11-20 20:17   ` Philippe Mathieu-Daudé
2018-11-20 21:37   ` [Qemu-devel] [Qemu-block] " John Snow
2018-11-20 21:54 ` [Qemu-devel] [PATCH for-3.1 0/2] iotests: More Python 3 fixes Kevin Wolf

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.