From f4573cef48bb594fa7156703813151745d7ef5c7 Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Thu, 27 Jun 2024 12:40:12 -0400 Subject: [PATCH] Fix user provided default run and variation for cat command --- python/ccdb/cmd/commands/cat.py | 14 ++++++++++++-- python/tests/integ_test_cli_manager.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/python/ccdb/cmd/commands/cat.py b/python/ccdb/cmd/commands/cat.py index 8aead43..4f6f093 100644 --- a/python/ccdb/cmd/commands/cat.py +++ b/python/ccdb/cmd/commands/cat.py @@ -147,7 +147,7 @@ def process_arguments(self, args): parser.add_argument("-d", "--directory") parser.add_argument("-v", "--variation") - parser.add_argument("-a", "--ass-id") + parser.add_argument("-a", "--id") parser.add_argument("-r", "--run") parser.add_argument("-f", "--file") parser.add_argument("-ph", "--horizontal", action="store_true", dest='user_request_print_horizontal') @@ -159,6 +159,16 @@ def process_arguments(self, args): # it probably must be a request or just a table name result.request = parse_request(result.obj_name) + # Check if user set the default variation + if not result.request.variation_is_parsed and self.context.current_variation: + result.request.variation = self.context.current_variation + result.request.variation_is_parsed = True + + # Check if user set the default run + if not result.request.run_is_parsed and self.context.current_run: + result.request.run = self.context.current_run + result.request.run_is_parsed = True + return result # ---------------------------------------- @@ -410,7 +420,7 @@ def print_help(self): Usage: cat - cat --id #Where assignment_id provided by 'vers ' command + cat -a #Where assignment_id provided by 'vers
' command Formatting flags: diff --git a/python/tests/integ_test_cli_manager.py b/python/tests/integ_test_cli_manager.py index 16c5369..b2f5e10 100644 --- a/python/tests/integ_test_cli_manager.py +++ b/python/tests/integ_test_cli_manager.py @@ -77,6 +77,19 @@ def test_cat(self): self.cli.process_command_line("cat /test/test_vars/test_table") self.assertIn("2.3", self.output.getvalue()) + def test_cat_user_set_variation(self): + """In non-interactive mode, cat should handle path without leading / as absolute anyway""" + + # Test DB has a test data assignment for: + # variation: test + # runs: 500-2000 + # it has data: [[4,6,8],[10,12,13]] + self.cli.context.current_variation = "test" + self.cli.context.current_run = 600 + self.cli.process_command_line("cat /test/test_vars/test_table") + self.assertIn("13", self.output.getvalue()) + + def test_cat_not_abs_path(self): """In non-interactive mode, cat should handle path without leading / as absolute anyway""" self.cli.process_command_line("cat test/test_vars/test_table")