diff --git a/1ano/2semestre/labi/tema02/functional_tests.py b/1ano/2semestre/labi/tema02/functional_tests.py new file mode 100644 index 0000000..8fd6e2a --- /dev/null +++ b/1ano/2semestre/labi/tema02/functional_tests.py @@ -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 " 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")