Skip to content

Commit

Permalink
Fixed a bug in logger when commands are provided as arrays.
Browse files Browse the repository at this point in the history
For example, logger.log("test", ["echo", "'"]) would not work before this
commit.

Added a unit test to ensure this works.
  • Loading branch information
dc-snl committed Mar 16, 2021
1 parent 7ac0714 commit acd2f8b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,9 @@ def log(self, msg, cmd, cwd=None, live_stdout=False,
for i in range(9))

if isinstance(cmd, list):
cmd_str = ' '.join(str(x) for x in cmd)
cmd_str = ' '.join(
"'" + str(x).replace("'", "'\"'\"'") + "'" for x in cmd
)
else:
cmd_str = str(cmd)

Expand Down
14 changes: 14 additions & 0 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,3 +707,17 @@ def test_append_mode():
assert "FOR REAL" in html_text
assert "111" in html_text

def test_list_commands():
logger = Logger(stack()[0][3], Path.cwd())
cmd = ["echo" "'"]
msg = "Make sure echo \"'\" doesn't hang"

p = Process(target=logger.log, args=(msg, cmd))
p.start()
p.join(1)
assert not p.is_alive()
result = logger.log("Test out commands provided as arrays",
["echo", "'", '"', "(test)"],
return_info=True)
assert result["stdout"] == "' \" (test)\n"

0 comments on commit acd2f8b

Please sign in to comment.