]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix Python 3 issues in targets unit tests
authorVictor Stinner <vstinner@redhat.com>
Tue, 30 Jun 2015 14:14:09 +0000 (16:14 +0200)
committerVictor Stinner <vstinner@redhat.com>
Tue, 30 Jun 2015 14:23:13 +0000 (16:23 +0200)
* Replace StandardError with ZeroDivisionError: StandardError was
  removed in Python 3.
* Replace __builtin__ with six.moves.builtins.
* Open text mode with "w" mode (instead of "wb").
* tox.ini: add targets unit tests to Python 3.4

Note: cinder.tests.unit.targets.test_iet_driver still fails on Python 3,
it will be fixed in a different change.

Blueprint cinder-python3
Change-Id: Ie0f5d2dfaf2ffdeab29fe40f692a2f09fb5a7aba

cinder/tests/unit/targets/test_cxt_driver.py
cinder/tests/unit/targets/test_tgt_driver.py
tox.ini

index 49c79edd04e4004149f2f9a658eb9df59335edd7..9ae93219230f687ec7562cf24e14ecf558e9216a 100644 (file)
@@ -70,7 +70,7 @@ class TestCxtAdmDriver(tf.TargetDriverFixture):
         tmp_file.seek(0)
 
         expected = ('otzL', '234Z')
-        with mock.patch('__builtin__.open') as mock_open:
+        with mock.patch('six.moves.builtins.open') as mock_open:
             ctx = context.get_admin_context()
             mock_open.return_value = contextlib.closing(tmp_file)
             self.assertEqual(expected,
@@ -79,7 +79,7 @@ class TestCxtAdmDriver(tf.TargetDriverFixture):
             self.assertTrue(mock_open.called)
 
     def test_get_target_chap_auth_negative(self):
-        with mock.patch('__builtin__.open') as mock_open:
+        with mock.patch('six.moves.builtins.open') as mock_open:
             e = IOError()
             e.errno = 123
             mock_open.side_effect = e
@@ -87,8 +87,8 @@ class TestCxtAdmDriver(tf.TargetDriverFixture):
             self.assertRaises(IOError,
                               self.target._get_target_chap_auth,
                               ctxt, self.test_vol)
-            mock_open.side_effect = StandardError()
-            self.assertRaises(StandardError,
+            mock_open.side_effect = ZeroDivisionError()
+            self.assertRaises(ZeroDivisionError,
                               self.target._get_target_chap_auth,
                               ctxt, self.test_vol)
 
index efcbe089df9ca4fdfa9eaa112a78b999aa063986..4ef1a9e3999b8c767d316e6e51bb8c208eb990e1 100644 (file)
@@ -153,7 +153,7 @@ class TestTgtAdmDriver(tf.TargetDriverFixture):
                            'bspath': self.testvol_path}
         with open(os.path.join(self.fake_volumes_dir,
                                self.test_vol.split(':')[1]),
-                  'wb') as tmp_file:
+                  'w') as tmp_file:
             tmp_file.write(persist_file)
         ctxt = context.get_admin_context()
         expected = ('otzL', '234Z')
@@ -162,7 +162,7 @@ class TestTgtAdmDriver(tf.TargetDriverFixture):
                                                            self.test_vol))
 
     def test_get_target_chap_auth_negative(self):
-        with mock.patch('__builtin__.open') as mock_open:
+        with mock.patch('six.moves.builtins.open') as mock_open:
             e = IOError()
             e.errno = 123
             mock_open.side_effect = e
@@ -170,8 +170,8 @@ class TestTgtAdmDriver(tf.TargetDriverFixture):
             self.assertRaises(IOError,
                               self.target._get_target_chap_auth,
                               ctxt, self.test_vol)
-            mock_open.side_effect = StandardError()
-            self.assertRaises(StandardError,
+            mock_open.side_effect = ZeroDivisionError()
+            self.assertRaises(ZeroDivisionError,
                               self.target._get_target_chap_auth,
                               ctxt, self.test_vol)
 
diff --git a/tox.ini b/tox.ini
index 144737a4ad56bfb204ac04f18dfb1f7a0770c745..654349cbd7f292d2b69f28d317d8dda62b7234e7 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -29,6 +29,12 @@ downloadcache = ~/cache/pip
 [testenv:py34]
 commands =
   python -m testtools.run \
+    cinder.tests.unit.targets.test_base_iscsi_driver \
+    cinder.tests.unit.targets.test_cxt_driver \
+    cinder.tests.unit.targets.test_iser_driver \
+    cinder.tests.unit.targets.test_lio_driver \
+    cinder.tests.unit.targets.test_scst_driver \
+    cinder.tests.unit.targets.test_tgt_driver \
     cinder.tests.unit.test_api_urlmap \
     cinder.tests.unit.test_backup \
     cinder.tests.unit.test_backup_ceph \