aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit
diff options
context:
space:
mode:
authorLinda Wang <wangwulin@huawei.com>2017-12-26 09:17:13 +0000
committerLinda Wang <wangwulin@huawei.com>2017-12-27 06:19:23 +0000
commit77d598a882652801b2ddf480c34d896f745657dc (patch)
tree9e32d7b531e3c0e257881250960656524ac2c2e0 /functest/tests/unit
parentc411e0a16b804792c1b34cc819618e1bfbca3d9a (diff)
Execute feature command by subprocess directly
Change-Id: I77e86af4e96310c6520d743e4d16c9a7b2e9adf5 Signed-off-by: Linda Wang <wangwulin@huawei.com>
Diffstat (limited to 'functest/tests/unit')
-rw-r--r--functest/tests/unit/core/test_feature.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/functest/tests/unit/core/test_feature.py b/functest/tests/unit/core/test_feature.py
index 553a5dfa..8c73bb5d 100644
--- a/functest/tests/unit/core/test_feature.py
+++ b/functest/tests/unit/core/test_feature.py
@@ -23,7 +23,7 @@ class FeatureTestingBase(unittest.TestCase):
_case_name = "foo"
_project_name = "bar"
_repo = "dir_repo_bar"
- _cmd = "cd /home/opnfv/repos/bar/tests && bash run.sh && cd -"
+ _cmd = "run_bar_tests.py"
_output_file = '/home/opnfv/functest/results/foo.log'
feature = None
@@ -78,31 +78,33 @@ class BashFeatureTesting(FeatureTestingBase):
self.feature = feature.BashFeature(
project_name=self._project_name, case_name=self._case_name)
- @mock.patch("functest.utils.functest_utils.execute_command")
- def test_run_no_cmd(self, mock_method=None):
- self.assertEqual(self.feature.run(), testcase.TestCase.EX_RUN_ERROR)
- mock_method.assert_not_called()
+ @mock.patch('subprocess.Popen')
+ def test_run_no_cmd(self, mock_subproc):
+ self.assertEqual(
+ self.feature.run(), testcase.TestCase.EX_RUN_ERROR)
+ mock_subproc.assert_not_called()
- @mock.patch("functest.utils.functest_utils.execute_command",
- return_value=1)
- def test_run_ko(self, mock_method=None):
- self._test_run(testcase.TestCase.EX_RUN_ERROR)
- mock_method.assert_called_once_with(
- self._cmd, output_file=self._output_file)
+ @mock.patch('subprocess.Popen')
+ def test_run_ko(self, mock_subproc):
+ with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ mock_obj = mock.Mock()
+ attrs = {'wait.return_value': 1}
+ mock_obj.configure_mock(**attrs)
- @mock.patch("functest.utils.functest_utils.execute_command",
- side_effect=Exception)
- def test_run_exc(self, mock_method=None):
- self._test_run(testcase.TestCase.EX_RUN_ERROR)
- mock_method.assert_called_once_with(
- self._cmd, output_file=self._output_file)
-
- @mock.patch("functest.utils.functest_utils.execute_command",
- return_value=0)
- def test_run(self, mock_method):
- self._test_run(testcase.TestCase.EX_OK)
- mock_method.assert_called_once_with(
- self._cmd, output_file=self._output_file)
+ mock_subproc.return_value = mock_obj
+ self._test_run(testcase.TestCase.EX_RUN_ERROR)
+ mopen.assert_called_once_with(self._output_file, "w+")
+
+ @mock.patch('subprocess.Popen')
+ def test_run(self, mock_subproc):
+ with mock.patch('six.moves.builtins.open', mock.mock_open()) as mopen:
+ mock_obj = mock.Mock()
+ attrs = {'wait.return_value': 0}
+ mock_obj.configure_mock(**attrs)
+
+ mock_subproc.return_value = mock_obj
+ self._test_run(testcase.TestCase.EX_OK)
+ mopen.assert_called_once_with(self._output_file, "w+")
if __name__ == "__main__":