Compare commits
2 Commits
13b8cd4b5e
...
14efe02544
| Author | SHA1 | Date | |
|---|---|---|---|
| 14efe02544 | |||
| b644ce5216 |
10
tests/test_limitations.py
Normal file
10
tests/test_limitations.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
from untitled import rules
|
||||||
|
|
||||||
|
|
||||||
|
def test_bad_names():
|
||||||
|
assert rules.validate_cat_name("a")
|
||||||
|
assert rules.validate_cat_name("@nope")
|
||||||
|
assert rules.validate_cat_name("1111")
|
||||||
|
assert rules.validate_cat_name("a111") is None
|
||||||
|
assert rules.validate_cat_name("aaaa") is None
|
||||||
|
assert rules.validate_cat_name("a" * 24) is None
|
||||||
@@ -2,8 +2,25 @@ from untitled import model, persistence
|
|||||||
|
|
||||||
|
|
||||||
def test_save_load_roundtrip(tmp_path):
|
def test_save_load_roundtrip(tmp_path):
|
||||||
original = model.Save(version=1, cat=model.Cat("Mittens"))
|
original = model.Save(
|
||||||
|
version=1,
|
||||||
|
cat=model.Cat(
|
||||||
|
"Fry",
|
||||||
|
{
|
||||||
|
"size": "tiny",
|
||||||
|
"color": "tuxedo",
|
||||||
|
"eyes": "blue",
|
||||||
|
"personality": "judges you silently",
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
persistence.save(original, tmp_path)
|
persistence.save(original, tmp_path)
|
||||||
loaded = persistence.load("Mittens", tmp_path)
|
loaded = persistence.load("Fry", tmp_path)
|
||||||
assert loaded.cat.name == "Mittens"
|
assert loaded.cat.name == "Fry"
|
||||||
|
assert loaded.cat.traits == {
|
||||||
|
"size": "tiny",
|
||||||
|
"color": "tuxedo",
|
||||||
|
"eyes": "blue",
|
||||||
|
"personality": "judges you silently",
|
||||||
|
}
|
||||||
assert loaded.version == 1
|
assert loaded.version == 1
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
class Cat:
|
class Cat:
|
||||||
def __init__(self, name):
|
def __init__(self, name, traits):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.traits = traits
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {"name": self.name}
|
return {"name": self.name, "traits": self.traits}
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_dict(data):
|
def from_dict(data):
|
||||||
return Cat(data["name"])
|
return Cat(data["name"], data["traits"])
|
||||||
|
|
||||||
|
|
||||||
class Save:
|
class Save:
|
||||||
|
|||||||
@@ -7,6 +7,6 @@ def validate_cat_name(name):
|
|||||||
if len(name) < 4 or len(name) > 24:
|
if len(name) < 4 or len(name) > 24:
|
||||||
return "Your cat's name must be 4-24 characters long."
|
return "Your cat's name must be 4-24 characters long."
|
||||||
if not all(c in ALLOWED for c in name):
|
if not all(c in ALLOWED for c in name):
|
||||||
return "Letters and numbers only."
|
return "Your cat's name can only have letters and numbers."
|
||||||
if not any(c in string.ascii_letters for c in name):
|
if not any(c in string.ascii_letters for c in name):
|
||||||
return "Your cat's name needs at least 1 letter."
|
return "Your cat's name needs at least 1 letter."
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
from untitled import generation, ui
|
from untitled import generation, model, rules, ui
|
||||||
|
|
||||||
|
|
||||||
def adoption():
|
def adoption():
|
||||||
print("Welcome to the shelter!")
|
print("Welcome to the shelter!")
|
||||||
name = None
|
|
||||||
while not name:
|
while True:
|
||||||
choice = "Reroll"
|
choice = "Reroll"
|
||||||
while choice == "Reroll":
|
while choice == "Reroll":
|
||||||
choices = generation.generate_cat_choices()
|
choices = generation.generate_cat_choices()
|
||||||
@@ -12,4 +12,16 @@ def adoption():
|
|||||||
"Please choose a cat to adopt:",
|
"Please choose a cat to adopt:",
|
||||||
[ui.Choice(cat[0], cat[1]) for cat in choices] + ["Reroll"],
|
[ui.Choice(cat[0], cat[1]) for cat in choices] + ["Reroll"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
while True:
|
||||||
name = ui.text("Please choose a name for your cat:")
|
name = ui.text("Please choose a name for your cat:")
|
||||||
|
error = rules.validate_cat_name(name)
|
||||||
|
if not error:
|
||||||
|
break
|
||||||
|
print(error)
|
||||||
|
if ui.confirm(
|
||||||
|
f"Do you want to adopt {name}, {generation.generate_trait_sentence(choice).lower()}?"
|
||||||
|
):
|
||||||
|
break
|
||||||
|
|
||||||
|
return model.Cat(name, choice)
|
||||||
|
|||||||
@@ -42,3 +42,7 @@ def select(title, options):
|
|||||||
|
|
||||||
def text(title):
|
def text(title):
|
||||||
return questionary.text(title).ask()
|
return questionary.text(title).ask()
|
||||||
|
|
||||||
|
|
||||||
|
def confirm(title):
|
||||||
|
return questionary.confirm(title).ask()
|
||||||
|
|||||||
Reference in New Issue
Block a user