From 00b6a50927894fab2e73ef86e9464ef7c86019f4 Mon Sep 17 00:00:00 2001 From: Michael Hensley <29671149+ZRexshima@users.noreply.github.com> Date: Sun, 18 Aug 2024 10:45:51 +0900 Subject: [PATCH 1/2] adds a regex check for import of random module or import from random module --- figlet/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/figlet/__init__.py b/figlet/__init__.py index 48d5a2ec..db890c7e 100644 --- a/figlet/__init__.py +++ b/figlet/__init__.py @@ -63,3 +63,17 @@ def check_font_rendering(font, text): for line in lines: output += line check50.run(f"python3 figlet.py -f {font}").stdin(text, prompt=False).stdout(regex(output), output, regex=True).exit(0) + + +@check50.check(exists) +def check_imports_random(exists): + """figlet.py imports random""" + import re + import_regex = re.compile(r'^import random$') + from_regex = re.compile(r'^from random import') + with open('figlet.py') as file: + for line in file.readlines(): + if (match := import_regex.search(line)) or (match := from_regex.search(line)): + return + raise check50.Failure("Random library was not used") + From 7252d8dd0e27cf24ff4493503d85d06dbcc40026 Mon Sep 17 00:00:00 2001 From: Michael Hensley <29671149+ZRexshima@users.noreply.github.com> Date: Sun, 18 Aug 2024 14:30:34 +0900 Subject: [PATCH 2/2] adds test for figlet.py running without arguments --- figlet/__init__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/figlet/__init__.py b/figlet/__init__.py index db890c7e..d8171062 100644 --- a/figlet/__init__.py +++ b/figlet/__init__.py @@ -8,6 +8,15 @@ def exists(): check50.exists("figlet.py") +@check50.check(exists) +def test_no_arguments(): + """figlet.py exits given no command-line arguments""" + text = 'Random text' + exit = check50.run("python3 figlet.py").stdin(text, prompt=False).exit() + if exit != 0: + raise check50.Failure(f"Expected non-zero exit code.") + + @check50.check(exists) def test_one_argument(): """figlet.py exits given one command-line argument""" @@ -76,4 +85,3 @@ def check_imports_random(exists): if (match := import_regex.search(line)) or (match := from_regex.search(line)): return raise check50.Failure("Random library was not used") -