From bbfe9b09d2b1ac7bfe286311fef83d36c6125c96 Mon Sep 17 00:00:00 2001 From: Cédric Ollivier Date: Tue, 23 Jan 2018 11:19:41 +0100 Subject: Fix pylint warnings/errors in cli MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit cli_testcase and cli_tier have been refactored to avoid duplicating code. Then functest/cli and funtest/unit/cli can be added to the list of modules rated 10/10. Change-Id: Iec90e806397248a10f39080ec554e3f0a6eda7c1 Signed-off-by: Cédric Ollivier --- functest/tests/unit/cli/commands/test_cli_env.py | 23 +++++++++++----------- functest/tests/unit/cli/commands/test_cli_os.py | 17 +++++++--------- .../tests/unit/cli/commands/test_cli_testcase.py | 10 +++++----- functest/tests/unit/cli/commands/test_cli_tier.py | 17 ++++++++-------- 4 files changed, 31 insertions(+), 36 deletions(-) (limited to 'functest/tests/unit/cli/commands') diff --git a/functest/tests/unit/cli/commands/test_cli_env.py b/functest/tests/unit/cli/commands/test_cli_env.py index b5c653770..e5c409bf4 100644 --- a/functest/tests/unit/cli/commands/test_cli_env.py +++ b/functest/tests/unit/cli/commands/test_cli_env.py @@ -17,15 +17,13 @@ from functest.cli.commands import cli_env from functest.utils.constants import CONST -class RegexMatch(object): +class RegexMatch(object): # pylint: disable=too-few-public-methods def __init__(self, msg): self.msg = msg def __eq__(self, other): match = re.search(self.msg, other) - if match: - return True - return False + return match is not None class CliEnvTesting(unittest.TestCase): @@ -34,34 +32,35 @@ class CliEnvTesting(unittest.TestCase): self.cli_environ = cli_env.CliEnv() def _test_show_missing_env_var(self, var, *args): + # pylint: disable=unused-argument if var == 'INSTALLER_TYPE': CONST.__setattr__('INSTALLER_TYPE', None) - reg_string = "| INSTALLER: Unknown, \S+\s*|" + reg_string = r"| INSTALLER: Unknown, \S+\s*|" elif var == 'INSTALLER_IP': CONST.__setattr__('INSTALLER_IP', None) - reg_string = "| INSTALLER: \S+, Unknown\s*|" + reg_string = r"| INSTALLER: \S+, Unknown\s*|" elif var == 'SCENARIO': CONST.__setattr__('DEPLOY_SCENARIO', None) - reg_string = "| SCENARIO: Unknown\s*|" + reg_string = r"| SCENARIO: Unknown\s*|" elif var == 'NODE': CONST.__setattr__('NODE_NAME', None) - reg_string = "| POD: Unknown\s*|" + reg_string = r"| POD: Unknown\s*|" elif var == 'BUILD_TAG': CONST.__setattr__('BUILD_TAG', None) - reg_string = "| BUILD TAG: None|" + reg_string = r"| BUILD TAG: None|" elif var == 'DEBUG': CONST.__setattr__('CI_DEBUG', None) - reg_string = "| DEBUG FLAG: false\s*|" + reg_string = r"| DEBUG FLAG: false\s*|" with mock.patch('functest.cli.commands.cli_env.click.echo') \ as mock_click_echo: self.cli_environ.show() mock_click_echo.assert_called_with(RegexMatch(reg_string)) - def test_show_missing_ci_installer_type(self, *args): + def test_show_ci_installer_type_ko(self, *args): self._test_show_missing_env_var('INSTALLER_TYPE', *args) - def test_show_missing_ci_installer_ip(self, *args): + def test_show_ci_installer_ip_ko(self, *args): self._test_show_missing_env_var('INSTALLER_IP', *args) def test_show_missing_ci_scenario(self, *args): diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py index e4854cd6f..26956e08b 100644 --- a/functest/tests/unit/cli/commands/test_cli_os.py +++ b/functest/tests/unit/cli/commands/test_cli_os.py @@ -37,27 +37,24 @@ class CliOpenStackTesting(unittest.TestCase): @mock.patch('functest.cli.commands.cli_os.exit', side_effect=Exception) @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_ping_endpoint_missing_auth_url(self, mock_click_echo, - mock_exit): + def test_ping_endpoint_auth_url_ko(self, mock_click_echo, mock_exit): with self.assertRaises(Exception): self.cli_os.os_auth_url = None self.cli_os.ping_endpoint() - mock_click_echo.assert_called_once_with("Source the OpenStack " - "credentials first '. " - "$creds'") + mock_click_echo.assert_called_once_with( + "Source the OpenStack credentials first '. $creds'") + mock_exit.assert_called_once_with(0) @mock.patch('functest.cli.commands.cli_os.exit') @mock.patch('functest.cli.commands.cli_os.click.echo') - def test_ping_endpoint_os_system_fails(self, mock_click_echo, - mock_exit): + def test_ping_endpoint_system_fails(self, mock_click_echo, mock_exit): self.cli_os.os_auth_url = self.os_auth_url self.cli_os.endpoint_ip = self.endpoint_ip with mock.patch('functest.cli.commands.cli_os.os.system', return_value=1): self.cli_os.ping_endpoint() - mock_click_echo.assert_called_once_with("Cannot talk to the " - "endpoint %s\n" % - self.endpoint_ip) + mock_click_echo.assert_called_once_with( + "Cannot talk to the endpoint %s\n" % self.endpoint_ip) mock_exit.assert_called_once_with(0) def test_check(self): diff --git a/functest/tests/unit/cli/commands/test_cli_testcase.py b/functest/tests/unit/cli/commands/test_cli_testcase.py index 9ed7d8293..30e55fac0 100644 --- a/functest/tests/unit/cli/commands/test_cli_testcase.py +++ b/functest/tests/unit/cli/commands/test_cli_testcase.py @@ -19,28 +19,28 @@ class CliTestCasesTesting(unittest.TestCase): def setUp(self): self.testname = 'testname' - with mock.patch('functest.cli.commands.cli_testcase.tb'): + with mock.patch('functest.ci.tier_builder'): self.cli_tests = cli_testcase.CliTestcase() - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_default(self, mock_ft_utils): cmd = "run_tests -n -r -t {}".format(self.testname) self.cli_tests.run(self.testname, noclean=True, report=True) mock_ft_utils.assert_called_with(cmd) - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_noclean_missing_report(self, mock_ft_utils): cmd = "run_tests -n -t {}".format(self.testname) self.cli_tests.run(self.testname, noclean=True, report=False) mock_ft_utils.assert_called_with(cmd) - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_report_missing_noclean(self, mock_ft_utils): cmd = "run_tests -r -t {}".format(self.testname) self.cli_tests.run(self.testname, noclean=False, report=True) mock_ft_utils.assert_called_with(cmd) - @mock.patch('functest.cli.commands.cli_testcase.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_missing_noclean_report(self, mock_ft_utils): cmd = "run_tests -t {}".format(self.testname) self.cli_tests.run(self.testname, noclean=False, report=False) diff --git a/functest/tests/unit/cli/commands/test_cli_tier.py b/functest/tests/unit/cli/commands/test_cli_tier.py index 49c3c7a3e..f81ad31d0 100644 --- a/functest/tests/unit/cli/commands/test_cli_tier.py +++ b/functest/tests/unit/cli/commands/test_cli_tier.py @@ -20,7 +20,7 @@ class CliTierTesting(unittest.TestCase): def setUp(self): self.tiername = 'tiername' self.testnames = 'testnames' - with mock.patch('functest.cli.commands.cli_tier.tb'): + with mock.patch('functest.ci.tier_builder'): self.cli_tier = cli_tier.CliTier() @mock.patch('functest.cli.commands.cli_tier.click.echo') @@ -58,10 +58,9 @@ class CliTierTesting(unittest.TestCase): with mock.patch.object(self.cli_tier.tiers, 'get_tier', return_value=mock_obj): self.cli_tier.gettests(self.tiername) - mock_click_echo.assert_called_with("Test cases in tier " - "'%s':\n %s\n" % (self.tiername, - self.testnames - )) + mock_click_echo.assert_called_with( + "Test cases in tier '%s':\n %s\n" % ( + self.tiername, self.testnames)) @mock.patch('functest.cli.commands.cli_tier.click.echo') def test_gettests_missing_tier(self, mock_click_echo): @@ -75,25 +74,25 @@ class CliTierTesting(unittest.TestCase): ":\n %s\n" % (self.tiername, 'tiernames')) - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_default(self, mock_ft_utils): cmd = "run_tests -n -r -t {}".format(self.tiername) self.cli_tier.run(self.tiername, noclean=True, report=True) mock_ft_utils.assert_called_with(cmd) - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_report_missing_noclean(self, mock_ft_utils): cmd = "run_tests -r -t {}".format(self.tiername) self.cli_tier.run(self.tiername, noclean=False, report=True) mock_ft_utils.assert_called_with(cmd) - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_noclean_missing_report(self, mock_ft_utils): cmd = "run_tests -n -t {}".format(self.tiername) self.cli_tier.run(self.tiername, noclean=True, report=False) mock_ft_utils.assert_called_with(cmd) - @mock.patch('functest.cli.commands.cli_tier.ft_utils.execute_command') + @mock.patch('functest.utils.functest_utils.execute_command') def test_run_missing_noclean_report(self, mock_ft_utils): cmd = "run_tests -t {}".format(self.tiername) self.cli_tier.run(self.tiername, noclean=False, report=False) -- cgit 1.2.3-korg