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:
Griatch 2011-04-19 09:52:49 +00:00
parent 1ced5ee8f2
commit 935bef1f43
5 changed files with 51 additions and 84 deletions

View file

@ -19,20 +19,18 @@ class ObjManipCommand(MuxCommand):
some optional data, such as a typeclass or a location. A comma ',' some optional data, such as a typeclass or a location. A comma ','
separates different objects. Like this: 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. Spaces between all components are stripped.
A second situation is attribute manipulation. Such commands 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, ... 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 # OBS - this is just a parent - it's not intended to actually be
#actually be included in a commandset on its own! # included in a commandset on its own!
def parse(self): def parse(self):
""" """
@ -42,65 +40,30 @@ class ObjManipCommand(MuxCommand):
# get all the normal parsing done (switches etc) # get all the normal parsing done (switches etc)
super(ObjManipCommand, self).parse() super(ObjManipCommand, self).parse()
lhs_objs = [] obj_defs = ([],[]) # stores left- and right-hand side of '='
rhs_objs = [] obj_attrs = ([], []) # "
#first, we deal with the left hand side of an eventual = for iside, arglist in enumerate((self.lhslist, self.rhslist)):
for objdef in self.lhslist: # lhslist/rhslist is already split by ',' at this point
#lhslist is already split by ',' for objdef in arglist:
aliases, option = [], None aliases, option, attrs = [], None, []
if ':' in objdef: if ':' in objdef:
objdef, option = [str(part).strip() objdef, option = [part.strip() for part in objdef.rsplit(':', 1)]
for part in objdef.rsplit(':', 1)] if ';' in objdef:
if ';' in objdef: objdef, aliases = [part.strip() for part in objdef.split(';', 1)]
objdef, aliases = [str(part).strip() aliases = [alias.strip() for alias in aliases.split(';') if alias.strip()]
for part in objdef.split(';', 1)] if '/' in objdef:
aliases = [str(alias).strip() objdef, attrs = [part.strip() for part in objdef.split('/', 1)]
for alias in aliases.split(';') if alias.strip()] attrs = [part.strip().lower() for part in attrs.split('/') if part.strip()]
lhs_objs.append({"name":objdef, # store data
'option': option, 'aliases': aliases}) obj_defs[iside].append({"name":objdef, 'option':option, 'aliases':aliases})
obj_attrs[iside].append({"name":objdef, 'attrs':attrs})
#next, the right hand side of = # store for future access
for objdef in self.rhslist: self.lhs_objs = obj_defs[0]
#rhslist is already split by ',' self.rhs_objs = obj_defs[1]
aliases, option = [], None self.lhs_objattr = obj_attrs[0]
if ':' in objdef: self.rhs_objattr = obj_attrs[1]
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})
# 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
class CmdSetObjAlias(MuxCommand): class CmdSetObjAlias(MuxCommand):
@ -609,7 +572,7 @@ class CmdDig(ObjManipCommand):
new_room.locks.add(lockstring) new_room.locks.add(lockstring)
alias_string = "" alias_string = ""
if new_room.aliases: 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) room_string = "Created room %s(%s)%s of type %s." % (new_room, new_room.dbref, alias_string, typeclass)
exit_to_string = "" exit_to_string = ""

View file

@ -623,21 +623,22 @@ class CmdEncoding(MuxCommand):
del caller.player.db.encoding del caller.player.db.encoding
elif not self.args: elif not self.args:
# just list the encodings supported # just list the encodings supported
encodings = [] pencoding = caller.player.db.encoding
encoding = caller.player.db.encoding string = ""
string = "Supported encodings " if pencoding:
if encoding: string += "Default encoding: {g%s{n (change with {w@encoding <encoding>{n)" % pencoding
encodings.append(encoding) encodings = settings.ENCODINGS
string += "(the first one you can change with {w@encoding <encoding>{n)" if encodings:
encodings.extend(settings.ENCODINGS) string += "\nServer's alternative encodings (tested in this order):\n {g%s{n" % ", ".join(encodings)
string += ":\n " + ", ".join(encodings) if not string:
string = "No encodings found."
else: else:
# change encoding # change encoding
old_encoding = caller.player.db.encoding old_encoding = caller.player.db.encoding
encoding = self.args encoding = self.args
caller.player.db.encoding = encoding caller.player.db.encoding = encoding
string = "Your custom text encoding was changed from '%s' to '%s'." % (old_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): class CmdAccess(MuxCommand):
""" """

View file

@ -94,7 +94,7 @@ class MuxCommand(Command):
# split out switches # split out switches
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. # we have a switch, or a set of switches. These end with a space.
#print "'%s'" % args #print "'%s'" % args
switches = args[1:].split(None, 1) switches = args[1:].split(None, 1)
@ -104,7 +104,7 @@ class MuxCommand(Command):
else: else:
args = "" args = ""
switches = switches[0].split('/') 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 # check for arg1, arg2, ... = argA, argB, ... constructs
lhs, rhs = args, None lhs, rhs = args, None

View file

@ -77,8 +77,7 @@ class CommandTest(TestCase):
""" """
def setUp(self): def setUp(self):
"sets up the testing environment" "sets up the testing environment"
c = ServerConfig.objects.conf("default_home", 2) ServerConfig.objects.conf("default_home", 2)
c.save()
self.room1 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room1") self.room1 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room1")
self.room2 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room2") self.room2 = create.create_object(settings.BASE_ROOM_TYPECLASS, key="room2")
@ -198,7 +197,11 @@ class TestAccess(CommandTest):
self.execute_cmd("access") self.execute_cmd("access")
class TestEncoding(CommandTest): class TestEncoding(CommandTest):
def test_call(self): def test_call(self):
self.execute_cmd("@encoding", "Supported encodings") global NOMANGLE
NOMANGLE = True
self.char1.db.encoding="utf-8"
self.execute_cmd("@encoding", "Default encoding:")
NOMANGLE = False
# help.py command tests # help.py command tests
@ -206,9 +209,9 @@ class TestHelpSystem(CommandTest):
def test_call(self): def test_call(self):
global NOMANGLE global NOMANGLE
NOMANGLE = True NOMANGLE = True
sep = "-"*70 + "\n" sep = "-"*78 + "\n"
self.execute_cmd("@help/add TestTopic,TestCategory = Test1", ) 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/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 TestTopic", sep + "Help topic for Testtopic\nTest1 Test2")
self.execute_cmd("@help/append TestTopic = Test3", "Added the new text as a") self.execute_cmd("@help/append TestTopic = Test3", "Added the new text as a")

View file

@ -40,7 +40,7 @@ class TestObjAttrs(TestCase):
self.obj1 = create.create_object(objects.Object, key="testobj1", location=None) self.obj1 = create.create_object(objects.Object, key="testobj1", location=None)
self.obj2 = create.create_object(objects.Object, key="testobj2", location=self.obj1) self.obj2 = create.create_object(objects.Object, key="testobj2", location=self.obj1)
def test_store_str(self): def test_store_str(self):
hstring = "sdfv00=97sfjs842 ivfjlQKFos9GF^8dddsöäå-?%" hstring = u"sdfv00=97sfjs842 ivfjlQKFos9GF^8dddsöäå-?%"
self.obj1.db.testattr = hstring self.obj1.db.testattr = hstring
self.assertEqual(hstring, self.obj1.db.testattr) self.assertEqual(hstring, self.obj1.db.testattr)
def test_store_obj(self): def test_store_obj(self):