Change tutorial typeclass to Tutorial Readable and TutorialClimbable. Improve error report for failed typeclass import.

This commit is contained in:
Griatch 2019-08-24 16:55:46 +02:00
parent 5755fbdb18
commit 7f3c6dd918
5 changed files with 27 additions and 22 deletions

View file

@ -702,7 +702,7 @@ class DefaultAccount(with_metaclass(TypeclassBase, AccountDB)):
errors.append(string) errors.append(string)
return None, errors return None, errors
# everything's ok. Create the new account account. # everything's ok. Create the new account.
try: try:
try: try:
account = create.create_account(username, email, password, permissions=permissions, typeclass=typeclass) account = create.create_account(username, email, password, permissions=permissions, typeclass=typeclass)

View file

@ -881,13 +881,13 @@ class TestTutorialWorldObjects(TwistedTestCase, CommandTest):
self.assertEqual(obj1.location, obj1.home) self.assertEqual(obj1.location, obj1.home)
def test_readable(self): def test_readable(self):
readable = create_object(tutobjects.Readable, key="book", location=self.room1) readable = create_object(tutobjects.TutorialReadable, key="book", location=self.room1)
readable.db.readable_text = "Text to read" readable.db.readable_text = "Text to read"
self.call(tutobjects.CmdRead(), "book", "You read book:\n Text to read", obj=readable) self.call(tutobjects.CmdRead(), "book", "You read book:\n Text to read", obj=readable)
def test_climbable(self): def test_climbable(self):
climbable = create_object(tutobjects.Climbable, key="tree", location=self.room1) climbable = create_object(tutobjects.TutorialClimbable, key="tree", location=self.room1)
self.call(tutobjects.CmdClimb(), "tree", "You climb tree. Having looked around, you climb down again.", obj=climbable) self.call(tutobjects.CmdClimb(), "tree", "You climb tree. Having looked around, you climb down again.", obj=climbable)
self.assertEqual(self.char1.tags.get("tutorial_climbed_tree", category="tutorial_world"), "tutorial_climbed_tree") self.assertEqual(self.char1.tags.get("tutorial_climbed_tree", category="tutorial_world"), "tutorial_climbed_tree")

View file

@ -265,7 +265,7 @@ start
you get a customized error message when trying to pick it up (that you get a customized error message when trying to pick it up (that
is checked and echoed by the 'get' command). is checked and echoed by the 'get' command).
# #
@create/drop Wooden sign;sign : tutorial_world.objects.Readable @create/drop Wooden sign;sign : tutorial_world.objects.TutorialReadable
# #
@desc sign = @desc sign =
The wooden sign sits at the end of a small eastward path. Beyond it The wooden sign sits at the end of a small eastward path. Beyond it
@ -287,14 +287,14 @@ start
# #
@set sign/tutorial_info = @set sign/tutorial_info =
This is a readable object, of the Typeclass This is a readable object, of the Typeclass
evennia.contrib.tutorial_world.objects.Readable. The sign has a cmdset evennia.contrib.tutorial_world.objects.TutorialReadable. The sign has a cmdset
defined on itself, containing only one command, namely 'read'. This defined on itself, containing only one command, namely 'read'. This
command is what allows you to 'read sign'. Doing so returns the command is what allows you to 'read sign'. Doing so returns the
contents of the Attribute 'readable_sign', containing the information contents of the Attribute 'readable_sign', containing the information
on the sign. on the sign.
# Set a climbable object for discovering a hidden exit # Set a climbable object for discovering a hidden exit
# #
@create/drop gnarled old trees;tree;trees;gnarled : tutorial_world.objects.Climbable @create/drop gnarled old trees;tree;trees;gnarled : tutorial_world.objects.TutorialClimbable
# #
@desc trees = Only the sturdiest of trees survive at the edge of the @desc trees = Only the sturdiest of trees survive at the edge of the
moor. A small group of huddling black things has dug in near the moor. A small group of huddling black things has dug in near the
@ -310,7 +310,7 @@ start
@set trees/tutorial_info = @set trees/tutorial_info =
These are climbable objects; they make for a small puzzle for These are climbable objects; they make for a small puzzle for
accessing a hidden exit. Climbing the trees allows the accessing a hidden exit. Climbing the trees allows the
Climbable typeclass to assign an Attribute on the character TutorialClimbable typeclass to assign an Attribute on the character
that an exit is then looking for. that an exit is then looking for.
# #
# The text to echo to player if trying 'climb tree'. What # The text to echo to player if trying 'climb tree'. What

View file

@ -9,8 +9,8 @@ Objects:
TutorialObject TutorialObject
Readable TutorialReadable
Climbable TutorialClimbable
Obelisk Obelisk
LightSource LightSource
CrumblingWall CrumblingWall
@ -113,7 +113,7 @@ class CmdSetReadable(CmdSet):
self.add(CmdRead()) self.add(CmdRead())
class Readable(TutorialObject): class TutorialReadable(TutorialObject):
""" """
This simple object defines some attributes and This simple object defines some attributes and
""" """
@ -183,7 +183,7 @@ class CmdSetClimbable(CmdSet):
self.add(CmdClimb()) self.add(CmdClimb())
class Climbable(TutorialObject): class TutorialClimbable(TutorialObject):
""" """
A climbable object. All that is special about it is that it has A climbable object. All that is special about it is that it has
the "climb" command available on it. the "climb" command available on it.

View file

@ -17,6 +17,7 @@ import re
import textwrap import textwrap
import random import random
import inspect import inspect
import traceback
from twisted.internet.task import deferLater from twisted.internet.task import deferLater
from twisted.internet.defer import returnValue # noqa - used as import target from twisted.internet.defer import returnValue # noqa - used as import target
from os.path import join as osjoin from os.path import join as osjoin
@ -1453,8 +1454,10 @@ def class_from_module(path, defaultpaths=None):
""" """
cls = None cls = None
err = ""
if defaultpaths: if defaultpaths:
paths = [path] + ["%s.%s" % (dpath, path) for dpath in make_iter(defaultpaths)] if defaultpaths else [] paths = [path] + ["%s.%s" % (dpath, path)
for dpath in make_iter(defaultpaths)] if defaultpaths else []
else: else:
paths = [path] paths = [path]
@ -1473,6 +1476,7 @@ def class_from_module(path, defaultpaths=None):
try: try:
mod = import_module(testpath, package='evennia') mod = import_module(testpath, package='evennia')
except ModuleNotFoundError: except ModuleNotFoundError:
err = traceback.format_exc(30)
break break
try: try:
@ -1481,10 +1485,11 @@ def class_from_module(path, defaultpaths=None):
except AttributeError: except AttributeError:
if len(trace()) > 2: if len(trace()) > 2:
# AttributeError within the module, don't hide it # AttributeError within the module, don't hide it
exc = sys.exc_info() err = traceback.format_exc(30)
raise_(exc[1], None, exc[2]) break
if not cls: if not cls:
err = "Could not load typeclass '%s'" % path err = "\nCould not load typeclass '{}'{}".format(
path, " with the following traceback:\n" + err if err else "")
if defaultpaths: if defaultpaths:
err += "\nPaths searched:\n %s" % "\n ".join(paths) err += "\nPaths searched:\n %s" % "\n ".join(paths)
else: else: