Skip to content

Commit

Permalink
Full path
Browse files Browse the repository at this point in the history
  • Loading branch information
MauroDruwel committed May 18, 2023
1 parent a002924 commit c42c516
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import sys
print(sys.argv[1], sys.argv[2])
14 changes: 10 additions & 4 deletions tests/test_execute_python_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ def test_execute_python_file_with_valid_file(mock_run):
with open(filename, "w") as file:
file.write("print('Hello, world!')")

full_path = os.path.abspath(filename)

mock_run.return_value.returncode = 0
mock_run.return_value.stdout = "Hello, world!"

result = execute_python_file(filename)
result = execute_python_file(full_path)

assert result == "Hello, world!"

Expand All @@ -32,10 +34,12 @@ def test_execute_python_file_with_valid_file_and_args(mock_run):
with open(filename, "w") as file:
file.write("import sys\nprint(sys.argv[1], sys.argv[2])")

full_path = os.path.abspath(filename)

mock_run.return_value.returncode = 0
mock_run.return_value.stdout = "Hello world"

result = execute_python_file(filename, args)
result = execute_python_file(full_path, args)

assert result == "Hello world"

Expand All @@ -45,16 +49,18 @@ def test_execute_python_file_with_valid_file_and_args(mock_run):
def test_execute_python_file_with_invalid_file():
# Test executing a Python file with an invalid file
filename = "invalid.txt"
full_path = os.path.abspath(filename)

result = execute_python_file(filename)
result = execute_python_file(full_path)

assert result == "Error: Invalid file type. Only .py files are allowed."


def test_execute_python_file_with_nonexistent_file():
# Test executing a Python file with a nonexistent file
filename = "nonexistent.py"
full_path = os.path.abspath(filename)

result = execute_python_file(filename)
result = execute_python_file(full_path)

assert result == f"Error: File '{filename}' does not exist."

0 comments on commit c42c516

Please sign in to comment.