mirror of
https://github.com/evennia/evennia.git
synced 2026-03-31 04:57:16 +02:00
Update unittest for open command
This commit is contained in:
parent
a380419d8c
commit
9984aa63bd
2 changed files with 11 additions and 36 deletions
|
|
@ -1436,37 +1436,6 @@ def _convert_from_string(cmd, strobj):
|
|||
string this will always fail).
|
||||
"""
|
||||
|
||||
def rec_convert(obj):
|
||||
"""
|
||||
Helper function of recursive conversion calls. This is only
|
||||
used for Python <=2.5. After that literal_eval is available.
|
||||
"""
|
||||
# simple types
|
||||
try:
|
||||
return int(obj)
|
||||
except ValueError:
|
||||
# obj cannot be converted to int - that's fine
|
||||
pass
|
||||
try:
|
||||
return float(obj)
|
||||
except ValueError:
|
||||
# obj cannot be converted to float - that's fine
|
||||
pass
|
||||
# iterables
|
||||
if obj.startswith('[') and obj.endswith(']'):
|
||||
"A list. Traverse recursively."
|
||||
return [rec_convert(val) for val in obj[1:-1].split(',')]
|
||||
if obj.startswith('(') and obj.endswith(')'):
|
||||
"A tuple. Traverse recursively."
|
||||
return tuple([rec_convert(val) for val in obj[1:-1].split(',')])
|
||||
if obj.startswith('{') and obj.endswith('}') and ':' in obj:
|
||||
"A dict. Traverse recursively."
|
||||
return dict([(rec_convert(pair.split(":", 1)[0]),
|
||||
rec_convert(pair.split(":", 1)[1]))
|
||||
for pair in obj[1:-1].split(',') if ":" in pair])
|
||||
# if nothing matches, return as-is
|
||||
return obj
|
||||
|
||||
# Use literal_eval to parse python structure exactly.
|
||||
try:
|
||||
return _LITERAL_EVAL(strobj)
|
||||
|
|
@ -1477,10 +1446,9 @@ def _convert_from_string(cmd, strobj):
|
|||
"Make sure this is acceptable." % strobj
|
||||
cmd.caller.msg(string)
|
||||
return strobj
|
||||
else:
|
||||
# fall back to old recursive solution (does not support
|
||||
# nested lists/dicts)
|
||||
return rec_convert(strobj.strip())
|
||||
except Exception as err:
|
||||
string = "|RUnknown error in evaluating Attribute: {}".format(err)
|
||||
return string
|
||||
|
||||
|
||||
class CmdSetAttribute(ObjManipCommand):
|
||||
|
|
|
|||
|
|
@ -442,10 +442,17 @@ class TestBuilding(CommandTest):
|
|||
def test_exit_commands(self):
|
||||
self.call(building.CmdOpen(), "TestExit1=Room2", "Created new Exit 'TestExit1' from Room to Room2")
|
||||
self.call(building.CmdLink(), "TestExit1=Room", "Link created TestExit1 -> Room (one way).")
|
||||
self.call(building.CmdUnLink(), "TestExit1", "Former exit TestExit1 no longer links anywhere.")
|
||||
self.call(building.CmdUnLink(), "", "Usage: ")
|
||||
self.call(building.CmdLink(), "NotFound", "Could not find 'NotFound'.")
|
||||
self.call(building.CmdLink(), "TestExit", "TestExit1 is an exit to Room.")
|
||||
self.call(building.CmdLink(), "Obj", "Obj is not an exit. Its home location is Room.")
|
||||
self.call(building.CmdUnLink(), "TestExit1", "Former exit TestExit1 no longer links anywhere.")
|
||||
|
||||
self.char1.location = self.room2
|
||||
self.call(building.CmdOpen(), "TestExit2=Room", "Created new Exit 'TestExit2' from Room2 to Room.")
|
||||
self.call(building.CmdOpen(), "TestExit2=Room", "Exit TestExit2 already exists. It already points to the correct place.")
|
||||
|
||||
|
||||
# ensure it matches locally first
|
||||
self.call(building.CmdLink(), "TestExit=Room2", "Link created TestExit2 -> Room2 (one way).")
|
||||
self.call(building.CmdLink(), "/twoway TestExit={}".format(self.exit.dbref),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue