Move spawner tests into prototypes folder

This commit is contained in:
Griatch 2018-06-09 12:10:32 +02:00
parent 55f8e58c43
commit 7f250cdec4
5 changed files with 43 additions and 48 deletions

View file

@ -174,7 +174,7 @@ def _init():
from .utils import logger
from .utils import gametime
from .utils import ansi
from .utils.spawner import spawn
from .prototypes.spawner import spawn
from . import contrib
from .utils.evmenu import EvMenu
from .utils.evtable import EvTable

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.eveditor import EvEditor
from evennia.utils.evmore import EvMore
from evennia.utils import spawner
from evennia.prototypes import spawner
from evennia.utils.ansi import raw
COMMAND_DEFAULT_CLASS = class_from_module(settings.COMMAND_DEFAULT_CLASS)

View file

@ -15,7 +15,7 @@ from evennia.utils.utils import (
from evennia.locks.lockhandler import validate_lockstring, check_lockstring
from evennia.utils import logger
from evennia.utils.evtable import EvTable
from evennia.utils.prototypes.protfuncs import protfunc_parser
from evennia.prototypes.protfuncs import protfunc_parser
_MODULE_PROTOTYPE_MODULES = {}

View file

@ -129,11 +129,8 @@ import time
from django.conf import settings
import evennia
from random import randint
from evennia.objects.models import ObjectDB
from evennia.utils.utils import (
make_iter, dbid_to_obj,
is_iter, get_all_typeclasses)
from evennia.utils.utils import make_iter, is_iter
from evennia.prototypes import prototypes as protlib
from evennia.prototypes.prototypes import value_to_obj, value_to_obj_or_any, init_spawn_value
@ -516,42 +513,3 @@ def spawn(*prototypes, **kwargs):
alias_string, nattributes, attributes, tags, execs))
return batch_create_object(*objsparams)
# Testing
if __name__ == "__main__":
protparents = {
"NOBODY": {},
# "INFINITE" : {
# "prototype":"INFINITE"
# },
"GOBLIN": {
"key": "goblin grunt",
"health": lambda: randint(20, 30),
"resists": ["cold", "poison"],
"attacks": ["fists"],
"weaknesses": ["fire", "light"]
},
"GOBLIN_WIZARD": {
"prototype": "GOBLIN",
"key": "goblin wizard",
"spells": ["fire ball", "lighting bolt"]
},
"GOBLIN_ARCHER": {
"prototype": "GOBLIN",
"key": "goblin archer",
"attacks": ["short bow"]
},
"ARCHWIZARD": {
"attacks": ["archwizard staff"],
},
"GOBLIN_ARCHWIZARD": {
"key": "goblin archwizard",
"prototype": ("GOBLIN_WIZARD", "ARCHWIZARD")
}
}
# test
print([o.key for o in spawn(protparents["GOBLIN"],
protparents["GOBLIN_ARCHWIZARD"],
prototype_parents=protparents)])

View file

@ -1,10 +1,44 @@
"""
Unit test for the spawner
Unit tests for the prototypes and spawner
"""
from random import randint
from evennia.utils.test_resources import EvenniaTest
from evennia.utils import spawner
from evennia.prototypes import spawner, prototypes as protlib
_PROTPARENTS = {
"NOBODY": {},
"GOBLIN": {
"key": "goblin grunt",
"health": lambda: randint(1, 1),
"resists": ["cold", "poison"],
"attacks": ["fists"],
"weaknesses": ["fire", "light"]
},
"GOBLIN_WIZARD": {
"prototype": "GOBLIN",
"key": "goblin wizard",
"spells": ["fire ball", "lighting bolt"]
},
"GOBLIN_ARCHER": {
"prototype": "GOBLIN",
"key": "goblin archer",
"attacks": ["short bow"]
},
"ARCHWIZARD": {
"attacks": ["archwizard staff"],
},
"GOBLIN_ARCHWIZARD": {
"key": "goblin archwizard",
"prototype": ("GOBLIN_WIZARD", "ARCHWIZARD")
}
}
class TestPrototypes(EvenniaTest):
pass
class TestSpawner(EvenniaTest):
@ -17,6 +51,9 @@ class TestSpawner(EvenniaTest):
obj1 = spawner.spawn(self.prot1)
# check spawned objects have the right tag
self.assertEqual(list(spawner.search_objects_with_prototype("testprototype")), obj1)
self.assertEqual([o.key for o in spawner.spawn(
_PROTPARENTS["GOBLIN"], _PROTPARENTS["GOBLIN_ARCHWIZARD"],
prototype_parents=_PROTPARENTS)], [])
class TestPrototypeStorage(EvenniaTest):