Skip to content

Commit

Permalink
add test.py; reorganize all python tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Dec 29, 2024
1 parent 20faf9d commit 63ad291
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions python/test/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import os
import subprocess

def run_tests(directory):
# Get all .py files in the directory, sort them alphabetically, and skip 'template.py'
test_files = sorted(
f for f in os.listdir(directory) if f.endswith(".py") and f != "template.py"
)

# Run each test file
for test_file in test_files:
print(f"Running {test_file}...")
test_path = os.path.join(directory, test_file)
result = subprocess.run(["python3", test_path], capture_output=True, text=True)

# Print the results
print(f"Output of {test_file}:\n{result.stdout}")
if result.returncode != 0:
print(f"Error in {test_file}:\n{result.stderr}")
print("--------------------------------------------------")
print("Test failed.")
return # Stop batch execution if a test fails
else:
print("Test passed!")
print("--------------------------------------------------")

print("All tests completed successfully!")

if __name__ == "__main__":
run_tests("../tutorials")

0 comments on commit 63ad291

Please sign in to comment.