Advertisement
Kovitikus

Not a dictionary assertion.

Nov 27th, 2020
759
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.69 KB | None | 0 0
  1. """
  2. (evenv) D:\muddev\hecate>evennia test
  3.  
  4.    TESTING: Using Evennia's default settings file (evennia.settings_default).
  5.    (use 'evennia test --settings settings.py .' to run only your custom game tests)
  6.  
  7. Creating test database for alias 'default'...
  8. System check identified no issues (0 silenced).
  9. F.
  10. ======================================================================
  11. FAIL: test_equipment_generation (hecate.world.tests.TestEquipmentHandler)
  12. ----------------------------------------------------------------------
  13. Traceback (most recent call last):
  14.  File "D:\muddev\hecate\world\tests.py", line 23, in test_equipment_generation
  15.    self.assertDictEqual(equip_dic, actual_dic)
  16. AssertionError: {'head': None, 'neck': None, 'shoulders': None, 'chest': None, 'arms': None, 'hands': None, 'fingers': None, 'waist': None, 'thighs': None, 'calves': None, 'feet': None, 'inventory_container': a pristine black bag} is not an instance of <class 'dict'> : Second argument is not a dictionary
  17.  
  18. ----------------------------------------------------------------------
  19. Ran 2 tests in 0.989s
  20.  
  21. FAILED (failures=1)
  22. Destroying test database for alias 'default'...
  23. """
  24.  
  25.  
  26.  
  27.  
  28. # tests.py
  29. class TestEquipmentHandler(EvenniaTest):
  30.     def setUp(self):
  31.         super().setUp()
  32.         self.basic_bag = create.create_object(typeclass='typeclasses.objects.InventoryContainer', key='Basic Bag')
  33.         self.char_test = create.create_object(typeclass='typeclasses.characters.Character', key='Test Char')
  34.    
  35.     def tearDown(self):
  36.         super().tearDown()
  37.         self.basic_bag.delete()
  38.         self.char_test.delete()
  39.  
  40.     def test_equipment_generation(self):
  41.         equip_dic = {'head': None, 'neck': None, 'shoulder': None, 'chest': None, 'arms': None, 'hands': None,
  42.                         'fingers': None, 'waist': None, 'thighs': None, 'calves': None, 'feet': None, 'bag': self.basic_bag}
  43.         actual_dic = self.char_test.attributes.get('equipment')
  44.         self.assertDictEqual(equip_dic, actual_dic)
  45.  
  46.  
  47.  
  48.  
  49.  
  50. # equipment_handler.py
  51. class EquipmentHandler:
  52.     def __init__(self, owner):
  53.         self.owner = owner
  54.  
  55.     def generate_equipment(self):
  56.         owner = self.owner
  57.         if not owner.attributes.has('equipment'):
  58.             basic_bag = spawn('inventory_bag')
  59.             if basic_bag:
  60.                 basic_bag = basic_bag[0]
  61.                 basic_bag.move_to(owner)
  62.                 equip_dic = {'head': None, 'neck': None, 'shoulders': None, 'chest': None, 'arms': None, 'hands': None,
  63.                             'fingers': None, 'waist': None, 'thighs': None, 'calves': None, 'feet': None, 'inventory_container': basic_bag}
  64.                 owner.attributes.add('equipment', equip_dic)
  65.                 owner.db.inventory_slots['max_slots'] = basic_bag.db.max_slots
  66.  
  67.  
  68.  
  69.  
  70.  
  71. # prototypes.py
  72. INVENTORY_CONTAINER = {
  73.     'prototype_key': 'inventory_container',
  74.     'key': 'inventory_container',
  75.     'typeclass': 'typeclasses.objects.InventoryContainer'
  76. }
  77.  
  78.  
  79. INVENTORY_BAG = {
  80.     'prototype_parent': 'inventory_container',
  81.     'key': lambda: generate_random_bag_key()
  82. }
  83.  
  84. def generate_random_bag_key():
  85.     color = ('red', 'blue', 'green', 'yellow', 'black')
  86.     adjective = ('tattered', 'worn', 'pristine', 'well-crafted', 'frayed')
  87.     # a tattered red bag
  88.     # a pristine yellow bag
  89.     bag_key = f"a {random.choice(adjective)} {random.choice(color)} bag"
  90.     return bag_key
  91.  
  92.  
  93.  
  94.  
  95.  
  96. # characters.py
  97. class Character(DefaultCharacter):
  98.  
  99.     @lazy_property
  100.     def combat(self):
  101.         return CombatHandler(self)
  102.        
  103.     @lazy_property
  104.     def equip(self):
  105.         return EquipmentHandler(self)
  106.  
  107.     def at_object_creation(self):
  108.         self.equip.generate_equipment()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement