Move path argument sanitization for commands to a decorator (#4918)

* Move path argument sanitization for commands to a decorator

* Fix tests

* Add `@functools.wraps` to `@sanitize_path_arg` decorator

Co-authored-by: James Collins <collijk@uw.edu>

---------

Co-authored-by: James Collins <collijk@uw.edu>
This commit is contained in:
Reinier van der Leer
2023-07-09 21:40:56 +02:00
committed by GitHub
parent 050c52a008
commit c562fbf4bc
8 changed files with 138 additions and 63 deletions

View File

@@ -1,5 +1,6 @@
import os
import random
import re
import string
import tempfile
@@ -88,13 +89,9 @@ def test_execute_python_file_invalid(agent: Agent):
def test_execute_python_file_not_found(agent: Agent):
assert all(
s in sut.execute_python_file("notexist.py", agent).lower()
for s in [
"python: can't open file 'notexist.py'",
"[errno 2] no such file or directory",
]
)
result = sut.execute_python_file("notexist.py", agent).lower()
assert re.match(r"python: can't open file '([A-Z]:)?[/\\\-\w]*notexist.py'", result)
assert "[errno 2] no such file or directory" in result
def test_execute_shell(random_string: str, agent: Agent):