[LABI] tema02: added functional_tests.py to test fibonacci.py

This commit is contained in:
brunombpereira 2023-05-16 18:43:56 +01:00
parent 61890e9fd2
commit a31b378e2b
Signed by untrusted user who does not match committer: TiagoRG
GPG Key ID: DFCD48E3F420DB42
1 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1,29 @@
import os
import subprocess
def test_invalid_arguments():
result = subprocess.run(["python", "listdir.py", "invalid", "invalid"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
assert result.returncode == 1
assert b"Usage: python listdir.py <directory_path> <ignore_term>" in result.stdout
def test_nonexistent_directory():
result = subprocess.run(["python", "listdir.py", "nonexistent", "invalid"], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
assert result.returncode == 1
assert b"Error: could not list directory." in result.stdout
def test_ignore_term():
with open("test.txt", "w") as f:
f.write("file1\nfile2\nignoreme.txt\n")
result = subprocess.run(["python", "listdir.py", ".", "ignoreme"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
assert result.returncode == 0
assert b"ignoreme.txt" not in result.stdout
assert b"file1\nfile2" in result.stdout
os.remove("test.txt")