diff --git a/tests/test_generation.py b/tests/test_generation.py index 9945c37..74be68e 100644 --- a/tests/test_generation.py +++ b/tests/test_generation.py @@ -25,8 +25,8 @@ def test_generated_names_pass_filters(): with open(PACKAGE_ROOT / "assets" / "cat_names.txt") as f: for i in f.readlines(): names.append(i.strip()) - name_generator = namegen.NameGenerator(names, rules.validate_cat_name) + name_generator = namegen.NameGenerator(names, rules.validate_auto_gen_cat_name) for _ in range(10000): name = name_generator.generate_name() - assert rules.validate_cat_name(name, auto_gen=True) is None + assert rules.validate_auto_gen_cat_name(name) is None assert any(c in "aeiouy" for c in name.lower()) diff --git a/untitled/namegen.py b/untitled/namegen.py index d75220a..8212608 100644 --- a/untitled/namegen.py +++ b/untitled/namegen.py @@ -35,5 +35,5 @@ class NameGenerator: def generate_name(self): while True: name = self.make_name(self.model) - if self.validate and self.validate(name, auto_gen=True) is None: + if self.validate and self.validate(name) is None: return name diff --git a/untitled/rules.py b/untitled/rules.py index 5890aaf..153cbba 100644 --- a/untitled/rules.py +++ b/untitled/rules.py @@ -3,22 +3,24 @@ import string from untitled import content, model -def validate_cat_name(name, auto_gen=False): +def validate_cat_name(name): ALLOWED = set(string.ascii_letters + string.digits) - if not auto_gen: - if len(name) < 4 or len(name) > 24: - return "Your cat's name must be 4-24 characters long." - else: - if len(name) < 4 or len(name) > 9: - return "Your cat's name must be greater than 3 characters and below 9 characters long." - if not any(c in "aeiou" for c in name.lower()): - return "Your cat's name must contain a vowel." + if len(name) < 4 or len(name) > 24: + return "Your cat's name must be 4-24 characters long." + if not all(c in ALLOWED for c in name): return "Your cat's name can only have letters and numbers." if not any(c in string.ascii_letters for c in name): return "Your cat's name needs at least 1 letter." +def validate_auto_gen_cat_name(name): + if len(name) < 4 or len(name) > 9: + return "Your cat's name must be greater than 3 characters and below 9 characters long." + if not any(c in "aeiou" for c in name.lower()): + return "Your cat's name must contain a vowel." + + def _clamp(value, low=0, high=100): if value < low: return low diff --git a/untitled/screens/adoption.py b/untitled/screens/adoption.py index 1777133..ef68f93 100644 --- a/untitled/screens/adoption.py +++ b/untitled/screens/adoption.py @@ -6,7 +6,7 @@ def adoption(): with open(PACKAGE_ROOT / "assets" / "cat_names.txt") as f: for i in f.readlines(): names.append(i.strip()) - name_generator = namegen.NameGenerator(names, rules.validate_cat_name) + name_generator = namegen.NameGenerator(names, rules.validate_auto_gen_cat_name) print("Welcome to the shelter!") while True: auto_name = ""