Fix "os.path" mock problems during tests 45/59045/1
authorEmma Foley <emma.l.foley@intel.com>
Tue, 26 Jun 2018 14:37:52 +0000 (15:37 +0100)
committerEmma Foley <emma.l.foley@intel.com>
Tue, 26 Jun 2018 14:37:52 +0000 (15:37 +0100)
This patch removes the global mocking applied on "os.path".

Change-Id: Ia18d2c90195c5408a1852792bdf05b6f0c1ad21f
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Signed-off-by: Emma Foley <emma.l.foley@intel.com>
(cherry picked from commit d7f8717c3beb1854976e77d56823f482497ffff3)

yardstick/benchmark/contexts/heat.py
yardstick/tests/unit/benchmark/contexts/standalone/test_model.py
yardstick/tests/unit/benchmark/contexts/test_heat.py
yardstick/tests/unit/network_services/helpers/test_samplevnf_helper.py

index 0640d2c..3d8907b 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 8f60a10..5ed199a 100644 (file)
@@ -422,7 +422,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 d05b912..749f731 100644 (file)
@@ -225,7 +225,7 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
         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)
@@ -250,7 +250,7 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
              'yardstick/resources/files/yardstick_key-',
              self.test_context._name_task_id])
         mock_genkeys.assert_called_once_with(key_filename)
-        mock_path_exists.assert_called()
+        mock_path_exists.assert_any_call(key_filename)
 
     @mock.patch.object(heat, 'HeatTemplate')
     @mock.patch.object(os.path, 'exists', return_value=False)
@@ -276,7 +276,7 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
              '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)
@@ -292,7 +292,6 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
         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)
@@ -330,7 +329,7 @@ class HeatContextTestCase(ut_base.BaseUnitTestCase):
              '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 = (
index 45efb82..e66e7fb 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)