summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorEmma Foley <emma.l.foley@intel.com>2017-12-19 15:44:11 +0000
committerEmma Foley <emma.l.foley@intel.com>2018-01-12 14:45:53 +0000
commit2f2ee2293ffdf2969d36ad1ac73eb5cc90dd308a (patch)
treefaf606ce577301e84414112949a8f736982e695e /tests
parentd579e62b431a31856a03098dc5323948ccfa4fdb (diff)
Use assertIn(x, y) instead of other variations
unittest.assertIn(x,y) should be used instead of: * unittest.assertTrue(x in y) * unittest.assertEqual(x in y, True) Also fixes pep8 violations existing in the file. Change-Id: I705c1bd4af74757b5c928995894aede436d66817 JIRA: YARDSTICK-901 Signed-off-by: Emma Foley <emma.l.foley@intel.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/benchmark/scenarios/availability/test_util.py36
1 files changed, 21 insertions, 15 deletions
diff --git a/tests/unit/benchmark/scenarios/availability/test_util.py b/tests/unit/benchmark/scenarios/availability/test_util.py
index 0974f385a..03dc70e2a 100644
--- a/tests/unit/benchmark/scenarios/availability/test_util.py
+++ b/tests/unit/benchmark/scenarios/availability/test_util.py
@@ -16,36 +16,42 @@ import unittest
from yardstick.benchmark.scenarios.availability import util
-@mock.patch('yardstick.benchmark.scenarios.availability.util.subprocess')
class ExecuteShellTestCase(unittest.TestCase):
def setUp(self):
self.param_config = {'serviceName': '@serviceName', 'value': 1}
self.intermediate_variables = {'@serviceName': 'nova-api'}
self.std_output = '| id | 1 |'
- self.cmd_config = {'cmd':'ls','param':'-a'}
+ self.cmd_config = {'cmd':'ls', 'param':'-a'}
- def test_util_build_command_shell(self,mock_subprocess):
+ self._mock_subprocess = mock.patch.object(util, 'subprocess')
+ self.mock_subprocess = self._mock_subprocess.start()
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_subprocess.stop()
+
+ def test_util_build_command_shell(self):
result = util.build_shell_command(self.param_config, True,
self.intermediate_variables)
- self.assertEqual("nova-api" in result, True)
+ self.assertIn("nova-api", result)
- def test_read_stdout_item(self,mock_subprocess):
- result = util.read_stdout_item(self.std_output,'id')
- self.assertEquals('1',result)
+ def test_read_stdout_item(self):
+ result = util.read_stdout_item(self.std_output, 'id')
+ self.assertEquals('1', result)
- def test_buildshellparams(self,mock_subprocess):
- result = util.buildshellparams(self.cmd_config,True)
+ def test_buildshellparams(self):
+ result = util.buildshellparams(self.cmd_config, True)
self.assertEquals('/bin/bash -s {0} {1}', result)
- def test__fun_execute_shell_command_successful(self, mock_subprocess):
+ def test__fun_execute_shell_command_successful(self):
cmd = "env"
- mock_subprocess.check_output.return_value = (0, 'unittest')
- exitcode, output = util.execute_shell_command(cmd)
+ self.mock_subprocess.check_output.return_value = (0, 'unittest')
+ exitcode, _ = util.execute_shell_command(cmd)
self.assertEqual(exitcode, 0)
- def test__fun_execute_shell_command_fail_cmd_exception(self, mock_subprocess):
+ def test__fun_execute_shell_command_fail_cmd_exception(self):
cmd = "env"
- mock_subprocess.check_output.side_effect = RuntimeError
- exitcode, output = util.execute_shell_command(cmd)
+ self.mock_subprocess.check_output.side_effect = RuntimeError
+ exitcode, _ = util.execute_shell_command(cmd)
self.assertEqual(exitcode, -1)