From 8acb74418a46367719fbb0144803ddd98cab8b0e Mon Sep 17 00:00:00 2001 From: Harold Zeng Date: Thu, 23 Apr 2020 18:17:08 +0800 Subject: [PATCH 1/6] fix cores in certain profiles --- .../azure/cli/core/tests/test_help.py | 40 +++++++++++-------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help.py b/src/azure-cli-core/azure/cli/core/tests/test_help.py index 18d4c842384..9da9bd20a52 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help.py @@ -365,13 +365,15 @@ def test_load_from_help_py(self, mocked_load, mocked_pkg_util): self.assertEqual(obj_param_dict["--arg1 -a"].value_sources[0]['link']['command'], "az foo bar") self.assertEqual(obj_param_dict["--arg1 -a"].value_sources[1]['link']['command'], "az bar baz") - self.assertEqual(command_help_obj.examples[0].short_summary, "Alpha Example") - self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 a --arg2 b --arg3 c") - self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") - self.assertEqual(command_help_obj.examples[0].unsupported_profiles, None) + if self.test_cli.cloud.profile in ['2018-03-01-hybrid', 'latest']: + # if won't show under other profiles + self.assertEqual(command_help_obj.examples[0].short_summary, "Alpha Example") + self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 a --arg2 b --arg3 c") + self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") + self.assertEqual(command_help_obj.examples[0].unsupported_profiles, None) - self.assertEqual(command_help_obj.examples[1].supported_profiles, None) - self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") + self.assertEqual(command_help_obj.examples[1].supported_profiles, None) + self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader) @@ -425,14 +427,16 @@ def test_load_from_help_yaml(self, mocked_load, mocked_pkg_util): self.assertEqual(obj_param_dict["--arg2 -b"].value_sources[2]['link'], {"command": "az test show", "title": "Show test details"}) - self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example") - self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") - self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 apple --arg2 ball --arg3 cat") - self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") - self.assertEqual(command_help_obj.examples[0].unsupported_profiles, None) + if self.test_cli.cloud.profile in ['2018-03-01-hybrid', 'latest']: + # if won't show under other profiles + self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example") + self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") + self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 apple --arg2 ball --arg3 cat") + self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") + self.assertEqual(command_help_obj.examples[0].unsupported_profiles, None) - self.assertEqual(command_help_obj.examples[1].supported_profiles, None) - self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") + self.assertEqual(command_help_obj.examples[1].supported_profiles, None) + self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") @mock.patch('inspect.getmembers', side_effect=mock_inspect_getmembers) @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @@ -486,10 +490,12 @@ def test_load_from_help_json(self, mocked_load, mocked_pkg_util, mocked_getmembe self.assertEqual(obj_param_dict["--arg3"].value_sources[2]['link'], {"command": "az test show", "title": "Show test details. Json file"}) - self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example from json") - self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") - self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 alpha --arg2 beta --arg3 chi") - self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") + if self.test_cli.cloud.profile in ['2018-03-01-hybrid', 'latest']: + # if won't show under other profiles + self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example from json") + self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") + self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 alpha --arg2 beta --arg3 chi") + self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") # validate other parameters, which have help from help.py and help.yamls self.assertEqual(obj_param_dict["--arg1 -a"].short_summary, "A short summary.") From e25beea564371bf030cd259f8adc2a6efdfa5bde Mon Sep 17 00:00:00 2001 From: harold random Date: Fri, 24 Apr 2020 00:28:01 +0800 Subject: [PATCH 2/6] update test_help.py tests about loading help entries --- .../azure/cli/core/tests/test_help.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help.py b/src/azure-cli-core/azure/cli/core/tests/test_help.py index 9da9bd20a52..d339ca41516 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help.py @@ -366,7 +366,6 @@ def test_load_from_help_py(self, mocked_load, mocked_pkg_util): self.assertEqual(obj_param_dict["--arg1 -a"].value_sources[1]['link']['command'], "az bar baz") if self.test_cli.cloud.profile in ['2018-03-01-hybrid', 'latest']: - # if won't show under other profiles self.assertEqual(command_help_obj.examples[0].short_summary, "Alpha Example") self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 a --arg2 b --arg3 c") self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") @@ -374,6 +373,10 @@ def test_load_from_help_py(self, mocked_load, mocked_pkg_util): self.assertEqual(command_help_obj.examples[1].supported_profiles, None) self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") + else: + # only supported example here + self.assertEqual(len(command_help_obj.examples), 1) + self.assertEqual(command_help_obj.examples[0].unsupported_profiles, '2017-03-09-profile') @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader) @@ -428,7 +431,6 @@ def test_load_from_help_yaml(self, mocked_load, mocked_pkg_util): "title": "Show test details"}) if self.test_cli.cloud.profile in ['2018-03-01-hybrid', 'latest']: - # if won't show under other profiles self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example") self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 apple --arg2 ball --arg3 cat") @@ -437,6 +439,10 @@ def test_load_from_help_yaml(self, mocked_load, mocked_pkg_util): self.assertEqual(command_help_obj.examples[1].supported_profiles, None) self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") + else: + # only supported example here + self.assertEqual(len(command_help_obj.examples), 1) + self.assertEqual(command_help_obj.examples[0].unsupported_profiles, '2017-03-09-profile') @mock.patch('inspect.getmembers', side_effect=mock_inspect_getmembers) @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @@ -491,11 +497,13 @@ def test_load_from_help_json(self, mocked_load, mocked_pkg_util, mocked_getmembe {"command": "az test show", "title": "Show test details. Json file"}) if self.test_cli.cloud.profile in ['2018-03-01-hybrid', 'latest']: - # if won't show under other profiles self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example from json") self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 alpha --arg2 beta --arg3 chi") self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") + else: + # only supported example here + self.assertEqual(len(command_help_obj.examples), 0) # validate other parameters, which have help from help.py and help.yamls self.assertEqual(obj_param_dict["--arg1 -a"].short_summary, "A short summary.") From db99a5a2e5615907c55a403363a69abfb76dc47b Mon Sep 17 00:00:00 2001 From: harold random Date: Fri, 24 Apr 2020 10:41:17 +0800 Subject: [PATCH 3/6] fix test_load_from_help_py under different profiles --- src/azure-cli-core/azure/cli/core/tests/test_help.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help.py b/src/azure-cli-core/azure/cli/core/tests/test_help.py index d339ca41516..db9266df8c2 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help.py @@ -373,11 +373,17 @@ def test_load_from_help_py(self, mocked_load, mocked_pkg_util): self.assertEqual(command_help_obj.examples[1].supported_profiles, None) self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") - else: - # only supported example here + + if self.test_cli.cloud.profile == '2019-03-01-hybrid': self.assertEqual(len(command_help_obj.examples), 1) + self.assertEqual(command_help_obj.examples[0].short_summary, "A simple example unsupported on latest") + self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 a --arg2 b") self.assertEqual(command_help_obj.examples[0].unsupported_profiles, '2017-03-09-profile') + if self.test_cli.cloud.profile == '2017-03-09-profile': + self.assertEqual(len(command_help_obj.examples), 0) + + @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader) def test_load_from_help_yaml(self, mocked_load, mocked_pkg_util): From cece4c784f939f52c20c844eee7707ccb0f47fef Mon Sep 17 00:00:00 2001 From: harold random Date: Fri, 24 Apr 2020 10:50:44 +0800 Subject: [PATCH 4/6] fix test_load_from_help_yaml --- src/azure-cli-core/azure/cli/core/tests/test_help.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help.py b/src/azure-cli-core/azure/cli/core/tests/test_help.py index db9266df8c2..bbe6035cec5 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help.py @@ -445,11 +445,16 @@ def test_load_from_help_yaml(self, mocked_load, mocked_pkg_util): self.assertEqual(command_help_obj.examples[1].supported_profiles, None) self.assertEqual(command_help_obj.examples[1].unsupported_profiles, "2017-03-09-profile") - else: - # only supported example here + + if self.test_cli.cloud.profile == '2019-03-01-hybrid': self.assertEqual(len(command_help_obj.examples), 1) + self.assertEqual(command_help_obj.examples[0].short_summary, "Another example unsupported on latest") + self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 apple --arg2 ball") self.assertEqual(command_help_obj.examples[0].unsupported_profiles, '2017-03-09-profile') + if self.test_cli.cloud.profile == '2017-03-09-profile': + self.assertEqual(len(command_help_obj.examples), 0) + @mock.patch('inspect.getmembers', side_effect=mock_inspect_getmembers) @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader) From 02c867f8611ecdd5ddc6ac44942d890d33d689e5 Mon Sep 17 00:00:00 2001 From: harold random Date: Fri, 24 Apr 2020 10:53:00 +0800 Subject: [PATCH 5/6] fix test_load_from_help_json --- src/azure-cli-core/azure/cli/core/tests/test_help.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help.py b/src/azure-cli-core/azure/cli/core/tests/test_help.py index bbe6035cec5..a537b182c60 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help.py @@ -512,10 +512,14 @@ def test_load_from_help_json(self, mocked_load, mocked_pkg_util, mocked_getmembe self.assertEqual(command_help_obj.examples[0].long_summary, "More detail on the simple example.") self.assertEqual(command_help_obj.examples[0].command, "az test alpha --arg1 alpha --arg2 beta --arg3 chi") self.assertEqual(command_help_obj.examples[0].supported_profiles, "2018-03-01-hybrid, latest") - else: + + if self.test_cli.cloud.profile == '2019-03-01-hybrid': # only supported example here self.assertEqual(len(command_help_obj.examples), 0) + if self.test_cli.cloud.profile == '2017-03-09-profile': + self.assertEqual(len(command_help_obj.examples), 0) + # validate other parameters, which have help from help.py and help.yamls self.assertEqual(obj_param_dict["--arg1 -a"].short_summary, "A short summary.") self.assertEqual(obj_param_dict["--arg2 -b"].short_summary, "Arg 2's summary.") From 1dd203cb889a140907d4d5944a8729b29afc6142 Mon Sep 17 00:00:00 2001 From: harold random Date: Fri, 24 Apr 2020 11:06:55 +0800 Subject: [PATCH 6/6] fix style --- src/azure-cli-core/azure/cli/core/tests/test_help.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/tests/test_help.py b/src/azure-cli-core/azure/cli/core/tests/test_help.py index a537b182c60..9f185b46d72 100644 --- a/src/azure-cli-core/azure/cli/core/tests/test_help.py +++ b/src/azure-cli-core/azure/cli/core/tests/test_help.py @@ -383,7 +383,6 @@ def test_load_from_help_py(self, mocked_load, mocked_pkg_util): if self.test_cli.cloud.profile == '2017-03-09-profile': self.assertEqual(len(command_help_obj.examples), 0) - @mock.patch('pkgutil.iter_modules', side_effect=lambda x: [(None, MOCKED_COMMAND_LOADER_MOD, None)]) @mock.patch('azure.cli.core.commands._load_command_loader', side_effect=mock_load_command_loader) def test_load_from_help_yaml(self, mocked_load, mocked_pkg_util):