aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/unit/benchmark/scenarios/parser/test_parser.py67
-rw-r--r--yardstick/benchmark/scenarios/parser/parser.py6
2 files changed, 45 insertions, 28 deletions
diff --git a/tests/unit/benchmark/scenarios/parser/test_parser.py b/tests/unit/benchmark/scenarios/parser/test_parser.py
index 014d724a5..ee2bbc07d 100644
--- a/tests/unit/benchmark/scenarios/parser/test_parser.py
+++ b/tests/unit/benchmark/scenarios/parser/test_parser.py
@@ -9,50 +9,67 @@
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-# Unittest for yardstick.benchmark.scenarios.parser.Parser
-
-from __future__ import absolute_import
+import subprocess
import unittest
-
import mock
+
from oslo_serialization import jsonutils
from yardstick.benchmark.scenarios.parser import parser
-@mock.patch('yardstick.benchmark.scenarios.parser.parser.subprocess')
class ParserTestCase(unittest.TestCase):
def setUp(self):
- pass
-
- def test_parser_successful_setup(self, mock_subprocess):
-
- p = parser.Parser({}, {})
- mock_subprocess.call().return_value = 0
- p.setup()
- self.assertTrue(p.setup_done)
-
- def test_parser_successful(self, mock_subprocess):
args = {
'options': {'yangfile': '/root/yardstick/samples/yang.yaml',
'toscafile': '/root/yardstick/samples/tosca.yaml'},
}
- p = parser.Parser(args, {})
+ self.scenario = parser.Parser(scenario_cfg=args, context_cfg={})
+
+ self._mock_popen = mock.patch.object(subprocess, 'Popen')
+ self.mock_popen = self._mock_popen.start()
+ self._mock_call = mock.patch.object(subprocess, 'call')
+ self.mock_call = self._mock_call.start()
+
+ self.addCleanup(self._stop_mock)
+
+ def _stop_mock(self):
+ self._mock_popen.stop()
+ self._mock_call.stop()
+
+ def test_setup_successful(self):
+
+ self.mock_call.return_value = 0
+ self.scenario.setup()
+ self.assertTrue(self.scenario.setup_done)
+
+ def test_run_successful(self):
+
result = {}
- mock_subprocess.call().return_value = 0
- sample_output = '{"yangtotosca": "success"}'
- p.run(result)
- expected_result = jsonutils.loads(sample_output) # pylint: disable=unused-variable
+ self.mock_popen().returncode = 0
+
+ expected_result = jsonutils.loads('{"yangtotosca": "success"}')
+
+ self.scenario.run(result)
+ self.assertEqual(result, expected_result)
+
+ def test_run_fail(self):
+ result = {}
+
+ self.mock_popen().returncode = 1
+ expected_result = jsonutils.loads('{"yangtotosca": "fail"}')
+
+ self.scenario.run(result)
+ self.assertEqual(result, expected_result)
- def test_parser_teardown_successful(self, mock_subprocess):
+ def test_teardown_successful(self):
- p = parser.Parser({}, {})
- mock_subprocess.call().return_value = 0
- p.teardown()
- self.assertTrue(p.teardown_done)
+ self.mock_call.return_value = 0
+ self.scenario.teardown()
+ self.assertTrue(self.scenario.teardown_done)
def main():
diff --git a/yardstick/benchmark/scenarios/parser/parser.py b/yardstick/benchmark/scenarios/parser/parser.py
index eb16833e5..5b2b49c2c 100644
--- a/yardstick/benchmark/scenarios/parser/parser.py
+++ b/yardstick/benchmark/scenarios/parser/parser.py
@@ -6,13 +6,13 @@
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
-from __future__ import print_function
-from __future__ import absolute_import
+
import pkg_resources
import logging
import subprocess
from yardstick.benchmark.scenarios import base
+
LOG = logging.getLogger(__name__)
@@ -63,7 +63,7 @@ class Parser(base.Scenario):
p = subprocess.Popen(cmd1, shell=True, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p.communicate()
- print("yangtotosca finished")
+ LOG.info("yangtotosca finished")
result['yangtotosca'] = "success" if p.returncode == 0 else "fail"