]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Port test_nfs to Python 3
authorVictor Stinner <vstinner@redhat.com>
Tue, 18 Aug 2015 23:22:20 +0000 (16:22 -0700)
committerVictor Stinner <vstinner@redhat.com>
Wed, 19 Aug 2015 18:29:08 +0000 (11:29 -0700)
testtools.ExpectedException(exc_class, regex) expects the exact
exc_class class, wheras the
test_setup_should_throw_exception_if_mount_nfs_command_fails() test
raises a PermissionError on Python 3.3+ instead of OSError. Replace
testtools.ExpectedException() with self.assertRaisesRegex() to port the
test to Python 3, this method accepts subclasses of exc_class.

Replace also testtools.ExpectedException() with self.assertRaisesRegex()
in other tests.

Blueprint https://blueprints.launchpad.net/cinder/+spec/cinder-python3
Change-Id: If5a74529e5ac68a2118afa8ecfd86bf24307b0b7

cinder/tests/unit/test_nfs.py
tox.ini

index f7617f2331d7a405d1f845ad142b2be3465c2732..528ac2f0b22b3d30179afd85157c609f278a70bb 100644 (file)
@@ -16,7 +16,6 @@
 
 import errno
 import os
-import testtools
 
 import mock
 from mox3 import mox as mox_lib
@@ -1140,8 +1139,8 @@ class NfsDriverDoSetupTestCase(test.TestCase):
 
         mock_os_path_exists = self.mock_object(os.path, 'exists')
 
-        with testtools.ExpectedException(exception.NfsException,
-                                         ".*no NFS config file configured.*"):
+        with self.assertRaisesRegex(exception.NfsException,
+                                    ".*no NFS config file configured.*"):
             drv.do_setup(self.context)
 
         self.assertEqual(0, mock_os_path_exists.call_count)
@@ -1154,8 +1153,8 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_os_path_exists = self.mock_object(os.path, 'exists')
         mock_os_path_exists.return_value = False
 
-        with testtools.ExpectedException(exception.NfsException,
-                                         "NFS config file.*doesn't exist"):
+        with self.assertRaisesRegex(exception.NfsException,
+                                    "NFS config file.*doesn't exist"):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
@@ -1170,9 +1169,8 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_os_path_exists = self.mock_object(os.path, 'exists')
         mock_os_path_exists.return_value = True
 
-        with testtools.ExpectedException(
-                exception.InvalidConfigurationValue,
-                ".*'nfs_oversub_ratio' invalid.*"):
+        with self.assertRaisesRegex(exception.InvalidConfigurationValue,
+                                    ".*'nfs_oversub_ratio' invalid.*"):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
@@ -1205,9 +1203,8 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_os_path_exists = self.mock_object(os.path, 'exists')
         mock_os_path_exists.return_value = True
 
-        with testtools.ExpectedException(
-                exception.InvalidConfigurationValue,
-                ".*'nfs_used_ratio' invalid.*"):
+        with self.assertRaisesRegex(exception.InvalidConfigurationValue,
+                                    ".*'nfs_used_ratio' invalid.*"):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
@@ -1222,9 +1219,8 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_os_path_exists = self.mock_object(os.path, 'exists')
         mock_os_path_exists.return_value = True
 
-        with testtools.ExpectedException(
-                exception.InvalidConfigurationValue,
-                ".*'nfs_used_ratio' invalid.*"):
+        with self.assertRaisesRegex(exception.InvalidConfigurationValue,
+                                    ".*'nfs_used_ratio' invalid.*"):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
@@ -1259,8 +1255,8 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_execute.side_effect = OSError(
             errno.ENOENT, 'No such file or directory.')
 
-        with testtools.ExpectedException(
-                exception.NfsException, 'mount.nfs is not installed'):
+        with self.assertRaisesRegex(exception.NfsException,
+                                    'mount.nfs is not installed'):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
@@ -1284,7 +1280,7 @@ class NfsDriverDoSetupTestCase(test.TestCase):
         mock_execute.side_effect = OSError(
             errno.EPERM, 'Operation... BROKEN')
 
-        with testtools.ExpectedException(OSError, '.*Operation... BROKEN'):
+        with self.assertRaisesRegex(OSError, '.*Operation... BROKEN'):
             drv.do_setup(self.context)
 
         mock_os_path_exists.assert_has_calls(
diff --git a/tox.ini b/tox.ini
index dc91a71f5c54c0f0a117bd24a9594cbbbcdf82ca..0416784fd1d3abb244409c473836dabddf47b1ce 100644 (file)
--- a/tox.ini
+++ b/tox.ini
@@ -77,6 +77,7 @@ commands =
     cinder.tests.unit.test_ibm_xiv_ds8k \
     cinder.tests.unit.test_infortrend_cli \
     cinder.tests.unit.test_netapp_nfs \
+    cinder.tests.unit.test_nfs \
     cinder.tests.unit.test_nimble \
     cinder.tests.unit.test_qos_specs \
     cinder.tests.unit.test_quota \