evennia.commands.default.tests

This is part of the Evennia unittest framework, for testing the stability and integrity of the codebase during updates. This module test the default command set. It is instantiated by the evennia/objects/tests.py module, which in turn is run by as part of the main test suite started with

> python game/manage.py test.

class evennia.commands.default.tests.CommandTest(methodName='runTest')[source]

Bases: evennia.utils.test_resources.EvenniaTest

Tests a Command by running it and comparing what messages it sends with expected values. This tests without actually spinning up the cmdhandler for every test, which is more controlled.

Example:

from commands.echo import CmdEcho

class MyCommandTest(CommandTest):

    def test_echo(self):
        '''
        Test that the echo command really returns
        what you pass into it.
        '''
        self.call(MyCommand(), "hello world!",
                  "You hear your echo: 'Hello world!'")
call(cmdobj, input_args, msg=None, cmdset=None, noansi=True, caller=None, receiver=None, cmdstring=None, obj=None, inputs=None, raw_string=None)[source]

Test a command by assigning all the needed properties to a cmdobj and running the sequence. The resulting .msg calls will be mocked and the text= calls to them compared to a expected output.

Parameters
  • cmdobj (Command) – The command object to use.

  • input_args (str) – This should be the full input the Command should see, such as ‘look here’. This will become .args for the Command instance to parse.

  • msg (str or dict, optional) – This is the expected return value(s) returned through caller.msg(text=…) calls in the command. If a string, the receiver is controlled with the receiver kwarg (defaults to caller). If this is a dict, it is a mapping {receiver1: “expected1”, receiver2: “expected2”,…} and receiver is ignored. The message(s) are compared with the actual messages returned to the receiver(s) as the Command runs. Each check uses .startswith, so you can choose to only include the first part of the returned message if that’s enough to verify a correct result. EvMenu decorations (like borders) are stripped and should not be included. This should also not include color tags unless noansi=False. If the command returns texts in multiple separate .msg- calls to a receiver, separate these with | if noansi=True (default) and || if noansi=False. If no msg is given (None), then no automatic comparison will be done.

  • cmdset (str, optional) – If given, make .cmdset available on the Command instance as it runs. While .cmdset is normally available on the Command instance by default, this is usually only used by commands that explicitly operates/displays cmdsets, like examine.

  • noansi (str, optional) – By default the color tags of the msg is ignored, this makes them significant. If unset, msg must contain the same color tags as the actual return message.

  • caller (Object or Account, optional) – By default self.char1 is used as the command-caller (the .caller property on the Command). This allows to execute with another caller, most commonly an Account.

  • receiver (Object or Account, optional) – This is the object to receive the return messages we want to test. By default this is the same as caller (which in turn defaults to is self.char1). Note that if msg is a dict, this is ignored since the receiver is already specified there.

  • cmdstring (str, optional) – Normally this is the Command’s key. This allows for tweaking the .cmdname property of the Command**. This isb used for commands with multiple aliases, where the command explicitly checs which alias was used to determine its functionality.

  • obj (str, optional) – This sets the .obj property of the Command - the object on which the Command ‘sits’. By default this is the same as caller. This can be used for testing on-object Command interactions.

  • inputs (list, optional) – A list of strings to pass to functions that pause to take input from the user (normally using @interactive and ret = yield(question) or evmenu.get_input). Each element of the list will be passed into the command as if the user wrote that at the prompt.

  • raw_string (str, optional) – Normally the .raw_string property is set as a combination of your key/cmdname and input_args. This allows direct control of what this is, for example for testing edge cases or malformed inputs.

Returns

str or dict

The message sent to receiver, or a dict of

{receiver: “msg”, …} if multiple are given. This is usually only used with msg=None to do the validation externally.

Raises

AssertionError – If the returns of .msg calls (tested with .startswith) does not match expected_input.

Notes

As part of the tests, all methods of the Command will be called in the proper order:

  • cmdobj.at_pre_cmd()

  • cmdobj.parse()

  • cmdobj.func()

  • cmdobj.at_post_cmd()

