From 202ff708797fe98700eb1f13838fe1036459010d Mon Sep 17 00:00:00 2001 From: Dmitry Romanov Date: Mon, 17 Jun 2024 12:27:34 -0400 Subject: [PATCH] Cat command accepts relative path --- python/ccdb/cmd/commands/cat.py | 11 +++++++---- python/tests/integ_test_cli_manager.py | 5 +++++ python/tests/unit_test_dump_comments.py | 10 ++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/python/ccdb/cmd/commands/cat.py b/python/ccdb/cmd/commands/cat.py index 99f82e4..63dc054 100644 --- a/python/ccdb/cmd/commands/cat.py +++ b/python/ccdb/cmd/commands/cat.py @@ -107,12 +107,15 @@ def get_assignment_by_request(self, request): @param request: Parsed request @type request: ParseRequestResult """ - return self.context.provider.get_assignment_by_request(request) - # ---------------------------------------- - # gets assignment by parsed request - # ---------------------------------------- + # In non-interactive mode, cat should handle path without leading / as absolute anyway + # Check mode and if relative path is given + if not self.context.is_interactive and request.path_is_parsed and not request.path.startswith("/"): + # PatCH the PaTH + request.path = "/" + request.path + # get the assignment from DB + return self.context.provider.get_assignment_by_request(request) # ---------------------------------------- # process_arguments diff --git a/python/tests/integ_test_cli_manager.py b/python/tests/integ_test_cli_manager.py index 449a0f3..869f85f 100644 --- a/python/tests/integ_test_cli_manager.py +++ b/python/tests/integ_test_cli_manager.py @@ -79,6 +79,11 @@ 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_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") + self.assertIn("2.3", self.output.getvalue()) + def test_variation_backup(self): """Test Backup of """ diff --git a/python/tests/unit_test_dump_comments.py b/python/tests/unit_test_dump_comments.py index b3816f7..5c2f49f 100644 --- a/python/tests/unit_test_dump_comments.py +++ b/python/tests/unit_test_dump_comments.py @@ -55,13 +55,19 @@ def setUp(self): raise def tearDown(self): + self.context.process_command_line("vers /test/channel_mc_efficiency") with helper.captured_output() as (out, err): self.context.process_command_line("vers /test/channel_mc_efficiency") text = str(out.getvalue()) line = text.split("\n")[1] assignment_id = int(shlex.split(line)[0]) - self.context.process_command_line("rm -f -a {0}".format(assignment_id)) - self.context.process_command_line("rm -f -t /test/channel_mc_efficiency") + try: + self.context.process_command_line("rm -f -a {0}".format(assignment_id)) + self.context.process_command_line("rm -f -t /test/channel_mc_efficiency") + except Exception as ex: + print("Error removing '/test/channel_mc_efficiency'. It might be OK(!). " + str(ex) + os.linesep) + self.context.process_command_line("vers /test/channel_mc_efficiency") + helper.clean_test_sqlite_db() def test_same_content(self):