From a3df5126a9d115b66b6cb4668b01dc9683665279 Mon Sep 17 00:00:00 2001 From: brunombpereira Date: Tue, 16 May 2023 18:43:56 +0100 Subject: [PATCH] [LABI] tema02: added functional_tests.py to test fibonacci.py --- .../2semestre/labi/tema02/functional_tests.py | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 1ano/2semestre/labi/tema02/functional_tests.py 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")