From f036e9898a69f5041f9cde02e3652c29e2de1643 Mon Sep 17 00:00:00 2001 From: Ross Brattain Date: Mon, 5 Dec 2016 16:11:54 -0500 Subject: Add support for Python 3 Porting to Python3 using Openstack guidelines: https://wiki.openstack.org/wiki/Python3 This passes unittests on Python 3.5 and passes opnfv_smoke suite Updates: use six for urlparse and urlopen fix exception.message attribute removal run unittests on python3 use unitest.mock on python 3 fix open mock for vsperf fix float division by using delta/eplison comparison use unicode in StringIO use plugin/sample_config.yaml relative path from test case fixed apexlake unittests upgraded to mock 2.0.0 to match python3 unittest.mock features fixed flake8 issues implement safe JSON decode with oslo_serialization.jsonutils.dump_as_bytes() implement safe unicode encode/decode with oslo_utils.encodeutils heat: convert pub key file from bytes to unicode pkg_resources returns raw bytes, in python3 we have to decode this to utf-8 unicode so JSON can encode it for heat template JIRA: YARDSTICK-452 Change-Id: Ib80dd1d0c0eb0592acd832b82f6a7f8f7c20bfda Signed-off-by: Ross Brattain --- .../availability/test_result_checker_general.py | 30 ++++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'tests/unit/benchmark/scenarios/availability/test_result_checker_general.py') diff --git a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py index bbadf0ac3..c5451fabd 100644 --- a/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py +++ b/tests/unit/benchmark/scenarios/availability/test_result_checker_general.py @@ -12,11 +12,13 @@ # Unittest for yardstick.benchmark.scenarios.availability.result_checker # .result_checker_general +from __future__ import absolute_import import mock import unittest import copy -from yardstick.benchmark.scenarios.availability.result_checker import result_checker_general +from yardstick.benchmark.scenarios.availability.result_checker import \ + result_checker_general @mock.patch('yardstick.benchmark.scenarios.availability.result_checker.' @@ -35,16 +37,16 @@ class GeneralResultCheckerTestCase(unittest.TestCase): self.checker_cfg = { 'parameter': {'processname': 'process'}, 'checker_type': 'general-result-checker', - 'condition' : 'eq', - 'expectedValue' : 1, - 'key' : 'process-checker', - 'checker_key' : 'process-checker', + 'condition': 'eq', + 'expectedValue': 1, + 'key': 'process-checker', + 'checker_key': 'process-checker', 'host': 'node1' } def test__result_checker_eq(self, mock_open, mock_ssh): ins = result_checker_general.GeneralResultChecker(self.checker_cfg, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -53,7 +55,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'gt' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "2", '') ins.setup() self.assertTrue(ins.verify()) @@ -62,7 +64,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'gt_eq' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -71,7 +73,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'lt' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "0", '') ins.setup() self.assertTrue(ins.verify()) @@ -80,7 +82,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'lt_eq' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertTrue(ins.verify()) @@ -90,7 +92,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config['condition'] = 'in' config['expectedValue'] = "value" ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "value return", '') ins.setup() self.assertTrue(ins.verify()) @@ -99,7 +101,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config['condition'] = 'wrong' ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (0, "1", '') ins.setup() self.assertFalse(ins.verify()) @@ -108,7 +110,7 @@ class GeneralResultCheckerTestCase(unittest.TestCase): config = copy.deepcopy(self.checker_cfg) config.pop('parameter') ins = result_checker_general.GeneralResultChecker(config, - self.context); + self.context) mock_ssh.SSH().execute.return_value = (1, "fail", '') ins.setup() - ins.verify() \ No newline at end of file + ins.verify() -- cgit 1.2.3-korg