From 262ed0e72b7cbf2d7869db988fb3d0246a1cf8bf Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Mon, 25 Nov 2019 11:47:55 +0100 Subject: [PATCH] idf.py: Fix regression ignorance of --verbose flag --- tools/idf_py_actions/core_ext.py | 3 +++ tools/test_idf_py/idf_ext.py | 15 ++++++++++---- tools/test_idf_py/test_idf_py.py | 35 ++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/tools/idf_py_actions/core_ext.py b/tools/idf_py_actions/core_ext.py index 7eff74e5f..396eb4ce5 100644 --- a/tools/idf_py_actions/core_ext.py +++ b/tools/idf_py_actions/core_ext.py @@ -53,6 +53,8 @@ def action_extensions(base_actions, project_path): for line in ctx.command.verbose_output: print(line) + return value + def clean(action, ctx, args): if not os.path.isdir(args.build_dir): print("Build directory '%s' not found. Nothing to clean." % args.build_dir) @@ -157,6 +159,7 @@ def action_extensions(base_actions, project_path): "names": ["--version"], "help": "Show IDF version and exit.", "is_flag": True, + "expose_value": False, "callback": idf_version_callback }, { diff --git a/tools/test_idf_py/idf_ext.py b/tools/test_idf_py/idf_ext.py index b8fc8c3f2..d35ea50f3 100644 --- a/tools/test_idf_py/idf_ext.py +++ b/tools/test_idf_py/idf_ext.py @@ -2,6 +2,11 @@ def action_extensions(base_actions, project_path=None): def echo(name, *args, **kwargs): print(name, args, kwargs) + def verbose(name, ctx, args): + print("Output from test-verbose") + if args.verbose: + print("Verbose mode on") + # Add global options extensions = { "global_options": [ @@ -37,11 +42,13 @@ def action_extensions(base_actions, project_path=None): }, ], "actions": { + "test-verbose": { + "callback": verbose, + "help": "Command that have some verbosity", + }, "test-0": { - "callback": - echo, - "help": - "Non-deprecated command 0", + "callback": echo, + "help": "Non-deprecated command 0", "options": [ { "names": ["--test-sub-0"], diff --git a/tools/test_idf_py/test_idf_py.py b/tools/test_idf_py/test_idf_py.py index 212fc9e59..9c7cb7a1a 100755 --- a/tools/test_idf_py/test_idf_py.py +++ b/tools/test_idf_py/test_idf_py.py @@ -115,8 +115,9 @@ class TestDependencyManagement(unittest.TestCase): standalone_mode=False, ) sys.stdout = sys.__stdout__ - self.assertIn('WARNING: Commands "all", "clean" are found in the list of commands more than once.', - capturedOutput.getvalue()) + self.assertIn( + 'WARNING: Commands "all", "clean" are found in the list of commands more than once.', + capturedOutput.getvalue()) sys.stdout = capturedOutput idf.init_cli()( @@ -124,8 +125,34 @@ class TestDependencyManagement(unittest.TestCase): standalone_mode=False, ) sys.stdout = sys.__stdout__ - self.assertIn('WARNING: Command "clean" is found in the list of commands more than once.', - capturedOutput.getvalue()) + self.assertIn( + 'WARNING: Command "clean" is found in the list of commands more than once.', capturedOutput.getvalue()) + + +class TestVerboseFlag(unittest.TestCase): + def test_verbose_messages(self): + output = subprocess.check_output( + [ + sys.executable, + idf_py_path, + "-C%s" % current_dir, + "-v", + "test-verbose", + ], env=os.environ).decode('utf-8', 'ignore') + + self.assertIn('Verbose mode on', output) + + def test_verbose_messages_not_shown_by_default(self): + output = subprocess.check_output( + [ + sys.executable, + idf_py_path, + "-C%s" % current_dir, + "test-verbose", + ], env=os.environ).decode('utf-8', 'ignore') + + self.assertIn('Output from test-verbose', output) + self.assertNotIn('Verbose mode on', output) class TestGlobalAndSubcommandParameters(unittest.TestCase):