Fix "os.path" mock problems during tests 19/56119/10
authorRoss Brattain <ross.b.brattain@intel.com>
Thu, 19 Apr 2018 05:16:32 +0000 (22:16 -0700)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Wed, 25 Apr 2018 17:15:41 +0000 (17:15 +0000)
This patch removes the global mocking applied on "os.path".

Change-Id: Ia18d2c90195c5408a1852792bdf05b6f0c1ad21f
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
tests/unit/network_services/helpers/test_samplevnf_helper.py
yardstick/benchmark/contexts/heat.py
yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
yardstick/tests/unit/benchmark/contexts/test_heat.py

index 3b6c89d..dc74b18 100644 (file)
@@ -143,8 +143,6 @@ class TestMultiPortConfig(unittest.TestCase):
     def setUp(self):
         self._mock_open = mock.patch.object(six.moves.builtins, 'open')
         self.mock_open = self._mock_open.start()
-        self._mock_os = mock.patch.object(os, 'path')
-        self.mock_os = self._mock_os.start()
         self._mock_config_parser = mock.patch.object(
             samplevnf_helper, 'ConfigParser')
         self.mock_config_parser = self._mock_config_parser.start()
@@ -153,7 +151,6 @@ class TestMultiPortConfig(unittest.TestCase):
 
     def _cleanup(self):
         self._mock_open.stop()
-        self._mock_os.stop()
         self._mock_config_parser.stop()
 
     def test_validate_ip_and_prefixlen(self):
@@ -185,7 +182,8 @@ class TestMultiPortConfig(unittest.TestCase):
             samplevnf_helper.MultiPortConfig.validate_ip_and_prefixlen(
                 '::1', '129')
 
-    def test___init__(self):
+    @mock.patch.object(os.path, 'isfile', return_value=False)
+    def test___init__(self, *args):
         topology_file = mock.Mock()
         config_tpl = mock.Mock()
         tmp_file = mock.Mock()
@@ -193,8 +191,6 @@ class TestMultiPortConfig(unittest.TestCase):
         opnfv_vnf = samplevnf_helper.MultiPortConfig(
             topology_file, config_tpl, tmp_file, vnfd_mock)
         self.assertEqual(0, opnfv_vnf.swq)
-        self.mock_os.path = mock.MagicMock()
-        self.mock_os.path.isfile = mock.Mock(return_value=False)
         opnfv_vnf = samplevnf_helper.MultiPortConfig(
             topology_file, config_tpl, tmp_file, vnfd_mock)
         self.assertEqual(0, opnfv_vnf.swq)
index 0d1dfb8..0964b7b 100644 (file)
@@ -7,9 +7,6 @@
 # http://www.apache.org/licenses/LICENSE-2.0
 ##############################################################################
 
-from __future__ import absolute_import
-from __future__ import print_function
-
 import collections
 import logging
 import os
index 7078c89..72e684a 100644 (file)
@@ -478,7 +478,7 @@ class OvsDeployTestCase(unittest.TestCase):
 
     def setUp(self):
         self._mock_ssh = mock.patch.object(ssh, 'SSH')
-        self.mock_ssh = self._mock_ssh .start()
+        self.mock_ssh = self._mock_ssh.start()
         self.ovs_deploy = model.OvsDeploy(self.mock_ssh,
                                           '/tmp/dpdk-devbind.py',
                                           self.OVS_DETAILS)
index a40adf5..1d491fe 100644 (file)
@@ -229,7 +229,7 @@ class HeatContextTestCase(unittest.TestCase):
         self.assertRaises(y_exc.HeatTemplateError,
                           self.test_context.deploy)
 
-        mock_path_exists.assert_called_once()
+        mock_path_exists.assert_called()
         mock_resources_template.assert_called_once()
 
     @mock.patch.object(os.path, 'exists', return_value=False)
@@ -254,7 +254,7 @@ class HeatContextTestCase(unittest.TestCase):
              'yardstick/resources/files/yardstick_key-',
              self.test_context._name_task_id])
         mock_genkeys.assert_called_once_with(key_filename)
-        mock_path_exists.assert_called_once_with(key_filename)
+        mock_path_exists.assert_any_call(key_filename)
 
     @mock.patch.object(heat, 'HeatTemplate')
     @mock.patch.object(os.path, 'exists', return_value=False)
@@ -280,7 +280,7 @@ class HeatContextTestCase(unittest.TestCase):
              'yardstick/resources/files/yardstick_key-',
              self.test_context._name])
         mock_genkeys.assert_called_once_with(key_filename)
-        mock_path_exists.assert_called_once_with(key_filename)
+        mock_path_exists.assert_any_call(key_filename)
 
     @mock.patch.object(heat, 'HeatTemplate')
     @mock.patch.object(os.path, 'exists', return_value=False)
@@ -296,7 +296,6 @@ class HeatContextTestCase(unittest.TestCase):
         self.test_context._flags.no_setup = True
         self.test_context.template_file = '/bar/baz/some-heat-file'
         self.test_context.get_neutron_info = mock.MagicMock()
-
         self.test_context.deploy()
 
         mock_retrieve_stack.assert_called_once_with(self.test_context._name)
@@ -334,7 +333,7 @@ class HeatContextTestCase(unittest.TestCase):
              'yardstick/resources/files/yardstick_key-',
              self.test_context._name_task_id])
         mock_genkeys.assert_called_once_with(key_filename)
-        mock_path_exists.assert_called_with(key_filename)
+        mock_path_exists.assert_any_call(key_filename)
 
         mock_call_gen_keys = mock.call.gen_keys(key_filename)
         mock_call_add_resources = (