Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from evennia.utils.test_resources import EvenniaTest
- from typeclasses.objects import Object
- class Dog(Object):
- def describe(self, looker=None):
- from evennia.utils import list_to_string
- if looker: name = self.get_display_name(looker)
- else: name = self.key
- adjectives = self.tags.get(category='adjectives', return_list=True)
- # Deserialize the adjectives and drop the adjective names
- adjs = tuple(x.split(':')[-1] for x in adjectives)
- return f"{name} is a {list_to_string(adjs)} dog owned by {self.db.owner}."
- class DogTest(EvenniaTest):
- def test_create(self):
- # Account info is optional
- self.account.key = 'Michael Vick'
- michael_vick = self.account
- # Example adjectives
- adjectives = {
- 'size': 'Small',
- 'color': 'Tawny'
- # ... etc ...
- }
- # This will create a dog and store the owner's db id on it, but you
- # could totally omit the account and add the object itself.
- dog, errors = Dog.create('Fido', michael_vick)
- dog.db.owner = michael_vick
- # Add the dog's adjectives as k:v tags in the 'adjectives' category
- for adjective, value in adjectives.items():
- dog.tags.add(f'{adjective}:{value}', category='adjectives')
- print(dog.describe())
- self.assertEqual(dog.describe(), 'Fido is a small and tawny dog owned by Michael Vick(account 1).')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement