iotests: More Python 3 fixes
cover iotests: More Python 3 fixes
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(-)
Signature · 1 line
2.19.1
PATCH 1/2 iotests: Replace time.clock() with Timeout
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.
--- tests/qemu-iotests/118 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
tests/qemu-iotests/118 +6 -10
@@ -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):
Signature · 1 line
2.19.1
Re: [Qemu-devel] [PATCH 1/2] iotests: Replace time.clock() with Timeout
Quoted 8 lines · Kevin Wolf
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 <[email protected]>
Quoted 37 lines
--- tests/qemu-iotests/118 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)tests/qemu-iotests/118 +6
-10@@ -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):
Re: [Qemu-devel] [Qemu-block] [PATCH 1/2] iotests: Replace time.clock() with Timeout
In reply to Kevin WolfQuoted 35 lines · Kevin Wolf
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 <[email protected]>--- tests/qemu-iotests/118 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)tests/qemu-iotests/118 +3
-6@@ -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
tests/qemu-iotests/118 class ChangeBaseClass(iotests.QMPTestCase): · line 69
Quoted 10 lines
tests/qemu-iotests/118 +3
-4- 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!
PATCH 2/2 iotests: Replace assertEquals() with assertEqual()
In reply to Kevin WolfTestCase.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().
--- tests/qemu-iotests/041 | 6 +++--- tests/qemu-iotests/118 | 4 ++-- tests/qemu-iotests/iotests.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
tests/qemu-iotests/041 +3 -3
@@ -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')
tests/qemu-iotests/118 +2 -2
@@ -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)
tests/qemu-iotests/iotests.py +1 -1
@@ -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'])
Signature · 1 line
2.19.1
Re: [Qemu-devel] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual()
Quoted 7 lines · Kevin Wolf
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 <[email protected]>
Quoted 73 lines
--- tests/qemu-iotests/041 | 6 +++--- tests/qemu-iotests/118 | 4 ++-- tests/qemu-iotests/iotests.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)tests/qemu-iotests/041 +3
-3@@ -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')tests/qemu-iotests/118 +2
-2@@ -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)tests/qemu-iotests/iotests.py +1
-1@@ -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'])
Re: [Qemu-devel] [Qemu-block] [PATCH 2/2] iotests: Replace assertEquals() with assertEqual()
In reply to Kevin WolfQuoted 7 lines · Kevin Wolf
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 <[email protected]>
Am 20.11.2018 um 18:22 hat Kevin Wolf geschrieben:
Quoted 3 lines
Kevin Wolf (2):
iotests: Replacetime.clock()with Timeout
iotests: ReplaceassertEquals()withassertEqual()
Thanks for the quick reviews, applied to the block branch.
Kevin