Advertisement
Kovitikus

Pazuzu Dog Concept

Jul 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. from evennia.utils.test_resources import EvenniaTest
  2. from typeclasses.objects import Object
  3.  
  4. class Dog(Object):
  5.    
  6.     def describe(self, looker=None):
  7.         from evennia.utils import list_to_string
  8.         if looker: name = self.get_display_name(looker)
  9.         else: name = self.key
  10.        
  11.         adjectives = self.tags.get(category='adjectives', return_list=True)
  12.        
  13.         # Deserialize the adjectives and drop the adjective names
  14.         adjs = tuple(x.split(':')[-1] for x in adjectives)
  15.        
  16.         return f"{name} is a {list_to_string(adjs)} dog owned by {self.db.owner}."
  17.  
  18.  
  19. class DogTest(EvenniaTest):
  20.    
  21.     def test_create(self):
  22.         # Account info is optional
  23.         self.account.key = 'Michael Vick'
  24.         michael_vick = self.account
  25.        
  26.         # Example adjectives
  27.         adjectives = {
  28.             'size': 'Small',
  29.             'color': 'Tawny'
  30.             # ... etc ...
  31.         }
  32.        
  33.         # This will create a dog and store the owner's db id on it, but you
  34.         # could totally omit the account and add the object itself.
  35.         dog, errors = Dog.create('Fido', michael_vick)
  36.         dog.db.owner = michael_vick
  37.        
  38.         # Add the dog's adjectives as k:v tags in the 'adjectives' category
  39.         for adjective, value in adjectives.items():
  40.             dog.tags.add(f'{adjective}:{value}', category='adjectives')
  41.            
  42.         print(dog.describe())
  43.         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