Fix unittests; still missing protfunc tests and menus

This commit is contained in:
Griatch 2018-06-10 21:02:09 +02:00
parent 116f6e7505
commit d47834f28a
5 changed files with 20 additions and 17 deletions

View file

@ -13,7 +13,7 @@ from evennia.utils import create, utils, search
from evennia.utils.utils import inherits_from, class_from_module, get_all_typeclasses from evennia.utils.utils import inherits_from, class_from_module, get_all_typeclasses
from evennia.utils.eveditor import EvEditor from evennia.utils.eveditor import EvEditor
from evennia.utils.evmore import EvMore from evennia.utils.evmore import EvMore
from evennia.prototypes import spawner from evennia.prototypes import spawner, prototypes as protlib
from evennia.utils.ansi import raw from evennia.utils.ansi import raw
COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS) COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS)
@ -2887,7 +2887,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
"use the 'exec' prototype key.") "use the 'exec' prototype key.")
return None return None
try: try:
spawner.validate_prototype(prototype) protlib.validate_prototype(prototype)
except RuntimeError as err: except RuntimeError as err:
self.caller.msg(str(err)) self.caller.msg(str(err))
return return
@ -2929,7 +2929,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
if ';' in self.args: if ';' in self.args:
key, tags = (part.strip().lower() for part in self.args.split(";", 1)) key, tags = (part.strip().lower() for part in self.args.split(";", 1))
tags = [tag.strip() for tag in tags.split(",")] if tags else None tags = [tag.strip() for tag in tags.split(",")] if tags else None
EvMore(caller, unicode(spawner.list_prototypes(caller, key=key, tags=tags)), EvMore(caller, unicode(protlib.list_prototypes(caller, key=key, tags=tags)),
exit_on_lastpage=True) exit_on_lastpage=True)
return return
@ -2947,7 +2947,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
if 'list' in self.switches: if 'list' in self.switches:
# for list, all optional arguments are tags # for list, all optional arguments are tags
EvMore(caller, unicode(spawner.list_prototypes(caller, EvMore(caller, unicode(protlib.list_prototypes(caller,
tags=self.lhslist)), exit_on_lastpage=True) tags=self.lhslist)), exit_on_lastpage=True)
return return
@ -3049,7 +3049,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
return return
if not self.args: if not self.args:
ncount = len(spawner.search_prototype()) ncount = len(protlib.search_prototype())
caller.msg("Usage: @spawn <prototype-key> or {{key: value, ...}}" caller.msg("Usage: @spawn <prototype-key> or {{key: value, ...}}"
"\n ({} existing prototypes. Use /list to inspect)".format(ncount)) "\n ({} existing prototypes. Use /list to inspect)".format(ncount))
return return
@ -3065,7 +3065,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
caller.msg("|rDeletion cancelled.|n") caller.msg("|rDeletion cancelled.|n")
return return
try: try:
success = spawner.delete_db_prototype(caller, self.args) success = protlib.delete_db_prototype(caller, self.args)
except PermissionError as err: except PermissionError as err:
caller.msg("|rError deleting:|R {}|n".format(err)) caller.msg("|rError deleting:|R {}|n".format(err))
caller.msg("Deletion {}.".format( caller.msg("Deletion {}.".format(
@ -3077,7 +3077,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
if 'update' in self.switches: if 'update' in self.switches:
# update existing prototypes # update existing prototypes
key = self.args.strip().lower() key = self.args.strip().lower()
existing_objects = spawner.search_objects_with_prototype(key) existing_objects = protlib.search_objects_with_prototype(key)
if existing_objects: if existing_objects:
n_existing = len(existing_objects) n_existing = len(existing_objects)
slow = " (note that this may be slow)" if n_existing > 10 else "" slow = " (note that this may be slow)" if n_existing > 10 else ""
@ -3103,7 +3103,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
if isinstance(prototype, basestring): if isinstance(prototype, basestring):
# A prototype key we are looking to apply # A prototype key we are looking to apply
key = prototype key = prototype
prototypes = spawner.search_prototype(prototype) prototypes = protlib.search_prototype(prototype)
nprots = len(prototypes) nprots = len(prototypes)
if not prototypes: if not prototypes:
caller.msg("No prototype named '%s'." % prototype) caller.msg("No prototype named '%s'." % prototype)
@ -3115,7 +3115,7 @@ class CmdSpawn(COMMAND_DEFAULT_CLASS):
return return
# we have a prototype, check access # we have a prototype, check access
prototype = prototypes[0] prototype = prototypes[0]
if not caller.locks.check_lockstring(caller, prototype.get('prototype_locks', ''), access_type='use'): if not caller.locks.check_lockstring(caller, prototype.get('prototype_locks', ''), access_type='spawn'):
caller.msg("You don't have access to use this prototype.") caller.msg("You don't have access to use this prototype.")
return return

View file

@ -28,7 +28,7 @@ from evennia.utils import ansi, utils, gametime
from evennia.server.sessionhandler import SESSIONS from evennia.server.sessionhandler import SESSIONS
from evennia import search_object from evennia import search_object
from evennia import DefaultObject, DefaultCharacter from evennia import DefaultObject, DefaultCharacter
from evennia.utils import spawner from evennia.prototypes import spawner, prototypes as protlib
# set up signal here since we are not starting the server # set up signal here since we are not starting the server
@ -389,16 +389,16 @@ class TestBuilding(CommandTest):
spawnLoc = self.room1 spawnLoc = self.room1
self.call(building.CmdSpawn(), self.call(building.CmdSpawn(),
"{'prototype':'GOBLIN', 'key':'goblin', 'location':'%s'}" "{'prototype_key':'GOBLIN', 'key':'goblin', 'location':'%s'}"
% spawnLoc.dbref, "Spawned goblin") % spawnLoc.dbref, "Spawned goblin")
goblin = getObject(self, "goblin") goblin = getObject(self, "goblin")
self.assertEqual(goblin.location, spawnLoc) self.assertEqual(goblin.location, spawnLoc)
goblin.delete() goblin.delete()
spawner.save_db_prototype(self.char1, {'key': 'Ball', 'prototype': 'GOBLIN'}, 'ball') protlib.create_prototype(**{'key': 'Ball', 'prototype': 'GOBLIN', 'prototype_key': 'testball'})
# Tests "@spawn <prototype_name>" # Tests "@spawn <prototype_name>"
self.call(building.CmdSpawn(), "ball", "Spawned Ball") self.call(building.CmdSpawn(), "testball", "Spawned Ball")
ball = getObject(self, "Ball") ball = getObject(self, "Ball")
self.assertEqual(ball.location, self.char1.location) self.assertEqual(ball.location, self.char1.location)
self.assertIsInstance(ball, DefaultObject) self.assertIsInstance(ball, DefaultObject)
@ -414,7 +414,7 @@ class TestBuilding(CommandTest):
# Tests "@spawn/noloc ...", but DO specify a location. # Tests "@spawn/noloc ...", but DO specify a location.
# Location should be the specified location. # Location should be the specified location.
self.call(building.CmdSpawn(), self.call(building.CmdSpawn(),
"/noloc {'prototype':'BALL', 'location':'%s'}" "/noloc {'prototype':'TESTBALL', 'location':'%s'}"
% spawnLoc.dbref, "Spawned Ball") % spawnLoc.dbref, "Spawned Ball")
ball = getObject(self, "Ball") ball = getObject(self, "Ball")
self.assertEqual(ball.location, spawnLoc) self.assertEqual(ball.location, spawnLoc)

View file

@ -24,7 +24,7 @@ import random
from evennia import DefaultObject, DefaultExit, Command, CmdSet from evennia import DefaultObject, DefaultExit, Command, CmdSet
from evennia.utils import search, delay from evennia.utils import search, delay
from evennia.utils.spawner import spawn from evennia.prototypes.spawner import spawn
# ------------------------------------------------------------- # -------------------------------------------------------------
# #

View file

@ -132,13 +132,13 @@ import evennia
from evennia.objects.models import ObjectDB from evennia.objects.models import ObjectDB
from evennia.utils.utils import make_iter, is_iter from evennia.utils.utils import make_iter, is_iter
from evennia.prototypes import prototypes as protlib from evennia.prototypes import prototypes as protlib
from evennia.prototypes.prototypes import value_to_obj, value_to_obj_or_any, init_spawn_value from evennia.prototypes.prototypes import (
value_to_obj, value_to_obj_or_any, init_spawn_value, _PROTOTYPE_TAG_CATEGORY)
_CREATE_OBJECT_KWARGS = ("key", "location", "home", "destination") _CREATE_OBJECT_KWARGS = ("key", "location", "home", "destination")
_PROTOTYPE_META_NAMES = ("prototype_key", "prototype_desc", "prototype_tags", "prototype_locks") _PROTOTYPE_META_NAMES = ("prototype_key", "prototype_desc", "prototype_tags", "prototype_locks")
_NON_CREATE_KWARGS = _CREATE_OBJECT_KWARGS + _PROTOTYPE_META_NAMES _NON_CREATE_KWARGS = _CREATE_OBJECT_KWARGS + _PROTOTYPE_META_NAMES
_PROTOTYPE_TAG_CATEGORY = "spawned_by_prototype"
# Helper # Helper

View file

@ -83,6 +83,7 @@ class TestUtils(EvenniaTest):
'prototype_desc': 'Built from Obj', 'prototype_desc': 'Built from Obj',
'prototype_key': Something, 'prototype_key': Something,
'prototype_locks': 'spawn:all();edit:all()', 'prototype_locks': 'spawn:all();edit:all()',
'prototype_tags': [],
'tags': [(u'foo', None, None)], 'tags': [(u'foo', None, None)],
'typeclass': 'evennia.objects.objects.DefaultObject'}, new_prot) 'typeclass': 'evennia.objects.objects.DefaultObject'}, new_prot)
@ -121,6 +122,7 @@ class TestUtils(EvenniaTest):
'prototype_desc': 'UPDATE', 'prototype_desc': 'UPDATE',
'prototype_key': 'UPDATE', 'prototype_key': 'UPDATE',
'prototype_locks': 'KEEP', 'prototype_locks': 'KEEP',
'prototype_tags': 'KEEP',
'test': 'UPDATE', 'test': 'UPDATE',
'typeclass': 'KEEP'}) 'typeclass': 'KEEP'})
@ -148,6 +150,7 @@ class TestUtils(EvenniaTest):
'prototype_desc': 'Built from Obj', 'prototype_desc': 'Built from Obj',
'prototype_key': Something, 'prototype_key': Something,
'prototype_locks': 'spawn:all();edit:all()', 'prototype_locks': 'spawn:all();edit:all()',
'prototype_tags': [],
'typeclass': 'evennia.objects.objects.DefaultObject'}, 'typeclass': 'evennia.objects.objects.DefaultObject'},
new_prot) new_prot)