class evennia.commands.default.tests.TestGeneral(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_look()[source]
test_home()[source]
test_inventory()[source]
test_pose()[source]
test_nick()[source]
test_get_and_drop()[source]
test_give()[source]
test_mux_command()[source]
test_say()[source]
test_whisper()[source]
test_access()[source]
class evennia.commands.default.tests.TestHelp(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

maxDiff = None
setUp()[source]

Sets up testing environment

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_help()[source]
test_set_help()[source]
test_subtopic_fetch = None
test_subtopic_fetch_00_test()

Check retrieval of subtopics [with helparg=’test’, expected=’Help for testnnMain help text… test/something else test/more’].

test_subtopic_fetch_01_test_creating_extra_stuff()

Check retrieval of subtopics [with helparg=’test/creating extra stuff’, expected=’Help for test/creating extra st…ating extra stuff/subsubtopicn’].

test_subtopic_fetch_02_test_creating()

Check retrieval of subtopics [with helparg=’test/creating’, expected=’Help for test/creating extra st…ating extra stuff/subsubtopicn’].

test_subtopic_fetch_03_test_extra()

Check retrieval of subtopics [with helparg=’test/extra’, expected=’Help for test/creating extra st…ating extra stuff/subsubtopicn’].

test_subtopic_fetch_04_test_extra_subsubtopic()

Check retrieval of subtopics [with helparg=’test/extra/subsubtopic’, expected=’Help for test/creating extra st…bsubtopicnnA subsubtopic text’].

test_subtopic_fetch_05_test_creating_extra_subsub()

Check retrieval of subtopics [with helparg=’test/creating extra/subsub’, expected=’Help for test/creating extra st…bsubtopicnnA subsubtopic text’].

test_subtopic_fetch_06_test_Something_else()

Check retrieval of subtopics [with helparg=’test/Something else’, expected=’Help for test/something elsennSomething else’].

test_subtopic_fetch_07_test_More()

Check retrieval of subtopics [with helparg=’test/More’, expected=’Help for test/morennAnother t…opics:n test/more/second-more’].

test_subtopic_fetch_08_test_More_Second_more()

Check retrieval of subtopics [with helparg=’test/More/Second-more’, expected=’Help for test/more/second-more...est/more/second-more/third more’].

test_subtopic_fetch_09_test_More_more()

Check retrieval of subtopics [with helparg=’test/More/-more’, expected=’Help for test/more/second-more...est/more/second-more/third more’].

test_subtopic_fetch_10_test_more_second_more_again()

Check retrieval of subtopics [with helparg=’test/more/second/more again’, expected=’Help for test/more/second-more/more againnnEven more text.n’].

test_subtopic_fetch_11_test_more_second_third()

Check retrieval of subtopics [with helparg=’test/more/second/third’, expected=’Help for test/more/second-more/third morennThird more textn’].

class evennia.commands.default.tests.TestSystem(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_py()[source]
test_scripts()[source]
test_objects()[source]
test_about()[source]
test_server_load()[source]
evennia.commands.default.tests.func_test_cmd_tasks()[source]
class evennia.commands.default.tests.TestCmdTasks(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

setUp()[source]

Sets up testing environment

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_no_tasks()[source]
test_active_task()[source]
test_persistent_task()[source]
test_pause_unpause()[source]
test_do_task()[source]
test_remove()[source]
test_call()[source]
test_cancel()[source]
test_func_name_manipulation()[source]
test_wrong_func_name()[source]
test_no_input()[source]
test_responce_of_yes()[source]
test_task_complete_waiting_input()[source]

Test for task completing while waiting for input.

test_new_task_waiting_input()[source]

Test task completing than a new task with the same ID being made while waitinf for input.

test_misformed_command()[source]
class evennia.commands.default.tests.TestAdmin(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_emit()[source]
test_perm()[source]
test_wall()[source]
test_ban()[source]
test_force()[source]
class evennia.commands.default.tests.TestAccount(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_ooc_look()[source]
test_ooc()[source]
test_ic()[source]
test_ic__other_object()[source]
test_ic__nonaccess()[source]
test_password()[source]
test_option()[source]
test_who()[source]
test_quit()[source]
test_sessions()[source]
test_color_test()[source]
test_char_create()[source]
test_char_delete()[source]
test_quell()[source]
class evennia.commands.default.tests.TestBuilding(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_create()[source]
test_examine()[source]
test_set_obj_alias()[source]
test_copy()[source]
test_attribute_commands()[source]
test_nested_attribute_commands()[source]
test_split_nested_attr()[source]
test_do_nested_lookup()[source]
test_name()[source]
test_desc()[source]
test_empty_desc()[source]

empty desc sets desc as ‘’

test_desc_default_to_room()[source]

no rhs changes room’s desc

test_destroy()[source]
test_destroy_sequence()[source]
test_dig()[source]
test_tunnel()[source]
test_tunnel_exit_typeclass()[source]
test_exit_commands()[source]
test_set_home()[source]
test_list_cmdsets()[source]
test_typeclass()[source]
test_lock()[source]
test_find()[source]
test_script()[source]
test_teleport()[source]
test_tag()[source]
test_spawn()[source]
class evennia.commands.default.tests.TestComms(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

setUp()[source]

Sets up testing environment

test_toggle_com()[source]
test_all_com()[source]
test_clock()[source]
test_cdesc()[source]
test_cwho()[source]
test_page()[source]
test_cboot()[source]
test_cdestroy()[source]
class evennia.commands.default.tests.TestCommsChannel(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

Test the central channel command.

setUp()[source]

Sets up testing environment

tearDown()[source]

Hook method for deconstructing the test fixture after testing it.

test_channel__noarg()[source]
test_channel__msg()[source]
test_channel__list()[source]
test_channel__all()[source]
test_channel__history()[source]
test_channel__sub()[source]
test_channel__unsub()[source]
test_channel__alias__unalias()[source]

Add and then remove a channel alias

test_channel__mute()[source]
test_channel__unmute()[source]
test_channel__create()[source]
test_channel__destroy()[source]
test_channel__desc()[source]
test_channel__lock()[source]
test_channel__unlock()[source]
test_channel__boot()[source]
test_channel__ban__unban()[source]

Test first ban and then unban

test_channel__who()[source]
class evennia.commands.default.tests.TestBatchProcess(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_batch_commands(mock_delay, mock_repeat)[source]
class evennia.commands.default.tests.CmdInterrupt(**kwargs)[source]

Bases: evennia.commands.command.Command

(you may see this if a child command had no help text defined)

Usage:

command [args]

This is the base command class. Inherit from this to create new commands.

The cmdhandler makes the following variables available to the command methods (so you can always assume them to be there): self.caller - the game object calling the command self.cmdstring - the command name used to trigger this command (allows

you to know which alias was used, for example)

cmd.args - everything supplied to the command following the cmdstring

(this is usually what is parsed in self.parse())

cmd.cmdset - the cmdset from which this command was matched (useful only

seldomly, notably for help-type commands, to create dynamic help entries and lists)

cmd.obj - the object on which this command is defined. If a default command,

this is usually the same as caller.

cmd.rawstring - the full raw string input, including any args and no parsing.

The following class properties can/should be defined on your child class:

key - identifier for command (e.g. “look”) aliases - (optional) list of aliases (e.g. [“l”, “loo”]) locks - lock string (default is “cmd:all()”) help_category - how to organize this help entry in help system

(default is “General”)

auto_help - defaults to True. Allows for turning off auto-help generation arg_regex - (optional) raw string regex defining how the argument part of

the command should look in order to match for this command (e.g. must it be a space between cmdname and arg?)

auto_help_display_key - (optional) if given, this replaces the string shown

in the auto-help listing. This is particularly useful for system-commands whose actual key is not really meaningful.

(Note that if auto_help is on, this initial string is also used by the system to create the help entry for the command, so it’s a good idea to format it similar to this one). This behavior can be changed by overriding the method ‘get_help’ of a command: by default, this method returns cmd.__doc__ (that is, this very docstring, or the docstring of your command). You can, however, extend or replace this without disabling auto_help.

key = 'interrupt'
parse()[source]

Once the cmdhandler has identified this as the command we want, this function is run. If many of your commands have a similar syntax (for example ‘cmd arg1 = arg2’) you should simply define this once and just let other commands of the same form inherit from this. See the docstring of this module for which object properties are available to use (notably self.args).

func()[source]

This is the actual executing part of the command. It is called directly after self.parse(). See the docstring of this module for which object properties are available (beyond those set in self.parse())

aliases = []
help_category = 'general'
lock_storage = 'cmd:all();'
search_index_entry = {'aliases': '', 'category': 'general', 'key': 'interrupt', 'tags': '', 'text': '\n ## Base command\n\n (you may see this if a child command had no help text defined)\n\n Usage:\n command [args]\n\n This is the base command class. Inherit from this\n to create new commands.\n\n The cmdhandler makes the following variables available to the\n command methods (so you can always assume them to be there):\n self.caller - the game object calling the command\n self.cmdstring - the command name used to trigger this command (allows\n you to know which alias was used, for example)\n cmd.args - everything supplied to the command following the cmdstring\n (this is usually what is parsed in self.parse())\n cmd.cmdset - the cmdset from which this command was matched (useful only\n seldomly, notably for help-type commands, to create dynamic\n help entries and lists)\n cmd.obj - the object on which this command is defined. If a default command,\n this is usually the same as caller.\n cmd.rawstring - the full raw string input, including any args and no parsing.\n\n The following class properties can/should be defined on your child class:\n\n key - identifier for command (e.g. "look")\n aliases - (optional) list of aliases (e.g. ["l", "loo"])\n locks - lock string (default is "cmd:all()")\n help_category - how to organize this help entry in help system\n (default is "General")\n auto_help - defaults to True. Allows for turning off auto-help generation\n arg_regex - (optional) raw string regex defining how the argument part of\n the command should look in order to match for this command\n (e.g. must it be a space between cmdname and arg?)\n auto_help_display_key - (optional) if given, this replaces the string shown\n in the auto-help listing. This is particularly useful for system-commands\n whose actual key is not really meaningful.\n\n (Note that if auto_help is on, this initial string is also used by the\n system to create the help entry for the command, so it\'s a good idea to\n format it similar to this one). This behavior can be changed by\n overriding the method \'get_help\' of a command: by default, this\n method returns cmd.__doc__ (that is, this very docstring, or\n the docstring of your command). You can, however, extend or\n replace this without disabling auto_help.\n '}
class evennia.commands.default.tests.TestInterruptCommand(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_interrupt_command()[source]
class evennia.commands.default.tests.TestUnconnectedCommand(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_info_command()[source]
class evennia.commands.default.tests.TestSystemCommands(methodName='runTest')[source]

Bases: evennia.commands.default.tests.CommandTest

test_simple_defaults()[source]
test_multimatch()[source]