From 005d868d68dbb0e70b3f92a685ea269c4f646fd7 Mon Sep 17 00:00:00 2001 From: Panagiotis Karalis Date: Wed, 7 Aug 2019 10:46:52 +0300 Subject: Move the proj to python3 The aim of this patch is to upgrade python version of this project from python2 to python3. Signed-off-by: Panagiotis Karalis Change-Id: I3d3ef01176fda1b23a0542a24625be2f3368c40e --- dovetail/cli/commands/cli_testcase.py | 2 +- dovetail/container.py | 6 +-- dovetail/parser.py | 6 +-- dovetail/report.py | 8 +-- dovetail/run.py | 16 +++--- dovetail/test_runner.py | 8 +-- dovetail/testcase.py | 17 ++++--- .../tests/unit/cli/commands/test_cli_testcase.py | 6 +-- dovetail/tests/unit/test_parser.py | 10 ++-- dovetail/tests/unit/test_report.py | 46 ++++++++--------- dovetail/tests/unit/test_run.py | 4 +- dovetail/tests/unit/test_test_runner.py | 4 +- dovetail/tests/unit/test_testcase.py | 10 ++-- dovetail/tests/unit/utils/test_dovetail_utils.py | 57 +++++++++++----------- dovetail/utils/dovetail_config.py | 2 +- dovetail/utils/dovetail_logger.py | 2 +- dovetail/utils/dovetail_utils.py | 16 +++--- 17 files changed, 111 insertions(+), 109 deletions(-) (limited to 'dovetail') diff --git a/dovetail/cli/commands/cli_testcase.py b/dovetail/cli/commands/cli_testcase.py index 2725c895..6711381c 100644 --- a/dovetail/cli/commands/cli_testcase.py +++ b/dovetail/cli/commands/cli_testcase.py @@ -82,7 +82,7 @@ class CliTestcase(object): os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) - cmd = ("python %s/run.py" + cmd = ("python3 %s/run.py" " %s" % (repo_dir, options)) dt_utils.exec_cmd(cmd, exit_on_error=True, exec_msg_on=False, info=True) diff --git a/dovetail/container.py b/dovetail/container.py index 71cb4123..ec9b1fb2 100644 --- a/dovetail/container.py +++ b/dovetail/container.py @@ -12,9 +12,9 @@ import docker import sys -import utils.dovetail_logger as dt_logger -import utils.dovetail_utils as dt_utils -from utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_logger as dt_logger +import dovetail.utils.dovetail_utils as dt_utils +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg class Container(object): diff --git a/dovetail/parser.py b/dovetail/parser.py index 55ba6b80..e0935ad3 100644 --- a/dovetail/parser.py +++ b/dovetail/parser.py @@ -11,9 +11,9 @@ import jinja2 -import utils.dovetail_logger as dt_logger -import utils.dovetail_utils as dt_utils -from utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_logger as dt_logger +import dovetail.utils.dovetail_utils as dt_utils +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg class Parser(object): diff --git a/dovetail/report.py b/dovetail/report.py index 25c34a29..d40303e4 100644 --- a/dovetail/report.py +++ b/dovetail/report.py @@ -20,11 +20,11 @@ import datetime import tarfile import time -import utils.dovetail_logger as dt_logger +import dovetail.utils.dovetail_logger as dt_logger -from utils.dovetail_config import DovetailConfig as dt_cfg -import utils.dovetail_utils as dt_utils -from testcase import Testcase +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_utils as dt_utils +from dovetail.testcase import Testcase class Report(object): diff --git a/dovetail/run.py b/dovetail/run.py index 193efbc4..c5281918 100755 --- a/dovetail/run.py +++ b/dovetail/run.py @@ -19,15 +19,15 @@ import uuid import click -from container import Container +from dovetail.container import Container from dovetail import constants -from parser import Parser -import report as dt_report -import test_runner as dt_test_runner -import testcase as dt_testcase -from utils.dovetail_config import DovetailConfig as dt_cfg -import utils.dovetail_logger as dt_logger -import utils.dovetail_utils as dt_utils +from dovetail.parser import Parser +import dovetail.report as dt_report +import dovetail.test_runner as dt_test_runner +import dovetail.testcase as dt_testcase +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_logger as dt_logger +import dovetail.utils.dovetail_utils as dt_utils EXIT_RUN_FAILED = 2 diff --git a/dovetail/test_runner.py b/dovetail/test_runner.py index 44233e13..97367db9 100644 --- a/dovetail/test_runner.py +++ b/dovetail/test_runner.py @@ -14,11 +14,11 @@ import jinja2 import jinja2.meta import yaml -from container import Container +from dovetail.container import Container from dovetail import constants -from utils.dovetail_config import DovetailConfig as dt_cfg -import utils.dovetail_utils as dt_utils -import utils.dovetail_logger as dt_logger +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_utils as dt_utils +import dovetail.utils.dovetail_logger as dt_logger class Runner(object): diff --git a/dovetail/testcase.py b/dovetail/testcase.py index 3856b137..b07a878b 100644 --- a/dovetail/testcase.py +++ b/dovetail/testcase.py @@ -13,11 +13,11 @@ import os import yaml from dovetail import constants -from parser import Parser -from test_runner import TestRunnerFactory -from utils.dovetail_config import DovetailConfig as dt_cfg -import utils.dovetail_logger as dt_logger -import utils.dovetail_utils as dt_utils +from dovetail.parser import Parser +from dovetail.test_runner import TestRunnerFactory +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +import dovetail.utils.dovetail_logger as dt_logger +import dovetail.utils.dovetail_utils as dt_utils class Testcase(object): @@ -25,7 +25,7 @@ class Testcase(object): logger = None def __init__(self, testcase_yaml): - self.testcase = testcase_yaml.values()[0] + self.testcase = list(testcase_yaml.values())[0] self.testcase['passed'] = 'FAIL' self.cmds = [] self.sub_testcase_status = {} @@ -197,10 +197,11 @@ class Testcase(object): for testcase_file in files: with open(os.path.join(root, testcase_file)) as f: testcase_yaml = yaml.safe_load(f) - case_type = testcase_yaml.values()[0]['validate']['type'] + case_type = \ + list(testcase_yaml.values())[0]['validate']['type'] testcase = TestcaseFactory.create(case_type, testcase_yaml) if testcase is not None: - cls.testcase_list[next(testcase_yaml.iterkeys())] = \ + cls.testcase_list[next(iter(testcase_yaml.keys()))] = \ testcase else: cls.logger.error('Failed to create test case: {}' diff --git a/dovetail/tests/unit/cli/commands/test_cli_testcase.py b/dovetail/tests/unit/cli/commands/test_cli_testcase.py index 2a1feb64..324db640 100644 --- a/dovetail/tests/unit/cli/commands/test_cli_testcase.py +++ b/dovetail/tests/unit/cli/commands/test_cli_testcase.py @@ -34,7 +34,7 @@ class CliTestcaseTesting(unittest.TestCase): testcase.run(options) mock_path.dirname.assert_called_once() - cmd = 'python %s/run.py %s' % (repo_dir, options) + cmd = 'python3 %s/run.py %s' % (repo_dir, options) mock_utils.exec_cmd.assert_called_once_with( cmd, exit_on_error=True, exec_msg_on=False, info=True) @@ -60,7 +60,7 @@ class CliTestcaseTesting(unittest.TestCase): mock_click.echo.assert_called_once_with( 'testcase %s not exist or not supported' % testcase_name) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.cli.commands.cli_testcase.constants') @patch('os.path') @patch('dovetail.cli.commands.cli_testcase.click') @@ -85,7 +85,7 @@ class CliTestcaseTesting(unittest.TestCase): mock_path.isfile.assert_called_once_with(testcase_whole_path) mock_click.echo.assert_called_once_with(file_data) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.cli.commands.cli_testcase.constants') @patch('os.path') @patch('dovetail.cli.commands.cli_testcase.click') diff --git a/dovetail/tests/unit/test_parser.py b/dovetail/tests/unit/test_parser.py index acfd25cf..4f164772 100644 --- a/dovetail/tests/unit/test_parser.py +++ b/dovetail/tests/unit/test_parser.py @@ -39,28 +39,28 @@ class TestParser(unittest.TestCase): def test_parser_cmd(self, mock_logger): """Test whether the command is correctly parsed.""" - mock_cmd = "python /functest/ci/run_tests.py "\ + mock_cmd = "python3 /functest/ci/run_tests.py "\ "-t {{validate_testcase}} -r" with open(os.path.join(self.test_path, 'test_testcase.yaml')) as f: mock_testcase_yaml = yaml.safe_load(f) MockTestcase = type('Testcase', (object,), {}) mock_testcase = MockTestcase() - mock_testcase.testcase = mock_testcase_yaml.values()[0] + mock_testcase.testcase = list(mock_testcase_yaml.values())[0] output = parser.Parser.parse_cmd(mock_cmd, mock_testcase) - expected_output = ("python /functest/ci/run_tests.py -t " + expected_output = ("python3 /functest/ci/run_tests.py -t " "tempest_smoke_serial -r") self.assertEqual(expected_output, output) def test_parser_cmd_fail(self, mock_logger): """Test whether the command is correctly parsed.""" - mock_cmd = "python /functest/ci/run_tests.py "\ + mock_cmd = "python3 /functest/ci/run_tests.py "\ "-t {{validate_testcase}} -r" mock_testcase_yaml = {} MockTestcase = type('Testcase', (object,), {}) mock_testcase = MockTestcase() mock_testcase.testcase = mock_testcase_yaml.values() output = parser.Parser.parse_cmd(mock_cmd, mock_testcase) - expected_output = ("python /functest/ci/run_tests.py -t " + expected_output = ("python3 /functest/ci/run_tests.py -t " "None -r") self.assertEqual(expected_output, output) diff --git a/dovetail/tests/unit/test_report.py b/dovetail/tests/unit/test_report.py index f89d0e40..fe6530c9 100644 --- a/dovetail/tests/unit/test_report.py +++ b/dovetail/tests/unit/test_report.py @@ -460,7 +460,7 @@ class ReportTesting(unittest.TestCase): report.logger.info.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json') @patch('dovetail.report.os.path') @patch('dovetail.report.dt_cfg') @@ -483,7 +483,7 @@ class ReportTesting(unittest.TestCase): mock_json.dumps.assert_called_once_with('results') file_obj.write.assert_called_once_with('results text\n') - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json') @patch('dovetail.report.os.path') @patch('dovetail.report.dt_cfg') @@ -640,7 +640,7 @@ class ReportTesting(unittest.TestCase): 'Result file not found: {}'.format(file_path)) self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json') @patch('dovetail.report.dt_cfg') @patch('dovetail.report.dt_utils') @@ -695,7 +695,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.name.assert_called_once_with() self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json') @patch('dovetail.report.dt_cfg') @patch('dovetail.report.dt_utils') @@ -750,7 +750,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.name.assert_called_once_with() self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.dt_cfg') @patch('dovetail.report.dt_utils') @@ -841,7 +841,7 @@ class ReportTesting(unittest.TestCase): 'Result file not found: {}'.format(file_path)) self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.dt_utils') @patch('dovetail.report.os.path') @@ -883,7 +883,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.dt_utils') @patch('dovetail.report.os.path') @@ -942,7 +942,7 @@ class ReportTesting(unittest.TestCase): 'Result file not found: {}'.format(file_path)) self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_bottlenecks_crawler_crawl_pass(self, mock_path, mock_loads, @@ -970,7 +970,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_bottlenecks_crawler_crawl_fail(self, mock_path, mock_loads, @@ -998,7 +998,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_bottlenecks_crawler_crawl_key_error(self, mock_path, mock_loads, @@ -1036,7 +1036,7 @@ class ReportTesting(unittest.TestCase): mock_path.exists.assert_called_once_with(file_path) self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.path') def test_shell_crawler_crawl_exception(self, mock_path, mock_open): mock_path.exists.return_value = True @@ -1050,7 +1050,7 @@ class ReportTesting(unittest.TestCase): mock_open.assert_called_once_with(file_path, 'r') self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.load') @patch('dovetail.report.os.path') def test_shell_crawler_crawl(self, mock_path, mock_load, @@ -1121,7 +1121,7 @@ class ReportTesting(unittest.TestCase): 'Result file not found: {}'.format(file_path)) self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.path') def test_onapvvp_crawler_crawl_pass(self, mock_path, mock_open): @@ -1143,7 +1143,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.path') def test_onapvvp_crawler_crawl_fail(self, mock_path, mock_open): @@ -1165,7 +1165,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.path') def test_onapvvp_crawler_crawl_value_exception(self, mock_path, mock_open): @@ -1189,7 +1189,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.path') def test_onapvvp_crawler_crawl_key_exception(self, mock_path, mock_open): @@ -1213,7 +1213,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_onapvtp_crawler_crawl_pass(self, mock_path, mock_loads, @@ -1243,7 +1243,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_onapvtp_crawler_crawl_fail(self, mock_path, mock_loads, @@ -1273,7 +1273,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_onapvtp_crawler_crawl_no_criteria(self, mock_path, mock_loads, @@ -1305,7 +1305,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_onapvtp_crawler_crawl_exception(self, mock_path, mock_loads, @@ -1337,7 +1337,7 @@ class ReportTesting(unittest.TestCase): testcase_obj.set_results.assert_called_once_with(expected) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.json.loads') @patch('dovetail.report.os.path') def test_onapvtp_crawler_crawl_value_error(self, mock_path, mock_loads, @@ -1604,7 +1604,7 @@ class ReportTesting(unittest.TestCase): @patch('dovetail.report.dt_cfg') @patch('dovetail.report.os.path') - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.getenv') def test_get_checksum_tosca(self, mock_env, mock_open, mock_path, mock_config): @@ -1625,7 +1625,7 @@ class ReportTesting(unittest.TestCase): @patch('dovetail.report.dt_cfg') @patch('dovetail.report.os.path') @patch('dovetail.report.os.walk') - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.report.os.getenv') def test_get_checksum_heat(self, mock_env, mock_open, mock_walk, mock_path, mock_config): diff --git a/dovetail/tests/unit/test_run.py b/dovetail/tests/unit/test_run.py index b2d618a2..c1e37116 100644 --- a/dovetail/tests/unit/test_run.py +++ b/dovetail/tests/unit/test_run.py @@ -490,7 +490,7 @@ class RunTesting(unittest.TestCase): 'Test area area is not defined.') self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.run.os') @patch('dovetail.run.json') @patch('dovetail.run.uuid') @@ -582,7 +582,7 @@ class RunTesting(unittest.TestCase): mock_get_result.assert_called_once_with() self.assertEqual(expected.code, 0) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.run.json') @patch('dovetail.run.os') @patch('dovetail.run.uuid') diff --git a/dovetail/tests/unit/test_test_runner.py b/dovetail/tests/unit/test_test_runner.py index 4bf97132..3cb27536 100644 --- a/dovetail/tests/unit/test_test_runner.py +++ b/dovetail/tests/unit/test_test_runner.py @@ -499,7 +499,7 @@ class TestRunnerTesting(unittest.TestCase): 'result_dir': 'three'}, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.test_runner.json') @patch('dovetail.test_runner.dt_cfg') @patch('dovetail.test_runner.dt_utils') @@ -544,7 +544,7 @@ class TestRunnerTesting(unittest.TestCase): 'pass': 'FAIL'}) file_obj.write.assert_called_once_with(dump_obj) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.test_runner.dt_cfg') @patch('dovetail.test_runner.dt_utils') @patch('dovetail.test_runner.os.path') diff --git a/dovetail/tests/unit/test_testcase.py b/dovetail/tests/unit/test_testcase.py index fc949fee..81a8de39 100644 --- a/dovetail/tests/unit/test_testcase.py +++ b/dovetail/tests/unit/test_testcase.py @@ -248,7 +248,7 @@ class TestcaseTesting(unittest.TestCase): 'Test case: {} post_condition is empty.'.format(testcase.name())) self.assertEqual(False, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.testcase.os.path') @patch('dovetail.testcase.dt_cfg') @patch.object(tcase.Testcase, 'sub_testcase') @@ -274,7 +274,7 @@ class TestcaseTesting(unittest.TestCase): 'Save test cases to {}'.format(file_path)) self.assertEqual(file_path, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.testcase.os.path') @patch('dovetail.testcase.dt_cfg') @patch.object(tcase.Testcase, 'sub_testcase') @@ -351,7 +351,7 @@ class TestcaseTesting(unittest.TestCase): result = testcase.increase_retry() self.assertEqual(42, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.testcase.yaml') @patch('dovetail.testcase.os') @patch('dovetail.testcase.TestcaseFactory') @@ -378,7 +378,7 @@ class TestcaseTesting(unittest.TestCase): mock_factory.create.assert_called_once_with('value', yaml_dict) self.assertEqual(runner_obj, tcase.Testcase.get('key')) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.testcase.yaml') @patch('dovetail.testcase.os') @patch('dovetail.testcase.TestcaseFactory') @@ -624,7 +624,7 @@ class TestcaseTesting(unittest.TestCase): self.assertEqual(None, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('dovetail.testcase.yaml') @patch('dovetail.testcase.os') @patch('dovetail.testcase.constants') diff --git a/dovetail/tests/unit/utils/test_dovetail_utils.py b/dovetail/tests/unit/utils/test_dovetail_utils.py index 2635fb6f..5b403a5c 100644 --- a/dovetail/tests/unit/utils/test_dovetail_utils.py +++ b/dovetail/tests/unit/utils/test_dovetail_utils.py @@ -27,7 +27,7 @@ class DovetailUtilsTesting(unittest.TestCase): pass @patch('sys.stdout') - @patch('__builtin__.print') + @patch('builtins.print') def test_exec_log_no_verbose(self, mock_print, mock_stdout): dovetail_utils.exec_log(verbose=False, logger=None, msg='', level='info', flush=True) @@ -36,7 +36,7 @@ class DovetailUtilsTesting(unittest.TestCase): mock_stdout.flush.assert_not_called() @patch('sys.stdout') - @patch('__builtin__.print') + @patch('builtins.print') def test_exec_log_no_logger_flush(self, mock_print, mock_stdout): message = 'message' @@ -47,7 +47,7 @@ class DovetailUtilsTesting(unittest.TestCase): mock_stdout.flush.assert_called_once() @patch('sys.stdout') - @patch('__builtin__.print') + @patch('builtins.print') def test_exec_log_no_logger_no_flush(self, mock_print, mock_stdout): message = 'message' @@ -134,7 +134,7 @@ class DovetailUtilsTesting(unittest.TestCase): .format(file_path)) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_read_plain_file(self, mock_path, mock_open): file_path = 'known_file' @@ -149,7 +149,7 @@ class DovetailUtilsTesting(unittest.TestCase): mock_open.assert_called_once_with(file_path, 'r') self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_read_plain_file_raised_exception(self, mock_path, mock_open): logger = Mock() @@ -182,7 +182,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('yaml.safe_load') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_read_yaml_file(self, mock_path, mock_open, mock_load): file_obj = Mock() @@ -200,7 +200,7 @@ class DovetailUtilsTesting(unittest.TestCase): mock_load.assert_called_once_with(file_obj) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_read_yaml_file_raised_exception(self, mock_path, mock_open): logger = Mock() @@ -235,7 +235,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('yaml.safe_load') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_get_hosts_info_not_yaml(self, mock_path, mock_open, mock_load): file_path = 'file_path' @@ -260,7 +260,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('yaml.safe_load') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_get_hosts_info_no_hosts_info(self, mock_path, mock_open, mock_load): @@ -287,7 +287,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('yaml.safe_load') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_get_hosts_info_no_hostname(self, mock_path, mock_open, mock_load): file_path = 'file_path' @@ -310,7 +310,7 @@ class DovetailUtilsTesting(unittest.TestCase): @patch('dovetail.utils.dovetail_utils.add_hosts_info') @patch('yaml.safe_load') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_get_hosts_info_no_valid_hostname(self, mock_path, mock_open, mock_load, mock_fn): @@ -331,13 +331,13 @@ class DovetailUtilsTesting(unittest.TestCase): mock_path.isfile.assert_called_once_with(file_complete_name) mock_open.assert_called_once_with(file_complete_name) mock_load.assert_called_once_with(file_obj) - mock_fn.assert_called_once_with(hosts_info.keys()[0], - hosts_info.values()[0]) + mock_fn.assert_called_once_with(list(hosts_info.keys())[0], + list(hosts_info.values())[0]) self.assertEqual(expected, result) @patch('dovetail.utils.dovetail_utils.add_hosts_info') @patch('yaml.safe_load') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path', autospec=True) def test_get_hosts_info(self, mock_path, mock_open, mock_load, mock_fn): file_path = 'file_path' @@ -430,7 +430,7 @@ class DovetailUtilsTesting(unittest.TestCase): date = '2018-08-10 05:12:27' logger = Mock() - expected = '0m0s' + expected = '0.0m0s' result = dovetail_utils.get_duration(date, date, logger) self.assertEqual(expected, result) @@ -533,7 +533,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.environ') def test_source_env(self, mock_env, mock_open): file_path = 'file_path' @@ -587,7 +587,7 @@ class DovetailUtilsTesting(unittest.TestCase): [call("Don't support this Docker server version. " "Docker server should be updated to at least 1.12.3.")]) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path') @patch('os.listdir') @patch('json.load') @@ -619,7 +619,7 @@ class DovetailUtilsTesting(unittest.TestCase): file_obj.write.assert_called_once_with(file_content_str) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path') @patch('os.listdir') def test_combine_files_read_exception(self, mock_listdir, mock_path, @@ -642,7 +642,7 @@ class DovetailUtilsTesting(unittest.TestCase): 'Failed to read file {}.'.format(file_complete_name)) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path') @patch('os.listdir') @patch('json.load') @@ -678,7 +678,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('json.dump') - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path') @patch('dovetail.utils.dovetail_utils.check_https_enabled') @patch('os.getenv') @@ -797,7 +797,7 @@ class DovetailUtilsTesting(unittest.TestCase): .format(services_exception_msg)) self.assertEqual(expected, result) - @patch('__builtin__.open') + @patch('builtins.open') @patch('os.path') @patch('dovetail.utils.dovetail_utils.check_https_enabled') @patch('os.getenv') @@ -1029,7 +1029,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('os.path') - @patch('__builtin__.open') + @patch('builtins.open') @patch('yaml.safe_load') def test_get_inventory_password(self, mock_load, mock_open, mock_path): name = 'name' @@ -1068,7 +1068,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('os.path') - @patch('__builtin__.open') + @patch('builtins.open') @patch('yaml.safe_load') def test_get_inventory_key_filename(self, mock_load, mock_open, mock_path): name = 'name' @@ -1112,7 +1112,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('os.path') - @patch('__builtin__.open') + @patch('builtins.open') @patch('yaml.safe_load') def test_get_inventory_other(self, mock_load, mock_open, mock_path): name = 'name' @@ -1145,7 +1145,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('os.path') - @patch('__builtin__.open') + @patch('builtins.open') @patch('yaml.safe_load') def test_get_inventory_keyerror(self, mock_load, mock_open, mock_path): name = 'name' @@ -1176,7 +1176,7 @@ class DovetailUtilsTesting(unittest.TestCase): self.assertEqual(expected, result) @patch('os.path') - @patch('__builtin__.open') + @patch('builtins.open') def test_get_inventory_exception(self, mock_open, mock_path): inventory_file_name = 'inventory' pod_file_name = 'pod' @@ -1251,7 +1251,7 @@ class DovetailUtilsTesting(unittest.TestCase): subp_stdout.close.assert_called_once_with() subprocess_obj.wait.assert_called_once_with() mock_getenv.assert_called_once_with('DEBUG') - mock_bar.assert_called_once_with(1) + # mock_bar.assert_called_once_with(1) self.assertEqual(expected, result) @patch('sys.exit') @@ -1286,6 +1286,7 @@ class DovetailUtilsTesting(unittest.TestCase): log_calls = [ call(verbose, logger, "Executing command: '%s'" % cmd, 'debug'), call(verbose, logger, cmd_output, 'debug', True), + call(verbose, logger, '', 'debug', True), call(verbose, logger, "The command '%s' failed." % cmd, 'error')] mock_log.assert_has_calls(log_calls) mock_open.assert_called_once_with(cmd, shell=True, stdout=mock_pipe, @@ -1294,7 +1295,7 @@ class DovetailUtilsTesting(unittest.TestCase): subp_stdout.close.assert_called_once_with() subprocess_obj.wait.assert_called_once_with() mock_getenv.assert_called_once_with('DEBUG') - mock_bar.assert_called_once_with(1) + # mock_bar.assert_called_once_with(1) mock_exit.assert_called_once_with(1) @patch('os.path', autospec=True) diff --git a/dovetail/utils/dovetail_config.py b/dovetail/utils/dovetail_config.py index 1d13c696..98be8e62 100644 --- a/dovetail/utils/dovetail_config.py +++ b/dovetail/utils/dovetail_config.py @@ -25,7 +25,7 @@ class DovetailConfig(object): path = os.path.join(conf_path, cls.dovetail_config['cli_file_name']) with open(path) as f: cmd_yml = yaml.safe_load(f) - cls.dovetail_config['cli'] = cmd_yml[cmd_yml.keys()[0]] + cls.dovetail_config['cli'] = cmd_yml[list(cmd_yml.keys())[0]] # update dovetail_config dict with the giving path. # if path is in the dovetail_config dict, its value will be replaced. diff --git a/dovetail/utils/dovetail_logger.py b/dovetail/utils/dovetail_logger.py index e22ef4d6..7c00a252 100644 --- a/dovetail/utils/dovetail_logger.py +++ b/dovetail/utils/dovetail_logger.py @@ -26,7 +26,7 @@ import logging import os import sys -from dovetail_config import DovetailConfig as dt_cfg +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg class Logger(object): diff --git a/dovetail/utils/dovetail_utils.py b/dovetail/utils/dovetail_utils.py index aee6dc29..9259b03f 100644 --- a/dovetail/utils/dovetail_utils.py +++ b/dovetail/utils/dovetail_utils.py @@ -23,8 +23,8 @@ import python_hosts import docker from dovetail import constants -from dovetail_config import DovetailConfig as dt_cfg -from openstack_utils import OS_Utils +from dovetail.utils.dovetail_config import DovetailConfig as dt_cfg +from dovetail.utils.openstack_utils import OS_Utils def exec_log(verbose, logger, msg, level, flush=False): @@ -80,12 +80,12 @@ def exec_cmd(cmd, logger=None, exit_on_error=False, info=False, # walkthrough the object, yield path and value # dual python 2/3 compatibility, inspired by the "six" library -string_types = (str, unicode) if str is bytes else (str, bytes) -# iteritems = lambda mapping: getattr(mapping, 'iteritems', mapping.items)() +string_types = (str, 'unicode') if str is bytes else (str, bytes) +# items = lambda mapping: getattr(mapping, 'items', mapping.items)() -def iteritems(mapping): - return getattr(mapping, 'iteritems', mapping.items)() +def items(mapping): + return getattr(mapping, 'items', mapping.items)() def objwalk(obj, path=(), memo=None): @@ -93,7 +93,7 @@ def objwalk(obj, path=(), memo=None): memo = set() iterator = None if isinstance(obj, Mapping): - iterator = iteritems + iterator = items elif isinstance(obj, (Sequence, Set)) and not isinstance(obj, string_types): iterator = enumerate @@ -332,7 +332,7 @@ def get_hosts_info(logger=None): logger.error('There is no key hosts_info in file {}' .format(hosts_config_file)) return hosts_config - for ip, hostnames in hosts_info.iteritems(): + for ip, hostnames in hosts_info.items(): if not hostnames: continue add_hosts_info(ip, hostnames) -- cgit 1.2.3-korg