Fix unit tests
This commit is contained in:
parent
15f1eaaac0
commit
21f76560b8
5 changed files with 81 additions and 47 deletions
|
|
@ -3330,7 +3330,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
||||||
# handle the search result
|
# handle the search result
|
||||||
err = None
|
err = None
|
||||||
if not prototypes:
|
if not prototypes:
|
||||||
err = f"No prototype named '{prototype_key}'."
|
err = f"No prototype named '{prototype_key}' was found."
|
||||||
elif nprots > 1:
|
elif nprots > 1:
|
||||||
err = "Found {} prototypes matching '{}':\n {}".format(
|
err = "Found {} prototypes matching '{}':\n {}".format(
|
||||||
nprots,
|
nprots,
|
||||||
|
|
@ -3430,7 +3430,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
||||||
if prototypes:
|
if prototypes:
|
||||||
return "\n".join(protlib.prototype_to_str(prot) for prot in prototypes)
|
return "\n".join(protlib.prototype_to_str(prot) for prot in prototypes)
|
||||||
elif query:
|
elif query:
|
||||||
self.caller.msg(f"No prototype found to match the query '{query}'.")
|
self.caller.msg(f"No prototype named '{query}' was found.")
|
||||||
else:
|
else:
|
||||||
self.caller.msg(f"No prototypes found.")
|
self.caller.msg(f"No prototypes found.")
|
||||||
|
|
||||||
|
|
@ -3583,24 +3583,44 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
|
||||||
# store a prototype to the database store
|
# store a prototype to the database store
|
||||||
if not self.args:
|
if not self.args:
|
||||||
caller.msg(
|
caller.msg(
|
||||||
"Usage: spawn/save <key>[;desc[;tag,tag[,...][;lockstring]]] = <prototype_dict>"
|
"Usage: spawn/save [<key>[;desc[;tag,tag[,...][;lockstring]]]] = <prototype_dict>"
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
if self.rhs:
|
||||||
|
# input on the form key = prototype
|
||||||
|
prototype_key, prototype_desc, prototype_tags = self._parse_key_desc_tags(self.lhs)
|
||||||
|
prototype_key = None if not prototype_key else prototype_key
|
||||||
|
prototype_desc = None if not prototype_desc else prototype_desc
|
||||||
|
prototype_tags = None if not prototype_tags else prototype_tags
|
||||||
|
prototype_input = self.rhs.strip()
|
||||||
|
else:
|
||||||
|
prototype_key = prototype_desc = None
|
||||||
|
prototype_tags = None
|
||||||
|
prototype_input = self.lhs.strip()
|
||||||
|
|
||||||
prototype_key, prototype_desc, prototype_tags = self._parse_key_desc_tags(self.lhs)
|
# handle parsing
|
||||||
|
prototype = self._parse_prototype(prototype_input)
|
||||||
# handle rhs:
|
|
||||||
prototype = self._parse_prototype(self.rhs.strip())
|
|
||||||
if not prototype:
|
if not prototype:
|
||||||
return
|
return
|
||||||
|
|
||||||
if prototype.get("prototype_key") != prototype_key:
|
prot_prototype_key = prototype.get("prototype_key")
|
||||||
|
|
||||||
|
if not (prototype_key or prot_prototype_key):
|
||||||
|
caller.msg("A prototype_key must be given, either as `prototype_key = <prototype>` "
|
||||||
|
"or as a key 'prototype_key' inside the prototype structure.")
|
||||||
|
return
|
||||||
|
|
||||||
|
if prototype_key is None:
|
||||||
|
prototype_key = prot_prototype_key
|
||||||
|
|
||||||
|
if prot_prototype_key != prototype_key:
|
||||||
caller.msg("(Replacing `prototype_key` in prototype with given key.)")
|
caller.msg("(Replacing `prototype_key` in prototype with given key.)")
|
||||||
prototype['prototype_key'] = prototype_key
|
prototype['prototype_key'] = prototype_key
|
||||||
if prototype_desc and prototype.get("prototype_desc") != prototype_desc:
|
|
||||||
|
if prototype_desc is not None and prot_prototype_key != prototype_desc:
|
||||||
caller.msg("(Replacing `prototype_desc` in prototype with given desc.)")
|
caller.msg("(Replacing `prototype_desc` in prototype with given desc.)")
|
||||||
prototype['prototype_desc'] = prototype_desc
|
prototype['prototype_desc'] = prototype_desc
|
||||||
if prototype_tags and prototype.get("prototype_tags") != prototype_tags:
|
if prototype_tags is not None and prototype.get("prototype_tags") != prototype_tags:
|
||||||
caller.msg("(Replacing `prototype_tags` in prototype with given tag(s))" )
|
caller.msg("(Replacing `prototype_tags` in prototype with given tag(s))" )
|
||||||
prototype['prototype_tags'] = prototype_tags
|
prototype['prototype_tags'] = prototype_tags
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1228,13 +1228,22 @@ class TestBuilding(CommandTest):
|
||||||
inputs=["y"],
|
inputs=["y"],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.call(
|
||||||
|
building.CmdSpawn(),
|
||||||
|
"/save testprot2 = {'key':'Test Char', "
|
||||||
|
"'typeclass':'evennia.objects.objects.DefaultCharacter'}",
|
||||||
|
"(Replacing `prototype_key` in prototype with given key.)|Saved prototype: testprot2",
|
||||||
|
inputs=["y"],
|
||||||
|
)
|
||||||
|
|
||||||
self.call(building.CmdSpawn(), "/search ", "Key ")
|
self.call(building.CmdSpawn(), "/search ", "Key ")
|
||||||
self.call(building.CmdSpawn(), "/search test;test2", "")
|
self.call(building.CmdSpawn(), "/search test;test2", "")
|
||||||
|
|
||||||
self.call(
|
self.call(
|
||||||
building.CmdSpawn(),
|
building.CmdSpawn(),
|
||||||
"/save {'key':'Test Char', " "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
|
"/save {'key':'Test Char', " "'typeclass':'evennia.objects.objects.DefaultCharacter'}",
|
||||||
"To save a prototype it must have the 'prototype_key' set.",
|
"A prototype_key must be given, either as `prototype_key = <prototype>` or as "
|
||||||
|
"a key 'prototype_key' inside the prototype structure.",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.call(building.CmdSpawn(), "/list", "Key ")
|
self.call(building.CmdSpawn(), "/list", "Key ")
|
||||||
|
|
@ -1312,7 +1321,7 @@ class TestBuilding(CommandTest):
|
||||||
ball.delete()
|
ball.delete()
|
||||||
|
|
||||||
# test calling spawn with an invalid prototype.
|
# test calling spawn with an invalid prototype.
|
||||||
self.call(building.CmdSpawn(), "'NO_EXIST'", "No prototype named 'NO_EXIST'")
|
self.call(building.CmdSpawn(), "'NO_EXIST'", "No prototype named 'NO_EXIST' was found.")
|
||||||
|
|
||||||
# Test listing commands
|
# Test listing commands
|
||||||
self.call(building.CmdSpawn(), "/list", "Key ")
|
self.call(building.CmdSpawn(), "/list", "Key ")
|
||||||
|
|
@ -1343,13 +1352,12 @@ class TestBuilding(CommandTest):
|
||||||
|
|
||||||
# spawn/edit with invalid prototype
|
# spawn/edit with invalid prototype
|
||||||
msg = self.call(
|
msg = self.call(
|
||||||
building.CmdSpawn(), "/edit NO_EXISTS", "No prototype 'NO_EXISTS' was found."
|
building.CmdSpawn(), "/edit NO_EXISTS", "No prototype named 'NO_EXISTS' was found."
|
||||||
)
|
)
|
||||||
|
|
||||||
# spawn/examine (missing prototype)
|
# spawn/examine (missing prototype)
|
||||||
# lists all prototypes that exist
|
# lists all prototypes that exist
|
||||||
msg = self.call(building.CmdSpawn(), "/examine")
|
self.call(building.CmdSpawn(), "/examine", "You need to specify a prototype-key to show.")
|
||||||
assert "testball" in msg and "testprot" in msg
|
|
||||||
|
|
||||||
# spawn/examine with valid prototype
|
# spawn/examine with valid prototype
|
||||||
# prints the prototype
|
# prints the prototype
|
||||||
|
|
@ -1358,7 +1366,7 @@ class TestBuilding(CommandTest):
|
||||||
|
|
||||||
# spawn/examine with invalid prototype
|
# spawn/examine with invalid prototype
|
||||||
# shows error
|
# shows error
|
||||||
self.call(building.CmdSpawn(), "/examine NO_EXISTS", "No prototype 'NO_EXISTS' was found.")
|
self.call(building.CmdSpawn(), "/examine NO_EXISTS", "No prototype named 'NO_EXISTS' was found.")
|
||||||
|
|
||||||
|
|
||||||
class TestComms(CommandTest):
|
class TestComms(CommandTest):
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ PROTOTYPE_TAG_CATEGORY = "from_prototype"
|
||||||
_PROTOTYPE_TAG_META_CATEGORY = "db_prototype"
|
_PROTOTYPE_TAG_META_CATEGORY = "db_prototype"
|
||||||
PROT_FUNCS = {}
|
PROT_FUNCS = {}
|
||||||
|
|
||||||
_PROTOTYPE_FALLBACK_LOCK = "spawn:all();edit:perm(Admin)"
|
_PROTOTYPE_FALLBACK_LOCK = "spawn:all();edit:all()"
|
||||||
|
|
||||||
|
|
||||||
class PermissionError(RuntimeError):
|
class PermissionError(RuntimeError):
|
||||||
|
|
|
||||||
|
|
@ -166,6 +166,18 @@ _PROTOTYPE_ROOT_NAMES = (
|
||||||
_NON_CREATE_KWARGS = _CREATE_OBJECT_KWARGS + _PROTOTYPE_META_NAMES
|
_NON_CREATE_KWARGS = _CREATE_OBJECT_KWARGS + _PROTOTYPE_META_NAMES
|
||||||
|
|
||||||
|
|
||||||
|
class Unset:
|
||||||
|
"""
|
||||||
|
Helper class representing a non-set diff element.
|
||||||
|
|
||||||
|
"""
|
||||||
|
def __bool__(self):
|
||||||
|
return False
|
||||||
|
def __str__(self):
|
||||||
|
return "<Unset>"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Helper
|
# Helper
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -351,12 +363,6 @@ def prototype_diff(prototype1, prototype2, maxdepth=2, homogenize=False, implici
|
||||||
instruction can be one of "REMOVE", "ADD", "UPDATE" or "KEEP".
|
instruction can be one of "REMOVE", "ADD", "UPDATE" or "KEEP".
|
||||||
|
|
||||||
"""
|
"""
|
||||||
class Unset:
|
|
||||||
def __bool__(self):
|
|
||||||
return False
|
|
||||||
def __str__(self):
|
|
||||||
return "<Unset>"
|
|
||||||
|
|
||||||
_unset = Unset()
|
_unset = Unset()
|
||||||
|
|
||||||
def _recursive_diff(old, new, depth=0):
|
def _recursive_diff(old, new, depth=0):
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ from evennia.utils.test_resources import EvenniaTest
|
||||||
from evennia.utils.tests.test_evmenu import TestEvMenu
|
from evennia.utils.tests.test_evmenu import TestEvMenu
|
||||||
from evennia.prototypes import spawner, prototypes as protlib
|
from evennia.prototypes import spawner, prototypes as protlib
|
||||||
from evennia.prototypes import menus as olc_menus
|
from evennia.prototypes import menus as olc_menus
|
||||||
from evennia.prototypes import protfuncs as protofuncs
|
from evennia.prototypes import protfuncs as protofuncs, spawner
|
||||||
|
|
||||||
from evennia.prototypes.prototypes import _PROTOTYPE_TAG_META_CATEGORY
|
from evennia.prototypes.prototypes import _PROTOTYPE_TAG_META_CATEGORY
|
||||||
|
|
||||||
|
|
@ -212,22 +212,21 @@ class TestUtils(EvenniaTest):
|
||||||
"puppet:pperm(Developer);tell:perm(Admin);view:all()",
|
"puppet:pperm(Developer);tell:perm(Admin);view:all()",
|
||||||
"KEEP",
|
"KEEP",
|
||||||
),
|
),
|
||||||
"prototype_tags": {},
|
"prototype_tags": (None, None, 'KEEP'),
|
||||||
"attrs": {
|
"attrs": {
|
||||||
"oldtest": (
|
"oldtest": (
|
||||||
("oldtest", "to_keep", None, ""),
|
("oldtest", "to_keep", None, ""),
|
||||||
("oldtest", "to_keep", None, ""),
|
("oldtest", "to_keep", None, ""),
|
||||||
"KEEP",
|
"KEEP",
|
||||||
),
|
),
|
||||||
"test": (("test", "testval", None, ""), None, "REMOVE"),
|
"desc": (("desc", "changed desc", None, ""), None, "KEEP"),
|
||||||
"desc": (("desc", "changed desc", None, ""), None, "REMOVE"),
|
"fooattr": (Something, ("fooattr", "fooattrval", None, ""), "ADD"),
|
||||||
"fooattr": (None, ("fooattr", "fooattrval", None, ""), "ADD"),
|
|
||||||
"test": (
|
"test": (
|
||||||
("test", "testval", None, ""),
|
("test", "testval", None, ""),
|
||||||
("test", "testval_changed", None, ""),
|
("test", "testval_changed", None, ""),
|
||||||
"UPDATE",
|
"UPDATE",
|
||||||
),
|
),
|
||||||
"new": (None, ("new", "new_val", None, ""), "ADD"),
|
"new": (Something, ("new", "new_val", None, ""), "ADD"),
|
||||||
},
|
},
|
||||||
"key": ("Obj", "Obj", "KEEP"),
|
"key": ("Obj", "Obj", "KEEP"),
|
||||||
"typeclass": (
|
"typeclass": (
|
||||||
|
|
@ -246,7 +245,7 @@ class TestUtils(EvenniaTest):
|
||||||
spawner.flatten_diff(pdiff),
|
spawner.flatten_diff(pdiff),
|
||||||
{
|
{
|
||||||
"aliases": "REMOVE",
|
"aliases": "REMOVE",
|
||||||
"attrs": "REPLACE",
|
"attrs": "UPDATE",
|
||||||
"home": "KEEP",
|
"home": "KEEP",
|
||||||
"key": "KEEP",
|
"key": "KEEP",
|
||||||
"location": "KEEP",
|
"location": "KEEP",
|
||||||
|
|
@ -270,7 +269,9 @@ class TestUtils(EvenniaTest):
|
||||||
new_prot = spawner.prototype_from_object(self.obj1)
|
new_prot = spawner.prototype_from_object(self.obj1)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
{
|
{
|
||||||
|
"aliases": ['foo'],
|
||||||
"attrs": [
|
"attrs": [
|
||||||
|
("desc", "changed desc", None, ""),
|
||||||
("fooattr", "fooattrval", None, ""),
|
("fooattr", "fooattrval", None, ""),
|
||||||
("new", "new_val", None, ""),
|
("new", "new_val", None, ""),
|
||||||
("oldtest", "to_keep", None, ""),
|
("oldtest", "to_keep", None, ""),
|
||||||
|
|
@ -293,6 +294,9 @@ class TestUtils(EvenniaTest):
|
||||||
"view:all()",
|
"view:all()",
|
||||||
]
|
]
|
||||||
),
|
),
|
||||||
|
'tags': [
|
||||||
|
('footag', 'foocategory', None),
|
||||||
|
(Something, 'from_prototype', None)],
|
||||||
"permissions": ["builder"],
|
"permissions": ["builder"],
|
||||||
"prototype_desc": "Built from Obj",
|
"prototype_desc": "Built from Obj",
|
||||||
"prototype_key": Something,
|
"prototype_key": Something,
|
||||||
|
|
@ -912,24 +916,20 @@ class TestMenuModule(EvenniaTest):
|
||||||
|
|
||||||
texts, options = olc_menus._format_diff_text_and_options(obj_diff)
|
texts, options = olc_menus._format_diff_text_and_options(obj_diff)
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
"\n".join(texts),
|
"\n".join(txt.strip() for txt in texts),
|
||||||
"- |wattrs:|n \n"
|
"- |wattrs:|n |c[1] |yADD|n: foo |W=|n bar |W(category:|n None|W, locks:|n |W)|n"
|
||||||
" |gKEEP|W:|n desc |W=|n This is User #1. |W(category:|n None|W, locks:|n |W)|n\n"
|
"\n- |whome:|n"
|
||||||
" |c[1] |yADD|n|W:|n None |W->|n foo |W=|n bar |W(category:|n None|W, locks:|n |W)|n\n"
|
"\n- |wkey:|n"
|
||||||
" |gKEEP|W:|n prelogout_location |W=|n #2 |W(category:|n None|W, locks:|n |W)|n\n"
|
"\n- |wlocks:|n"
|
||||||
"- |whome:|n |gKEEP|W:|n #2\n"
|
"\n- |wpermissions:|n"
|
||||||
"- |wkey:|n |gKEEP|W:|n TestChar\n"
|
"\n- |wprototype_desc:|n |c[2] |rREMOVE|n: Testobject build"
|
||||||
"- |wlocks:|n |gKEEP|W:|n boot:false();call:false();control:perm(Developer);delete:false();edit:false();examine:perm(Developer);get:false();msg:all();puppet:false();tell:perm(Admin);view:all()\n"
|
"\n- |wprototype_key:|n"
|
||||||
"- |wpermissions:|n \n"
|
"\n- |wprototype_locks:|n"
|
||||||
" |gKEEP|W:|n developer\n"
|
"\n- |wprototype_tags:|n"
|
||||||
"- |wprototype_desc:|n |c[2] |rREMOVE|n|W:|n Testobject build |W->|n None\n"
|
"\n- |wtags:|n |c[3] |yADD|n: foo |W(category:|n None|W)|n"
|
||||||
"- |wprototype_key:|n |gKEEP|W:|n TestDiffKey\n"
|
"\n- |wtypeclass:|n"
|
||||||
"- |wprototype_locks:|n |gKEEP|W:|n spawn:all();edit:all()\n"
|
|
||||||
"- |wprototype_tags:|n \n"
|
|
||||||
"- |wtags:|n \n"
|
|
||||||
" |c[3] |yADD|n|W:|n None |W->|n foo |W(category:|n None|W)|n\n"
|
|
||||||
"- |wtypeclass:|n |gKEEP|W:|n typeclasses.characters.Character",
|
|
||||||
)
|
)
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
options,
|
options,
|
||||||
[
|
[
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue