Fix unittests
This commit is contained in:
parent
a721889fc1
commit
a4b8b12e63
5 changed files with 128 additions and 60 deletions
|
|
@ -13,7 +13,7 @@ from evennia.objects.models import ObjectDB
|
|||
from evennia.utils.create import create_script
|
||||
from evennia.utils.utils import (
|
||||
all_from_module, make_iter, is_iter, dbid_to_obj, callables_from_module,
|
||||
get_all_typeclasses, to_str)
|
||||
get_all_typeclasses, to_str, dbref)
|
||||
from evennia.locks.lockhandler import validate_lockstring, check_lockstring
|
||||
from evennia.utils import logger
|
||||
from evennia.utils import inlinefuncs
|
||||
|
|
@ -91,6 +91,10 @@ def protfunc_parser(value, available_functions=None, testing=False, stacktrace=F
|
|||
|
||||
"""
|
||||
if not isinstance(value, basestring):
|
||||
try:
|
||||
value = value.dbref
|
||||
except AttributeError:
|
||||
pass
|
||||
value = to_str(value, force_string=True)
|
||||
|
||||
available_functions = _PROT_FUNCS if available_functions is None else available_functions
|
||||
|
|
@ -577,7 +581,7 @@ def validate_prototype(prototype, protkey=None, protparents=None,
|
|||
for protstring in make_iter(prototype_parent):
|
||||
protstring = protstring.lower()
|
||||
if protkey is not None and protstring == protkey:
|
||||
_flags['errors'].append("Protototype {} tries to parent itself.".format(protkey))
|
||||
_flags['errors'].append("Prototype {} tries to parent itself.".format(protkey))
|
||||
protparent = protparents.get(protstring)
|
||||
if not protparent:
|
||||
_flags['errors'].append("Prototype {}'s prototype_parent '{}' was not found.".format(
|
||||
|
|
@ -610,7 +614,7 @@ def validate_prototype(prototype, protkey=None, protparents=None,
|
|||
|
||||
# make sure prototype_locks are set to defaults
|
||||
prototype_locks = [lstring.split(":", 1)
|
||||
for lstring in prototype.get("prototype_locks", "").split(';')]
|
||||
for lstring in prototype.get("prototype_locks", "").split(';') if ":" in lstring]
|
||||
locktypes = [tup[0].strip() for tup in prototype_locks]
|
||||
if "spawn" not in locktypes:
|
||||
prototype_locks.append(("spawn", "all()"))
|
||||
|
|
|
|||
|
|
@ -114,24 +114,41 @@ class TestUtils(EvenniaTest):
|
|||
|
||||
self.assertEqual(
|
||||
pdiff,
|
||||
{'aliases': 'REMOVE',
|
||||
'attrs': 'REPLACE',
|
||||
'home': 'KEEP',
|
||||
'key': 'UPDATE',
|
||||
'location': 'KEEP',
|
||||
'locks': 'KEEP',
|
||||
'new': 'UPDATE',
|
||||
'permissions': 'UPDATE',
|
||||
'prototype_desc': 'UPDATE',
|
||||
'prototype_key': 'UPDATE',
|
||||
'prototype_locks': 'KEEP',
|
||||
'prototype_tags': 'KEEP',
|
||||
'test': 'UPDATE',
|
||||
'typeclass': 'KEEP'})
|
||||
({'aliases': 'REMOVE',
|
||||
'attrs': 'REPLACE',
|
||||
'home': 'KEEP',
|
||||
'key': 'UPDATE',
|
||||
'location': 'KEEP',
|
||||
'locks': 'KEEP',
|
||||
'new': 'UPDATE',
|
||||
'permissions': 'UPDATE',
|
||||
'prototype_desc': 'UPDATE',
|
||||
'prototype_key': 'UPDATE',
|
||||
'prototype_locks': 'KEEP',
|
||||
'prototype_tags': 'KEEP',
|
||||
'test': 'UPDATE',
|
||||
'typeclass': 'KEEP'},
|
||||
{'attrs': [('oldtest', 'to_remove', None, ['']),
|
||||
('test', 'testval', None, [''])],
|
||||
'prototype_locks': 'spawn:all();edit:all()',
|
||||
'prototype_key': Something,
|
||||
'locks': ['call:true()', 'control:perm(Developer)',
|
||||
'delete:perm(Admin)', 'edit:perm(Admin)',
|
||||
'examine:perm(Builder)', 'get:all()',
|
||||
'puppet:pperm(Developer)', 'tell:perm(Admin)',
|
||||
'view:all()'],
|
||||
'prototype_tags': [],
|
||||
'location': self.room1,
|
||||
'key': 'NewObj',
|
||||
'home': self.room1,
|
||||
'typeclass': 'evennia.objects.objects.DefaultObject',
|
||||
'prototype_desc': 'Built from NewObj',
|
||||
'aliases': 'foo'})
|
||||
)
|
||||
|
||||
# apply diff
|
||||
count = spawner.batch_update_objects_with_prototype(
|
||||
old_prot, diff=pdiff, objects=[self.obj1])
|
||||
old_prot, diff=pdiff[0], objects=[self.obj1])
|
||||
self.assertEqual(count, 1)
|
||||
|
||||
new_prot = spawner.prototype_from_object(self.obj1)
|
||||
|
|
@ -470,7 +487,7 @@ class TestOLCMenu(TestEvMenu):
|
|||
menutree = "evennia.prototypes.menus"
|
||||
startnode = "node_index"
|
||||
|
||||
debug_output = True
|
||||
# debug_output = True
|
||||
expect_all_nodes = True
|
||||
|
||||
expected_node_texts = {
|
||||
|
|
@ -480,15 +497,37 @@ class TestOLCMenu(TestEvMenu):
|
|||
expected_tree = \
|
||||
['node_index',
|
||||
['node_prototype_key',
|
||||
['node_index',
|
||||
'node_index',
|
||||
'node_validate_prototype',
|
||||
['node_index'],
|
||||
'node_index'],
|
||||
'node_typeclass',
|
||||
'node_aliases',
|
||||
'node_attrs',
|
||||
'node_tags',
|
||||
'node_locks',
|
||||
'node_permissions',
|
||||
'node_location',
|
||||
'node_home',
|
||||
'node_destination',
|
||||
'node_prototype_desc',
|
||||
'node_prototype_tags',
|
||||
'node_prototype_locks']]
|
||||
['node_key',
|
||||
['node_typeclass',
|
||||
'node_key',
|
||||
'node_index',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype'],
|
||||
'node_index',
|
||||
'node_index',
|
||||
'node_index',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype'],
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype',
|
||||
'node_validate_prototype']]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue