mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 22:06:30 +01:00
Cleaned up the test suite to pass all tests again. Cleaned up the build command's parse() method. Fixed some minor bugs.
This commit is contained in:
parent
1ced5ee8f2
commit
935bef1f43
5 changed files with 51 additions and 84 deletions
|
|
@ -19,20 +19,18 @@ class ObjManipCommand(MuxCommand):
|
|||
some optional data, such as a typeclass or a location. A comma ','
|
||||
separates different objects. Like this:
|
||||
|
||||
name1;alias;alias;alias:option, name2;alias;alias ...
|
||||
name1;alias;alias;alias:option, name2;alias;alias ...
|
||||
|
||||
Spaces between all components are stripped.
|
||||
|
||||
A second situation is attribute manipulation. Such commands
|
||||
are simpler and appear in combinations
|
||||
are simpler and offer combinations
|
||||
|
||||
objname/attr/attr/attr, objname/attr, ...
|
||||
|
||||
Stores four new attributes with the parsed data.
|
||||
|
||||
"""
|
||||
#OBS - this is just a parent - it's not intended to
|
||||
#actually be included in a commandset on its own!
|
||||
# OBS - this is just a parent - it's not intended to actually be
|
||||
# included in a commandset on its own!
|
||||
|
||||
def parse(self):
|
||||
"""
|
||||
|
|
@ -42,65 +40,30 @@ class ObjManipCommand(MuxCommand):
|
|||
# get all the normal parsing done (switches etc)
|
||||
super(ObjManipCommand, self).parse()
|
||||
|
||||
lhs_objs = []
|
||||
rhs_objs = []
|
||||
|
||||
#first, we deal with the left hand side of an eventual =
|
||||
for objdef in self.lhslist:
|
||||
#lhslist is already split by ','
|
||||
aliases, option = [], None
|
||||
if ':' in objdef:
|
||||
objdef, option = [str(part).strip()
|
||||
for part in objdef.rsplit(':', 1)]
|
||||
if ';' in objdef:
|
||||
objdef, aliases = [str(part).strip()
|
||||
for part in objdef.split(';', 1)]
|
||||
aliases = [str(alias).strip()
|
||||
for alias in aliases.split(';') if alias.strip()]
|
||||
lhs_objs.append({"name":objdef,
|
||||
'option': option, 'aliases': aliases})
|
||||
|
||||
#next, the right hand side of =
|
||||
for objdef in self.rhslist:
|
||||
#rhslist is already split by ','
|
||||
aliases, option = [], None
|
||||
if ':' in objdef:
|
||||
objdef, option = [str(part).strip()
|
||||
for part in objdef.rsplit(':', 1)]
|
||||
if ';' in objdef:
|
||||
objdef, aliases = [str(part).strip()
|
||||
for part in objdef.split(';', 1)]
|
||||
aliases = [str(alias).strip()
|
||||
for alias in aliases.split(';') if alias.strip()]
|
||||
rhs_objs.append({"name":objdef, 'option': option, 'aliases': aliases})
|
||||
obj_defs = ([],[]) # stores left- and right-hand side of '='
|
||||
obj_attrs = ([], []) # "
|
||||
|
||||
# We make a second sweep to handle attributes-on-objects
|
||||
lhs_objattr = []
|
||||
rhs_objattr = []
|
||||
|
||||
# first left hand side
|
||||
for objdef in self.lhslist:
|
||||
attrs = []
|
||||
if '/' in objdef:
|
||||
objdef, attrs = [str(part).strip()
|
||||
for part in objdef.split('/', 1)]
|
||||
attrs = [str(part).strip().lower()
|
||||
for part in attrs.split('/') if part.strip()]
|
||||
lhs_objattr.append({"name":objdef, 'attrs':attrs})
|
||||
# right hand side
|
||||
for objdef in self.rhslist:
|
||||
attrs = []
|
||||
if '/' in objdef:
|
||||
objdef, attrs = [str(part).strip()
|
||||
for part in objdef.split('/', 1)]
|
||||
attrs = [str(part).strip().lower()
|
||||
for part in attrs.split('/') if part.strip()]
|
||||
rhs_objattr.append({"name":objdef, 'attrs':attrs})
|
||||
|
||||
self.lhs_objs = lhs_objs
|
||||
self.rhs_objs = rhs_objs
|
||||
self.lhs_objattr = lhs_objattr
|
||||
self.rhs_objattr = rhs_objattr
|
||||
for iside, arglist in enumerate((self.lhslist, self.rhslist)):
|
||||
# lhslist/rhslist is already split by ',' at this point
|
||||
for objdef in arglist:
|
||||
aliases, option, attrs = [], None, []
|
||||
if ':' in objdef:
|
||||
objdef, option = [part.strip() for part in objdef.rsplit(':', 1)]
|
||||
if ';' in objdef:
|
||||
objdef, aliases = [part.strip() for part in objdef.split(';', 1)]
|
||||
aliases = [alias.strip() for alias in aliases.split(';') if alias.strip()]
|
||||
if '/' in objdef:
|
||||
objdef, attrs = [part.strip() for part in objdef.split('/', 1)]
|
||||
attrs = [part.strip().lower() for part in attrs.split('/') if part.strip()]
|
||||
# store data
|
||||
obj_defs[iside].append({"name":objdef, 'option':option, 'aliases':aliases})
|
||||
obj_attrs[iside].append({"name":objdef, 'attrs':attrs})
|
||||
|
||||
# store for future access
|
||||
self.lhs_objs = obj_defs[0]
|
||||
self.rhs_objs = obj_defs[1]
|
||||
self.lhs_objattr = obj_attrs[0]
|
||||
self.rhs_objattr = obj_attrs[1]
|
||||
|
||||
|
||||
class CmdSetObjAlias(MuxCommand):
|
||||
|
|
@ -609,7 +572,7 @@ class CmdDig(ObjManipCommand):
|
|||
new_room.locks.add(lockstring)
|
||||
alias_string = ""
|
||||
if new_room.aliases:
|
||||
alias_string = " (%s)" % ", ".join(new_room_aliases)
|
||||
alias_string = " (%s)" % ", ".join(new_room.aliases)
|
||||
room_string = "Created room %s(%s)%s of type %s." % (new_room, new_room.dbref, alias_string, typeclass)
|
||||
|
||||
exit_to_string = ""
|
||||
|
|
|
|||
|
|
@ -623,21 +623,22 @@ class CmdEncoding(MuxCommand):
|
|||
del caller.player.db.encoding
|
||||
elif not self.args:
|
||||
# just list the encodings supported
|
||||
encodings = []
|
||||
encoding = caller.player.db.encoding
|
||||
string = "Supported encodings "
|
||||
if encoding:
|
||||
encodings.append(encoding)
|
||||
string += "(the first one you can change with {w@encoding <encoding>{n)"
|
||||
encodings.extend(settings.ENCODINGS)
|
||||
string += ":\n " + ", ".join(encodings)
|
||||
pencoding = caller.player.db.encoding
|
||||
string = ""
|
||||
if pencoding:
|
||||
string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
|
||||
encodings = settings.ENCODINGS
|
||||
if encodings:
|
||||
string += "\nServer's alternative encodings (tested in this order):\n {g%s{n" % ", ".join(encodings)
|
||||
if not string:
|
||||
string = "No encodings found."
|
||||
else:
|
||||
# change encoding
|
||||
old_encoding = caller.player.db.encoding
|
||||
encoding = self.args
|
||||
caller.player.db.encoding = encoding
|
||||
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_encoding, encoding)
|
||||
caller.msg(string)
|
||||
caller.msg(string.strip())
|
||||
|
||||
class CmdAccess(MuxCommand):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ class MuxCommand(Command):
|
|||
|
||||
# split out switches
|
||||
switches = []
|
||||
if args and len(args) >1 and args[0] == "/":
|
||||
if args and len(args) > 1 and args[0] == "/":
|
||||
# we have a switch, or a set of switches. These end with a space.
|
||||
#print "'%s'" % args
|
||||
switches = args[1:].split(None, 1)
|
||||
|
|
@ -104,7 +104,7 @@ class MuxCommand(Command):
|
|||
else:
|
||||
args = ""
|
||||
switches = switches[0].split('/')
|
||||
arglist = [arg.strip() for arg in args.split(None)]
|
||||
arglist = [arg.strip() for arg in args.split()]
|
||||
|
||||
# check for arg1, arg2, ... = argA, argB, ... constructs
|
||||
lhs, rhs = args, None
|
||||
|
|
|
|||
|
|
@ -77,9 +77,8 @@ class CommandTest(TestCase):
|
|||
"""
|
||||
def setUp(self):
|
||||
"sets up the testing environment"
|
||||
c = ServerConfig.objects.conf("default_home", 2)
|
||||
c.save()
|
||||
|
||||
ServerConfig.objects.conf("default_home", 2)
|
||||
|
||||
self.room1 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room1")
|
||||
self.room2 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room2")
|
||||
|
||||
|
|
@ -197,8 +196,12 @@ class TestAccess(CommandTest):
|
|||
def test_call(self):
|
||||
self.execute_cmd("access")
|
||||
class TestEncoding(CommandTest):
|
||||
def test_call(self):
|
||||
self.execute_cmd("@encoding", "Supported encodings")
|
||||
def test_call(self):
|
||||
global NOMANGLE
|
||||
NOMANGLE = True
|
||||
self.char1.db.encoding="utf-8"
|
||||
self.execute_cmd("@encoding", "Default encoding:")
|
||||
NOMANGLE = False
|
||||
|
||||
# help.py command tests
|
||||
|
||||
|
|
@ -206,9 +209,9 @@ class TestHelpSystem(CommandTest):
|
|||
def test_call(self):
|
||||
global NOMANGLE
|
||||
NOMANGLE = True
|
||||
sep = "-"*70 + "\n"
|
||||
sep = "-"*78 + "\n"
|
||||
self.execute_cmd("@help/add TestTopic,TestCategory = Test1", )
|
||||
self.execute_cmd("help TestTopic",sep + "Help topic for Testtopic\nTest1")
|
||||
self.execute_cmd("help TestTopic",sep + "Help topic for Testtopic\nTest1" + "\n" + sep)
|
||||
self.execute_cmd("@help/merge TestTopic = Test2", "Added the new text right after")
|
||||
self.execute_cmd("help TestTopic", sep + "Help topic for Testtopic\nTest1 Test2")
|
||||
self.execute_cmd("@help/append TestTopic = Test3", "Added the new text as a")
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class TestObjAttrs(TestCase):
|
|||
self.obj1 = create.create_object(objects.Object, key="testobj1", location=None)
|
||||
self.obj2 = create.create_object(objects.Object, key="testobj2", location=self.obj1)
|
||||
def test_store_str(self):
|
||||
hstring = "sdfv00=97sfjs842 ivfjlQKFos9GF^8dddsöäå-?%"
|
||||
hstring = u"sdfv00=97sfjs842 ivfjlQKFos9GF^8dddsöäå-?%"
|
||||
self.obj1.db.testattr = hstring
|
||||
self.assertEqual(hstring, self.obj1.db.testattr)
|
||||
def test_store_obj(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue