Format code with black. Add makefile to run fmt/tests

This commit is contained in:
Griatch 2019-09-28 18:18:11 +02:00
parent d00bce9288
commit c2c7fa311a
299 changed files with 19037 additions and 11611 deletions

View file

@ -7,14 +7,6 @@ to provide some named prototypes for use with various tests
prototype dictionaries)
"""
GOBLIN = {
"key" : "Goblin", \
"typeclass" : "DefaultCharacter", \
"desc" : "A goblin."
}
GOBLIN = {"key": "Goblin", "typeclass": "DefaultCharacter", "desc": "A goblin."}
BALL = {
"key" : "Ball", \
"typeclass" : "DefaultObject", \
"desc" : "A ball."
}
BALL = {"key": "Ball", "typeclass": "DefaultObject", "desc": "A ball."}

View file

@ -9,71 +9,70 @@ from evennia.utils import create
class TestCreateScript(EvenniaTest):
def test_create_script(self):
class TestScriptA(DefaultScript):
def at_script_creation(self):
self.key = 'test_script'
self.key = "test_script"
self.interval = 10
self.persistent = False
script = create.create_script(TestScriptA, key='test_script')
script = create.create_script(TestScriptA, key="test_script")
assert script is not None
assert script.interval == 10
assert script.key == 'test_script'
assert script.key == "test_script"
script.stop()
def test_create_script_w_repeats_equal_1(self):
class TestScriptB(DefaultScript):
def at_script_creation(self):
self.key = 'test_script'
self.key = "test_script"
self.interval = 10
self.repeats = 1
self.persistent = False
# script is already stopped (interval=1, start_delay=False)
script = create.create_script(TestScriptB, key='test_script')
script = create.create_script(TestScriptB, key="test_script")
assert script is None
def test_create_script_w_repeats_equal_1_persisted(self):
class TestScriptB1(DefaultScript):
def at_script_creation(self):
self.key = 'test_script'
self.key = "test_script"
self.interval = 10
self.repeats = 1
self.persistent = True
# script is already stopped (interval=1, start_delay=False)
script = create.create_script(TestScriptB1, key='test_script')
script = create.create_script(TestScriptB1, key="test_script")
assert script is None
def test_create_script_w_repeats_equal_2(self):
class TestScriptC(DefaultScript):
def at_script_creation(self):
self.key = 'test_script'
self.key = "test_script"
self.interval = 10
self.repeats = 2
self.persistent = False
script = create.create_script(TestScriptC, key='test_script')
script = create.create_script(TestScriptC, key="test_script")
assert script is not None
assert script.interval == 10
assert script.repeats == 2
assert script.key == 'test_script'
assert script.key == "test_script"
script.stop()
def test_create_script_w_repeats_equal_1_and_delayed(self):
class TestScriptD(DefaultScript):
def at_script_creation(self):
self.key = 'test_script'
self.key = "test_script"
self.interval = 10
self.start_delay = True
self.repeats = 1
self.persistent = False
script = create.create_script(TestScriptD, key='test_script')
script = create.create_script(TestScriptD, key="test_script")
assert script is not None
assert script.interval == 10
assert script.repeats == 1
assert script.key == 'test_script'
assert script.key == "test_script"
script.stop()

View file

@ -10,84 +10,150 @@ from evennia.commands.default.tests import CommandTest
class TestEvEditor(CommandTest):
def test_eveditor_view_cmd(self):
eveditor.EvEditor(self.char1)
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":h",
msg="<txt> - any non-command is appended to the end of the buffer.")
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring=":h",
msg="<txt> - any non-command is appended to the end of the buffer.",
)
# empty buffer
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":",
msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)")
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring=":",
msg="Line Editor []\n01\n[l:01 w:000 c:0000](:h for help)",
)
# input a string
self.call(eveditor.CmdLineInput(), "First test line", raw_string="First test line",
msg="01First test line")
self.call(eveditor.CmdLineInput(), "Second test line", raw_string="Second test line",
msg="02Second test line")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(), 'First test line\nSecond test line')
self.call(
eveditor.CmdLineInput(),
"First test line",
raw_string="First test line",
msg="01First test line",
)
self.call(
eveditor.CmdLineInput(),
"Second test line",
raw_string="Second test line",
msg="02Second test line",
)
self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "First test line\nSecond test line")
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":", # view buffer
msg="Line Editor []\n01First test line\n"
"02Second test line\n[l:02 w:006 c:0032](:h for help)")
self.call(eveditor.CmdEditorGroup(), "", cmdstring="::", # view buffer, no linenums
msg="Line Editor []\nFirst test line\n"
"Second test line\n[l:02 w:006 c:0032](:h for help)")
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":::", # add single : alone on row
msg="Single ':' added to buffer.")
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":",
msg="Line Editor []\n01First test line\n"
"02Second test line\n03:\n[l:03 w:007 c:0034](:h for help)")
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring=":", # view buffer
msg="Line Editor []\n01First test line\n"
"02Second test line\n[l:02 w:006 c:0032](:h for help)",
)
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring="::", # view buffer, no linenums
msg="Line Editor []\nFirst test line\n"
"Second test line\n[l:02 w:006 c:0032](:h for help)",
)
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring=":::", # add single : alone on row
msg="Single ':' added to buffer.",
)
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring=":",
msg="Line Editor []\n01First test line\n"
"02Second test line\n03:\n[l:03 w:007 c:0034](:h for help)",
)
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":dd", # delete line
msg="Deleted line 3.")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(),
'First test line\nSecond test line')
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":u", # undo
msg="Undid one step.")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(),
'First test line\nSecond test line\n:')
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":uu", # redo
msg="Redid one step.")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(),
'First test line\nSecond test line')
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":u", # undo
msg="Undid one step.")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(),
'First test line\nSecond test line\n:')
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":",
msg="Line Editor []\n01First test line\n"
"02Second test line\n03:\n[l:03 w:007 c:0034](:h for help)")
self.call(
eveditor.CmdEditorGroup(), "", cmdstring=":dd", msg="Deleted line 3." # delete line
)
self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "First test line\nSecond test line")
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":u", msg="Undid one step.") # undo
self.assertEqual(
self.char1.ndb._eveditor.get_buffer(), "First test line\nSecond test line\n:"
)
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":uu", msg="Redid one step.") # redo
self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "First test line\nSecond test line")
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":u", msg="Undid one step.") # undo
self.assertEqual(
self.char1.ndb._eveditor.get_buffer(), "First test line\nSecond test line\n:"
)
self.call(
eveditor.CmdEditorGroup(),
"",
cmdstring=":",
msg="Line Editor []\n01First test line\n"
"02Second test line\n03:\n[l:03 w:007 c:0034](:h for help)",
)
self.call(eveditor.CmdEditorGroup(), "Second", cmdstring=":dw", # delete by word
msg="Removed Second for lines 1-4.")
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":u", # undo
msg="Undid one step.")
self.call(eveditor.CmdEditorGroup(), "2 Second", cmdstring=":dw", # delete by word/line
msg="Removed Second for line 2.")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(),
'First test line\n test line\n:')
self.call(
eveditor.CmdEditorGroup(),
"Second",
cmdstring=":dw", # delete by word
msg="Removed Second for lines 1-4.",
)
self.call(eveditor.CmdEditorGroup(), "", cmdstring=":u", msg="Undid one step.") # undo
self.call(
eveditor.CmdEditorGroup(),
"2 Second",
cmdstring=":dw", # delete by word/line
msg="Removed Second for line 2.",
)
self.assertEqual(self.char1.ndb._eveditor.get_buffer(), "First test line\n test line\n:")
self.call(
eveditor.CmdEditorGroup(), "2", cmdstring=":p", msg="Copy buffer is empty." # paste
)
self.call(
eveditor.CmdEditorGroup(),
"2",
cmdstring=":y", # yank
msg="Line 2, [' test line'] yanked.",
)
self.call(
eveditor.CmdEditorGroup(),
"2",
cmdstring=":p", # paste
msg="Pasted buffer [' test line'] to line 2.",
)
self.assertEqual(
self.char1.ndb._eveditor.get_buffer(), "First test line\n test line\n test line\n:"
)
self.call(eveditor.CmdEditorGroup(), "2", cmdstring=":p", # paste
msg="Copy buffer is empty.")
self.call(eveditor.CmdEditorGroup(), "2", cmdstring=":y", # yank
msg="Line 2, [' test line'] yanked.")
self.call(eveditor.CmdEditorGroup(), "2", cmdstring=":p", # paste
msg="Pasted buffer [' test line'] to line 2.")
self.assertEqual(self.char1.ndb._eveditor.get_buffer(),
'First test line\n test line\n test line\n:')
self.call(
eveditor.CmdEditorGroup(), "3", cmdstring=":x", msg="Line 3, [' test line'] cut." # cut
)
self.call(eveditor.CmdEditorGroup(), "3", cmdstring=":x", # cut
msg="Line 3, [' test line'] cut.")
self.call(eveditor.CmdEditorGroup(), "2 New Second line", cmdstring=":i", # insert
msg="Inserted 1 new line(s) at line 2.")
self.call(eveditor.CmdEditorGroup(), "2 New Replaced Second line", # replace
cmdstring=":r", msg="Replaced 1 line(s) at line 2.")
self.call(eveditor.CmdEditorGroup(), "2 Inserted-", # insert beginning line
cmdstring=":I", msg="Inserted text at beginning of line 2.")
self.call(eveditor.CmdEditorGroup(), "2 -End", # append end line
cmdstring=":A", msg="Appended text to end of line 2.")
self.call(
eveditor.CmdEditorGroup(),
"2 New Second line",
cmdstring=":i", # insert
msg="Inserted 1 new line(s) at line 2.",
)
self.call(
eveditor.CmdEditorGroup(),
"2 New Replaced Second line", # replace
cmdstring=":r",
msg="Replaced 1 line(s) at line 2.",
)
self.call(
eveditor.CmdEditorGroup(),
"2 Inserted-", # insert beginning line
cmdstring=":I",
msg="Inserted text at beginning of line 2.",
)
self.call(
eveditor.CmdEditorGroup(),
"2 -End", # append end line
cmdstring=":A",
msg="Appended text to end of line 2.",
)
self.assertEqual(
self.char1.ndb._eveditor.get_buffer(),
'First test line\nInserted-New Replaced Second line-End\n test line\n:')
"First test line\nInserted-New Replaced Second line-End\n test line\n:",
)

View file

@ -14,47 +14,47 @@ class TestEvForm(TestCase):
self.assertEqual(form1, form2)
# self.assertEqual(form1, "")
# '.------------------------------------------------.\n'
# '| |\n'
# '| Name: \x1b[0m\x1b[1m\x1b[32mTom\x1b[1m\x1b[32m \x1b'
# '[1m\x1b[32mthe\x1b[1m\x1b[32m \x1b[0m \x1b[0m '
# 'Account: \x1b[0m\x1b[1m\x1b[33mGriatch '
# '\x1b[0m\x1b[0m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[0m\x1b[0m '
# '|\n'
# '| \x1b[0m\x1b[1m\x1b[32mBouncer\x1b[0m \x1b[0m |\n'
# '| |\n'
# ' >----------------------------------------------< \n'
# '| |\n'
# '| Desc: \x1b[0mA sturdy \x1b[0m \x1b[0m'
# ' STR: \x1b[0m12 \x1b[0m\x1b[0m\x1b[0m\x1b[0m'
# ' DEX: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0mfellow\x1b[0m \x1b[0m'
# ' INT: \x1b[0m5 \x1b[0m\x1b[0m\x1b[0m\x1b[0m'
# ' STA: \x1b[0m18 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0m \x1b[0m'
# ' LUC: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m'
# ' MAG: \x1b[0m3 \x1b[0m\x1b[0m\x1b[0m |\n'
# '| |\n'
# ' >----------.-----------------------------------< \n'
# '| | |\n'
# '| \x1b[0mHP\x1b[0m|\x1b[0mMV \x1b[0m|\x1b[0mMP\x1b[0m '
# '| \x1b[0mSkill \x1b[0m|\x1b[0mValue \x1b[0m'
# '|\x1b[0mExp \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| ~~+~~~+~~ | ~~~~~~~~~~~+~~~~~~~~~~+~~~~~~~~~~~ |\n'
# '| \x1b[0m**\x1b[0m|\x1b[0m***\x1b[0m\x1b[0m|\x1b[0m**\x1b[0m\x1b[0m '
# '| \x1b[0mShooting \x1b[0m|\x1b[0m12 \x1b[0m'
# '|\x1b[0m550/1200 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0m \x1b[0m|\x1b[0m**\x1b[0m \x1b[0m|\x1b[0m*\x1b[0m \x1b[0m '
# '| \x1b[0mHerbalism \x1b[0m|\x1b[0m14 \x1b[0m'
# '|\x1b[0m990/1400 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0m \x1b[0m|\x1b[0m \x1b[0m|\x1b[0m \x1b[0m '
# '| \x1b[0mSmithing \x1b[0m|\x1b[0m9 \x1b[0m'
# '|\x1b[0m205/900 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| | |\n'
# ' -----------`-------------------------------------\n'
# ' Footer: \x1b[0mrev 1 \x1b[0m \n'
# ' info \n'
# ' ')
# '.------------------------------------------------.\n'
# '| |\n'
# '| Name: \x1b[0m\x1b[1m\x1b[32mTom\x1b[1m\x1b[32m \x1b'
# '[1m\x1b[32mthe\x1b[1m\x1b[32m \x1b[0m \x1b[0m '
# 'Account: \x1b[0m\x1b[1m\x1b[33mGriatch '
# '\x1b[0m\x1b[0m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[1m\x1b[32m\x1b[0m\x1b[0m '
# '|\n'
# '| \x1b[0m\x1b[1m\x1b[32mBouncer\x1b[0m \x1b[0m |\n'
# '| |\n'
# ' >----------------------------------------------< \n'
# '| |\n'
# '| Desc: \x1b[0mA sturdy \x1b[0m \x1b[0m'
# ' STR: \x1b[0m12 \x1b[0m\x1b[0m\x1b[0m\x1b[0m'
# ' DEX: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0mfellow\x1b[0m \x1b[0m'
# ' INT: \x1b[0m5 \x1b[0m\x1b[0m\x1b[0m\x1b[0m'
# ' STA: \x1b[0m18 \x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0m \x1b[0m'
# ' LUC: \x1b[0m10 \x1b[0m\x1b[0m\x1b[0m'
# ' MAG: \x1b[0m3 \x1b[0m\x1b[0m\x1b[0m |\n'
# '| |\n'
# ' >----------.-----------------------------------< \n'
# '| | |\n'
# '| \x1b[0mHP\x1b[0m|\x1b[0mMV \x1b[0m|\x1b[0mMP\x1b[0m '
# '| \x1b[0mSkill \x1b[0m|\x1b[0mValue \x1b[0m'
# '|\x1b[0mExp \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| ~~+~~~+~~ | ~~~~~~~~~~~+~~~~~~~~~~+~~~~~~~~~~~ |\n'
# '| \x1b[0m**\x1b[0m|\x1b[0m***\x1b[0m\x1b[0m|\x1b[0m**\x1b[0m\x1b[0m '
# '| \x1b[0mShooting \x1b[0m|\x1b[0m12 \x1b[0m'
# '|\x1b[0m550/1200 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0m \x1b[0m|\x1b[0m**\x1b[0m \x1b[0m|\x1b[0m*\x1b[0m \x1b[0m '
# '| \x1b[0mHerbalism \x1b[0m|\x1b[0m14 \x1b[0m'
# '|\x1b[0m990/1400 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| \x1b[0m \x1b[0m|\x1b[0m \x1b[0m|\x1b[0m \x1b[0m '
# '| \x1b[0mSmithing \x1b[0m|\x1b[0m9 \x1b[0m'
# '|\x1b[0m205/900 \x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m\x1b[0m |\n'
# '| | |\n'
# ' -----------`-------------------------------------\n'
# ' Footer: \x1b[0mrev 1 \x1b[0m \n'
# ' info \n'
# ' ')
def test_ansi_escape(self):
# note that in a msg() call, the result would be the correct |-----,

View file

@ -72,7 +72,7 @@ class TestEvMenu(TestCase):
nodename = menu.nodename
options = menu.test_options
if isinstance(options, dict):
options = (options, )
options = (options,)
# run validation tests for this node
compare_text = self.expected_node_texts.get(nodename, None)
@ -81,24 +81,31 @@ class TestEvMenu(TestCase):
node_text = menu.test_nodetext
self.assertIsNotNone(
bool(node_text),
"node: {}: node-text is None, which was not expected.".format(nodename))
"node: {}: node-text is None, which was not expected.".format(nodename),
)
if isinstance(node_text, tuple):
node_text, helptext = node_text
node_text = ansi.strip_ansi(node_text.strip())
self.assertTrue(
node_text.startswith(compare_text),
"\nnode \"{}\':\nOutput:\n{}\n\nExpected (startswith):\n{}".format(
nodename, node_text, compare_text))
"\nnode \"{}':\nOutput:\n{}\n\nExpected (startswith):\n{}".format(
nodename, node_text, compare_text
),
)
compare_options_count = self.expected_node_options_count.get(nodename, None)
if compare_options_count is not None:
self.assertEqual(
len(options), compare_options_count,
"Not the right number of options returned from node {}.".format(nodename))
len(options),
compare_options_count,
"Not the right number of options returned from node {}.".format(nodename),
)
compare_options = self.expected_node_options.get(nodename, None)
if compare_options:
self.assertEqual(
options, compare_options,
"Options returned from node {} does not match.".format(nodename))
options,
compare_options,
"Options returned from node {} does not match.".format(nodename),
)
self._debug_output(indent, "*{}".format(nodename))
subtree = []
@ -111,8 +118,12 @@ class TestEvMenu(TestCase):
else:
for inum, optdict in enumerate(options):
key, desc, execute, goto = optdict.get("key", ""), optdict.get("desc", None),\
optdict.get("exec", None), optdict.get("goto", None)
key, desc, execute, goto = (
optdict.get("key", ""),
optdict.get("desc", None),
optdict.get("exec", None),
optdict.get("goto", None),
)
# prepare the key to pass to the menu
if isinstance(key, (tuple, list)) and len(key) > 1:
@ -141,10 +152,10 @@ class TestEvMenu(TestCase):
visited.append(nodename)
subtree.append(nodename)
_depth_first(menu, subtree, visited, indent + 2)
#self._debug_output(indent, " -> arrived at {}".format(nodename))
# self._debug_output(indent, " -> arrived at {}".format(nodename))
else:
subtree.append(nodename)
#self._debug_output( indent, " -> arrived at {} (circular call)".format(nodename))
# self._debug_output( indent, " -> arrived at {} (circular call)".format(nodename))
self._debug_output(indent, "-- {} ({}) -> {}".format(key, desc, goto))
if subtree:
@ -175,23 +186,37 @@ class TestEvMenu(TestCase):
self.caller.session = self.session
self.caller2.session = self.session2
self.menu = evmenu.EvMenu(self.caller, self.menutree, startnode=self.startnode,
cmdset_mergetype=self.cmdset_mergetype,
cmdset_priority=self.cmdset_priority,
auto_quit=self.auto_quit, auto_look=self.auto_look,
auto_help=self.auto_help,
cmd_on_exit=self.cmd_on_exit, persistent=False,
startnode_input=self.startnode_input, session=self.session,
**self.kwargs)
self.menu = evmenu.EvMenu(
self.caller,
self.menutree,
startnode=self.startnode,
cmdset_mergetype=self.cmdset_mergetype,
cmdset_priority=self.cmdset_priority,
auto_quit=self.auto_quit,
auto_look=self.auto_look,
auto_help=self.auto_help,
cmd_on_exit=self.cmd_on_exit,
persistent=False,
startnode_input=self.startnode_input,
session=self.session,
**self.kwargs,
)
# persistent version
self.pmenu = evmenu.EvMenu(self.caller2, self.menutree, startnode=self.startnode,
cmdset_mergetype=self.cmdset_mergetype,
cmdset_priority=self.cmdset_priority,
auto_quit=self.auto_quit, auto_look=self.auto_look,
auto_help=self.auto_help,
cmd_on_exit=self.cmd_on_exit, persistent=True,
startnode_input=self.startnode_input, session=self.session2,
**self.kwargs)
self.pmenu = evmenu.EvMenu(
self.caller2,
self.menutree,
startnode=self.startnode,
cmdset_mergetype=self.cmdset_mergetype,
cmdset_priority=self.cmdset_priority,
auto_quit=self.auto_quit,
auto_look=self.auto_look,
auto_help=self.auto_help,
cmd_on_exit=self.cmd_on_exit,
persistent=True,
startnode_input=self.startnode_input,
session=self.session2,
**self.kwargs,
)
self.menu.close_menu = MagicMock()
self.pmenu.close_menu = MagicMock()
@ -209,26 +234,30 @@ class TestEvMenuExample(TestEvMenu):
kwargs = {"testval": "val", "testval2": "val2"}
debug_output = False
expected_node_texts = {
"test_view_node": "Your name is"}
expected_node_texts = {"test_view_node": "Your name is"}
expected_tree = \
['test_start_node',
['test_set_node',
['test_start_node'],
'test_look_node',
['test_start_node'],
'test_view_node',
['test_start_node'],
'test_dynamic_node',
['test_dynamic_node',
'test_dynamic_node',
'test_dynamic_node',
'test_dynamic_node',
'test_start_node'],
'test_end_node',
'test_displayinput_node',
['test_start_node']]]
expected_tree = [
"test_start_node",
[
"test_set_node",
["test_start_node"],
"test_look_node",
["test_start_node"],
"test_view_node",
["test_start_node"],
"test_dynamic_node",
[
"test_dynamic_node",
"test_dynamic_node",
"test_dynamic_node",
"test_dynamic_node",
"test_start_node",
],
"test_end_node",
"test_displayinput_node",
["test_start_node"],
],
]
def test_kwargsave(self):
self.assertTrue(hasattr(self.menu, "testval"))

View file

@ -29,47 +29,64 @@ class ANSIStringTestCase(TestCase):
"""
Make sure the ANSIString is always constructed correctly.
"""
clean = 'This isA|r testTest'
encoded = '\x1b[1m\x1b[32mThis is\x1b[1m\x1b[31mA|r test\x1b[0mTest\x1b[0m'
target = ANSIString(r'|gThis is|rA||r test|nTest|n')
clean = "This isA|r testTest"
encoded = "\x1b[1m\x1b[32mThis is\x1b[1m\x1b[31mA|r test\x1b[0mTest\x1b[0m"
target = ANSIString(r"|gThis is|rA||r test|nTest|n")
char_table = [9, 10, 11, 12, 13, 14, 15, 25, 26, 27, 28, 29, 30, 31, 32, 37, 38, 39, 40]
code_table = [0, 1, 2, 3, 4, 5, 6, 7, 8, 16, 17, 18, 19, 20, 21, 22, 23, 24, 33, 34, 35, 36, 41, 42, 43, 44]
code_table = [
0,
1,
2,
3,
4,
5,
6,
7,
8,
16,
17,
18,
19,
20,
21,
22,
23,
24,
33,
34,
35,
36,
41,
42,
43,
44,
]
self.checker(target, encoded, clean)
self.table_check(target, char_table, code_table)
self.checker(ANSIString(target), encoded, clean)
self.table_check(ANSIString(target), char_table, code_table)
self.checker(ANSIString(encoded, decoded=True), encoded, clean)
self.table_check(ANSIString(encoded, decoded=True), char_table,
code_table)
self.checker(ANSIString('Test'), 'Test', 'Test')
self.table_check(ANSIString('Test'), [0, 1, 2, 3], [])
self.checker(ANSIString(''), '', '')
self.table_check(ANSIString(encoded, decoded=True), char_table, code_table)
self.checker(ANSIString("Test"), "Test", "Test")
self.table_check(ANSIString("Test"), [0, 1, 2, 3], [])
self.checker(ANSIString(""), "", "")
def test_slice(self):
"""
Verifies that slicing an ANSIString results in expected color code
distribution.
"""
target = ANSIString(r'|gTest|rTest|n')
target = ANSIString(r"|gTest|rTest|n")
result = target[:3]
self.checker(result, '\x1b[1m\x1b[32mTes', 'Tes')
self.checker(result, "\x1b[1m\x1b[32mTes", "Tes")
result = target[:4]
self.checker(result, '\x1b[1m\x1b[32mTest\x1b[1m\x1b[31m', 'Test')
self.checker(result, "\x1b[1m\x1b[32mTest\x1b[1m\x1b[31m", "Test")
result = target[:]
self.checker(
result,
'\x1b[1m\x1b[32mTest\x1b[1m\x1b[31mTest\x1b[0m',
'TestTest')
self.checker(result, "\x1b[1m\x1b[32mTest\x1b[1m\x1b[31mTest\x1b[0m", "TestTest")
result = target[:-1]
self.checker(
result,
'\x1b[1m\x1b[32mTest\x1b[1m\x1b[31mTes',
'TestTes')
self.checker(result, "\x1b[1m\x1b[32mTest\x1b[1m\x1b[31mTes", "TestTes")
result = target[0:0]
self.checker(
result,
'',
'')
self.checker(result, "", "")
def test_split(self):
"""
@ -77,11 +94,10 @@ class ANSIStringTestCase(TestCase):
codes end up where they should.
"""
target = ANSIString("|gThis is |nA split string|g")
first = ('\x1b[1m\x1b[32mThis is \x1b[0m', 'This is ')
second = ('\x1b[1m\x1b[32m\x1b[0m split string\x1b[1m\x1b[32m',
' split string')
re_split = re.split('A', target)
normal_split = target.split('A')
first = ("\x1b[1m\x1b[32mThis is \x1b[0m", "This is ")
second = ("\x1b[1m\x1b[32m\x1b[0m split string\x1b[1m\x1b[32m", " split string")
re_split = re.split("A", target)
normal_split = target.split("A")
self.assertEqual(re_split, normal_split)
self.assertEqual(len(normal_split), 2)
self.checker(normal_split[0], *first)
@ -97,27 +113,31 @@ class ANSIStringTestCase(TestCase):
l = [ANSIString("|gTest|r") for _ in range(0, 3)]
# Force the generator to be evaluated.
result = "".join(l)
self.assertEqual(str(result), 'TestTestTest')
self.assertEqual(str(result), "TestTestTest")
result = ANSIString("").join(l)
self.checker(result, '\x1b[1m\x1b[32mTest\x1b[1m\x1b[31m\x1b[1m\x1b'
'[32mTest\x1b[1m\x1b[31m\x1b[1m\x1b[32mTest'
'\x1b[1m\x1b[31m', 'TestTestTest')
self.checker(
result,
"\x1b[1m\x1b[32mTest\x1b[1m\x1b[31m\x1b[1m\x1b"
"[32mTest\x1b[1m\x1b[31m\x1b[1m\x1b[32mTest"
"\x1b[1m\x1b[31m",
"TestTestTest",
)
def test_len(self):
"""
Make sure that length reporting on ANSIStrings does not include
ANSI codes.
"""
self.assertEqual(len(ANSIString('|gTest|n')), 4)
self.assertEqual(len(ANSIString("|gTest|n")), 4)
def test_capitalize(self):
"""
Make sure that capitalization works. This is the simplest of the
_transform functions.
"""
target = ANSIString('|gtest|n')
result = '\x1b[1m\x1b[32mTest\x1b[0m'
self.checker(target.capitalize(), result, 'Test')
target = ANSIString("|gtest|n")
result = "\x1b[1m\x1b[32mTest\x1b[0m"
self.checker(target.capitalize(), result, "Test")
def test_mxp_agnostic(self):
"""
@ -140,8 +160,8 @@ class ANSIStringTestCase(TestCase):
a = ANSIString("|gTest")
b = ANSIString("|cString|n")
c = a + b
result = '\x1b[1m\x1b[32mTest\x1b[1m\x1b[36mString\x1b[0m'
self.checker(c, result, 'TestString')
result = "\x1b[1m\x1b[32mTest\x1b[1m\x1b[36mString\x1b[0m"
self.checker(c, result, "TestString")
char_table = [9, 10, 11, 12, 22, 23, 24, 25, 26, 27]
code_table = [0, 1, 2, 3, 4, 5, 6, 7, 8, 13, 14, 15, 16, 17, 18, 19, 20, 21, 28, 29, 30, 31]
self.table_check(c, char_table, code_table)
@ -166,112 +186,157 @@ class TestTextToHTMLparser(TestCase):
del self.parser
def test_url_scheme_ftp(self):
self.assertEqual(self.parser.convert_urls('ftp.example.com'),
'<a href="ftp.example.com" target="_blank">ftp.example.com</a>')
self.assertEqual(
self.parser.convert_urls("ftp.example.com"),
'<a href="ftp.example.com" target="_blank">ftp.example.com</a>',
)
def test_url_scheme_www(self):
self.assertEqual(self.parser.convert_urls('www.example.com'),
'<a href="www.example.com" target="_blank">www.example.com</a>')
self.assertEqual(
self.parser.convert_urls("www.example.com"),
'<a href="www.example.com" target="_blank">www.example.com</a>',
)
def test_url_scheme_ftpproto(self):
self.assertEqual(self.parser.convert_urls('ftp://ftp.example.com'),
'<a href="ftp://ftp.example.com" target="_blank">ftp://ftp.example.com</a>')
self.assertEqual(
self.parser.convert_urls("ftp://ftp.example.com"),
'<a href="ftp://ftp.example.com" target="_blank">ftp://ftp.example.com</a>',
)
def test_url_scheme_http(self):
self.assertEqual(self.parser.convert_urls('http://example.com'),
'<a href="http://example.com" target="_blank">http://example.com</a>')
self.assertEqual(
self.parser.convert_urls("http://example.com"),
'<a href="http://example.com" target="_blank">http://example.com</a>',
)
def test_url_scheme_https(self):
self.assertEqual(self.parser.convert_urls('https://example.com'),
'<a href="https://example.com" target="_blank">https://example.com</a>')
self.assertEqual(
self.parser.convert_urls("https://example.com"),
'<a href="https://example.com" target="_blank">https://example.com</a>',
)
def test_url_chars_slash(self):
self.assertEqual(self.parser.convert_urls('www.example.com/homedir'),
'<a href="www.example.com/homedir" target="_blank">www.example.com/homedir</a>')
self.assertEqual(
self.parser.convert_urls("www.example.com/homedir"),
'<a href="www.example.com/homedir" target="_blank">www.example.com/homedir</a>',
)
def test_url_chars_colon(self):
self.assertEqual(self.parser.convert_urls('https://example.com:8000/login/'),
'<a href="https://example.com:8000/login/" target="_blank">'
'https://example.com:8000/login/</a>')
self.assertEqual(
self.parser.convert_urls("https://example.com:8000/login/"),
'<a href="https://example.com:8000/login/" target="_blank">'
"https://example.com:8000/login/</a>",
)
def test_url_chars_querystring(self):
self.assertEqual(self.parser.convert_urls('https://example.com/submitform?field1=val1+val3&field2=val2'),
'<a href="https://example.com/submitform?field1=val1+val3&field2=val2" target="_blank">'
'https://example.com/submitform?field1=val1+val3&field2=val2</a>')
self.assertEqual(
self.parser.convert_urls("https://example.com/submitform?field1=val1+val3&field2=val2"),
'<a href="https://example.com/submitform?field1=val1+val3&field2=val2" target="_blank">'
"https://example.com/submitform?field1=val1+val3&field2=val2</a>",
)
def test_url_chars_anchor(self):
self.assertEqual(self.parser.convert_urls('http://www.example.com/menu#section_1'),
'<a href="http://www.example.com/menu#section_1" target="_blank">'
'http://www.example.com/menu#section_1</a>')
self.assertEqual(
self.parser.convert_urls("http://www.example.com/menu#section_1"),
'<a href="http://www.example.com/menu#section_1" target="_blank">'
"http://www.example.com/menu#section_1</a>",
)
def test_url_chars_exclam(self):
self.assertEqual(self.parser.convert_urls('https://groups.google.com/forum/'
'?fromgroups#!categories/evennia/ainneve'),
'<a href="https://groups.google.com/forum/?fromgroups#!categories/evennia/ainneve"'
' target="_blank">https://groups.google.com/forum/?fromgroups#!categories/evennia/ainneve</a>')
self.assertEqual(
self.parser.convert_urls(
"https://groups.google.com/forum/" "?fromgroups#!categories/evennia/ainneve"
),
'<a href="https://groups.google.com/forum/?fromgroups#!categories/evennia/ainneve"'
' target="_blank">https://groups.google.com/forum/?fromgroups#!categories/evennia/ainneve</a>',
)
def test_url_edge_leadingw(self):
self.assertEqual(self.parser.convert_urls('wwww.example.com'),
'w<a href="www.example.com" target="_blank">www.example.com</a>')
self.assertEqual(
self.parser.convert_urls("wwww.example.com"),
'w<a href="www.example.com" target="_blank">www.example.com</a>',
)
def test_url_edge_following_period_eol(self):
self.assertEqual(self.parser.convert_urls('www.example.com.'),
'<a href="www.example.com" target="_blank">www.example.com</a>.')
self.assertEqual(
self.parser.convert_urls("www.example.com."),
'<a href="www.example.com" target="_blank">www.example.com</a>.',
)
def test_url_edge_following_period(self):
self.assertEqual(self.parser.convert_urls('see www.example.com. '),
'see <a href="www.example.com" target="_blank">www.example.com</a>. ')
self.assertEqual(
self.parser.convert_urls("see www.example.com. "),
'see <a href="www.example.com" target="_blank">www.example.com</a>. ',
)
def test_url_edge_brackets(self):
self.assertEqual(self.parser.convert_urls('[http://example.com/]'),
'[<a href="http://example.com/" target="_blank">http://example.com/</a>]')
self.assertEqual(
self.parser.convert_urls("[http://example.com/]"),
'[<a href="http://example.com/" target="_blank">http://example.com/</a>]',
)
def test_url_edge_multiline(self):
self.assertEqual(self.parser.convert_urls(' * http://example.com/info\n * bullet'),
' * <a href="http://example.com/info" target="_blank">'
'http://example.com/info</a>\n * bullet')
self.assertEqual(
self.parser.convert_urls(" * http://example.com/info\n * bullet"),
' * <a href="http://example.com/info" target="_blank">'
"http://example.com/info</a>\n * bullet",
)
def test_url_edge_following_htmlentity(self):
self.assertEqual(self.parser.convert_urls('http://example.com/info&lt;span&gt;'),
'<a href="http://example.com/info" target="_blank">http://example.com/info</a>&lt;span&gt;')
self.assertEqual(
self.parser.convert_urls("http://example.com/info&lt;span&gt;"),
'<a href="http://example.com/info" target="_blank">http://example.com/info</a>&lt;span&gt;',
)
def test_url_edge_surrounded_spans(self):
self.assertEqual(self.parser.convert_urls('</span>http://example.com/<span class="red">'),
'</span><a href="http://example.com/" target="_blank">'
'http://example.com/</a><span class="red">')
self.assertEqual(
self.parser.convert_urls('</span>http://example.com/<span class="red">'),
'</span><a href="http://example.com/" target="_blank">'
'http://example.com/</a><span class="red">',
)
class TestInlineFuncs(TestCase):
"""Test the nested inlinefunc module"""
def test_nofunc(self):
self.assertEqual(inlinefuncs.parse_inlinefunc(
"as$382ewrw w we w werw,|44943}"),
"as$382ewrw w we w werw,|44943}")
self.assertEqual(
inlinefuncs.parse_inlinefunc("as$382ewrw w we w werw,|44943}"),
"as$382ewrw w we w werw,|44943}",
)
def test_incomplete(self):
self.assertEqual(inlinefuncs.parse_inlinefunc(
"testing $blah{without an ending."),
"testing $blah{without an ending.")
self.assertEqual(
inlinefuncs.parse_inlinefunc("testing $blah{without an ending."),
"testing $blah{without an ending.",
)
def test_single_func(self):
self.assertEqual(inlinefuncs.parse_inlinefunc(
"this is a test with $pad(centered, 20) text in it."),
"this is a test with centered text in it.")
self.assertEqual(
inlinefuncs.parse_inlinefunc("this is a test with $pad(centered, 20) text in it."),
"this is a test with centered text in it.",
)
def test_nested(self):
self.assertEqual(inlinefuncs.parse_inlinefunc(
"this $crop(is a test with $pad(padded, 20) text in $pad(pad2, 10) a crop, 80)"),
"this is a test with padded text in pad2 a crop")
self.assertEqual(
inlinefuncs.parse_inlinefunc(
"this $crop(is a test with $pad(padded, 20) text in $pad(pad2, 10) a crop, 80)"
),
"this is a test with padded text in pad2 a crop",
)
def test_escaped(self):
self.assertEqual(inlinefuncs.parse_inlinefunc(
"this should be $pad('''escaped,''' and '''instead,''' cropped $crop(with a long,5) text., 80)"),
"this should be escaped, and instead, cropped with text. ")
self.assertEqual(
inlinefuncs.parse_inlinefunc(
"this should be $pad('''escaped,''' and '''instead,''' cropped $crop(with a long,5) text., 80)"
),
"this should be escaped, and instead, cropped with text. ",
)
def test_escaped2(self):
self.assertEqual(inlinefuncs.parse_inlinefunc(
'this should be $pad("""escaped,""" and """instead,""" cropped $crop(with a long,5) text., 80)'),
"this should be escaped, and instead, cropped with text. ")
self.assertEqual(
inlinefuncs.parse_inlinefunc(
'this should be $pad("""escaped,""" and """instead,""" cropped $crop(with a long,5) text., 80)'
),
"this should be escaped, and instead, cropped with text. ",
)

View file

@ -65,10 +65,12 @@ class TestListToString(TestCase):
"""
def test_list_to_string(self):
self.assertEqual('1, 2, 3', utils.list_to_string([1, 2, 3], endsep=""))
self.assertEqual("1, 2, 3", utils.list_to_string([1, 2, 3], endsep=""))
self.assertEqual('"1", "2", "3"', utils.list_to_string([1, 2, 3], endsep="", addquote=True))
self.assertEqual('1, 2 and 3', utils.list_to_string([1, 2, 3]))
self.assertEqual('"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True))
self.assertEqual("1, 2 and 3", utils.list_to_string([1, 2, 3]))
self.assertEqual(
'"1", "2" and "3"', utils.list_to_string([1, 2, 3], endsep="and", addquote=True)
)
class TestMLen(TestCase):
@ -78,22 +80,22 @@ class TestMLen(TestCase):
"""
def test_non_mxp_string(self):
self.assertEqual(utils.m_len('Test_string'), 11)
self.assertEqual(utils.m_len("Test_string"), 11)
def test_mxp_string(self):
self.assertEqual(utils.m_len('|lclook|ltat|le'), 2)
self.assertEqual(utils.m_len("|lclook|ltat|le"), 2)
def test_mxp_ansi_string(self):
self.assertEqual(utils.m_len(ANSIString('|lcl|gook|ltat|le|n')), 2)
self.assertEqual(utils.m_len(ANSIString("|lcl|gook|ltat|le|n")), 2)
def test_non_mxp_ansi_string(self):
self.assertEqual(utils.m_len(ANSIString('|gHello|n')), 5)
self.assertEqual(utils.m_len(ANSIString("|gHello|n")), 5)
def test_list(self):
self.assertEqual(utils.m_len([None, None]), 2)
def test_dict(self):
self.assertEqual(utils.m_len({'hello': True, 'Goodbye': False}), 2)
self.assertEqual(utils.m_len({"hello": True, "Goodbye": False}), 2)
class TestTimeformat(TestCase):
@ -141,12 +143,9 @@ class TestTimeformat(TestCase):
self.assertEqual(utils.time_format(3600, 2), "1 hour, 0 minutes")
self.assertEqual(utils.time_format(3725, 2), "1 hour, 2 minutes")
self.assertEqual(utils.time_format(86350, 2), "23 hours, 59 minutes")
self.assertEqual(utils.time_format(86800, 2),
"1 day, 0 hours, 6 minutes")
self.assertEqual(utils.time_format(130800, 2),
"1 day, 12 hours, 20 minutes")
self.assertEqual(utils.time_format(530800, 2),
"6 days, 3 hours, 26 minutes")
self.assertEqual(utils.time_format(86800, 2), "1 day, 0 hours, 6 minutes")
self.assertEqual(utils.time_format(130800, 2), "1 day, 12 hours, 20 minutes")
self.assertEqual(utils.time_format(530800, 2), "6 days, 3 hours, 26 minutes")
def test_style_3(self):
"""Test the style 3 of time_format."""
@ -155,18 +154,12 @@ class TestTimeformat(TestCase):
self.assertEqual(utils.time_format(92, 3), "1 minute 32 seconds")
self.assertEqual(utils.time_format(300, 3), "5 minutes 0 seconds")
self.assertEqual(utils.time_format(660, 3), "11 minutes 0 seconds")
self.assertEqual(utils.time_format(3600, 3),
"1 hour, 0 minutes")
self.assertEqual(utils.time_format(3725, 3),
"1 hour, 2 minutes 5 seconds")
self.assertEqual(utils.time_format(86350, 3),
"23 hours, 59 minutes 10 seconds")
self.assertEqual(utils.time_format(86800, 3),
"1 day, 0 hours, 6 minutes 40 seconds")
self.assertEqual(utils.time_format(130800, 3),
"1 day, 12 hours, 20 minutes 0 seconds")
self.assertEqual(utils.time_format(530800, 3),
"6 days, 3 hours, 26 minutes 40 seconds")
self.assertEqual(utils.time_format(3600, 3), "1 hour, 0 minutes")
self.assertEqual(utils.time_format(3725, 3), "1 hour, 2 minutes 5 seconds")
self.assertEqual(utils.time_format(86350, 3), "23 hours, 59 minutes 10 seconds")
self.assertEqual(utils.time_format(86800, 3), "1 day, 0 hours, 6 minutes 40 seconds")
self.assertEqual(utils.time_format(130800, 3), "1 day, 12 hours, 20 minutes 0 seconds")
self.assertEqual(utils.time_format(530800, 3), "6 days, 3 hours, 26 minutes 40 seconds")
def test_style_4(self):
"""Test the style 4 of time_format."""
@ -192,10 +185,11 @@ class TestTimeformat(TestCase):
self.assertRaises(ValueError, utils.time_format, 0, "u")
@mock.patch("evennia.utils.utils.timezone.now",
new=mock.MagicMock(return_value=datetime(2019, 8, 28, 21, 56)))
@mock.patch(
"evennia.utils.utils.timezone.now",
new=mock.MagicMock(return_value=datetime(2019, 8, 28, 21, 56)),
)
class TestDateTimeFormat(TestCase):
def test_datetimes(self):
dtobj = datetime(2017, 7, 26, 22, 54)
self.assertEqual(utils.datetime_format(dtobj), "Jul 26, 2017")
@ -213,19 +207,19 @@ class TestImportFunctions(TestCase):
return os.path.join(testdir, filename)
def test_mod_import(self):
loaded_mod = utils.mod_import('evennia.utils.ansi')
loaded_mod = utils.mod_import("evennia.utils.ansi")
self.assertIsNotNone(loaded_mod)
def test_mod_import_invalid(self):
loaded_mod = utils.mod_import('evennia.utils.invalid_module')
loaded_mod = utils.mod_import("evennia.utils.invalid_module")
self.assertIsNone(loaded_mod)
def test_mod_import_from_path(self):
test_path = self._t_dir_file('test_eveditor.py')
test_path = self._t_dir_file("test_eveditor.py")
loaded_mod = utils.mod_import_from_path(test_path)
self.assertIsNotNone(loaded_mod)
def test_mod_import_from_path_invalid(self):
test_path = self._t_dir_file('invalid_filename.py')
test_path = self._t_dir_file("invalid_filename.py")
loaded_mod = utils.mod_import_from_path(test_path)
self.assertIsNone(loaded_mod)