Skip to content

Commit

Permalink
Cat command accepts relative path
Browse files Browse the repository at this point in the history
  • Loading branch information
DraTeots committed Jun 17, 2024
1 parent 40786af commit 202ff70
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
11 changes: 7 additions & 4 deletions python/ccdb/cmd/commands/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions python/tests/integ_test_cli_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 """

Expand Down
10 changes: 8 additions & 2 deletions python/tests/unit_test_dump_comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 202ff70

Please sign in to comment.