<s> from shinytest import ShinyTestCase <EOL> class TestGeneralCommands ( ShinyTestCase ) : <EOL> def test_command_register ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . data import config <EOL> from shinymud . models . player import Player <EOL> from shinymud . commands import CommandRegister <EOL> cmds = CommandRegister ( ) <EOL> self . assertEqual ( cmds [ '<STR_LIT>' ] , None , <EOL> "<STR_LIT>" ) <EOL> cmds . register ( ( lambda : <NUM_LIT:3> ) , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> self . assertEqual ( cmds [ '<STR_LIT>' ] ( ) , <NUM_LIT:3> , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( cmds [ '<STR_LIT>' ] ( ) , <NUM_LIT:3> , <EOL> "<STR_LIT>" ) <EOL> self . assertEqual ( cmds [ '<STR_LIT>' ] , cmds [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" ) <EOL> def test_chat_command ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . data import config <EOL> from shinymud . models . player import Player <EOL> from shinymud . commands . commands import Chat <EOL> bob = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> alice = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> sam = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> bob . mode = None <EOL> bob . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> bob . outq = [ ] <EOL> sam . mode = None <EOL> sam . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> sam . outq = [ ] <EOL> self . world . player_add ( bob ) <EOL> self . world . player_add ( sam ) <EOL> self . world . player_add ( alice ) <EOL> Chat ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> chat = config . chat_color + '<STR_LIT>' + config . clear_fcolor <EOL> self . assertTrue ( chat in sam . outq ) <EOL> self . assertTrue ( chat in bob . outq ) <EOL> self . assertFalse ( chat in alice . outq ) <EOL> sam . channels [ '<STR_LIT>' ] = False <EOL> print sam . channels <EOL> print bob . channels <EOL> sam . outq = [ ] <EOL> bob . outq = [ ] <EOL> alice . outq = [ ] <EOL> Chat ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> print sam . channels <EOL> print sam . outq <EOL> print bob . channels <EOL> print bob . outq <EOL> self . assertFalse ( chat in sam . outq ) <EOL> self . assertTrue ( chat in bob . outq ) <EOL> self . assertFalse ( chat in alice . outq ) <EOL> def test_give_command ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . data import config <EOL> from shinymud . models . player import Player <EOL> from shinymud . commands . commands import Give <EOL> area = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> room = area . new_room ( ) <EOL> bob = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> bob . mode = None <EOL> bob . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> alice = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> alice . mode = None <EOL> alice . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . world . player_add ( bob ) <EOL> self . world . player_add ( alice ) <EOL> room . add_char ( bob ) <EOL> room . add_char ( alice ) <EOL> alice . location = room <EOL> bob . location = room <EOL> proto_npc = area . new_npc ( ) <EOL> npc = proto_npc . load ( ) <EOL> room . add_char ( npc ) <EOL> item = area . new_item ( ) <EOL> item . build_set_keywords ( '<STR_LIT>' , bob ) <EOL> item . build_set_name ( '<STR_LIT>' , bob ) <EOL> bob . item_add ( item . load ( ) ) <EOL> self . assertEqual ( len ( bob . inventory ) , <NUM_LIT:1> ) <EOL> Give ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( len ( bob . inventory ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( alice . inventory ) , <NUM_LIT:1> ) <EOL> to_alice = '<STR_LIT>' <EOL> self . assertTrue ( to_alice in alice . outq ) <EOL> to_bob = '<STR_LIT>' <EOL> self . assertTrue ( to_bob in bob . outq ) <EOL> Give ( alice , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( len ( alice . inventory ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( npc . inventory ) , <NUM_LIT:1> ) <EOL> to_alice = '<STR_LIT>' % npc . name <EOL> alice . world . log . debug ( alice . outq ) <EOL> self . assertTrue ( to_alice in alice . outq ) <EOL> to_shiny = '<STR_LIT>' <EOL> self . assertTrue ( to_shiny in npc . actionq ) <EOL> bob . currency = <NUM_LIT:100> <EOL> com = config . CURRENCY + '<STR_LIT>' <EOL> self . assertEqual ( alice . currency , <NUM_LIT:0> ) <EOL> Give ( bob , com , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . currency , <NUM_LIT> ) <EOL> self . assertEqual ( alice . currency , <NUM_LIT:1> ) <EOL> com = '<STR_LIT>' + config . CURRENCY + '<STR_LIT>' <EOL> Give ( bob , com , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . currency , <NUM_LIT:0> ) <EOL> self . assertEqual ( alice . currency , <NUM_LIT:100> ) <EOL> com = '<STR_LIT>' + config . CURRENCY + '<STR_LIT>' <EOL> Give ( bob , com , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . currency , <NUM_LIT:0> ) <EOL> self . assertEqual ( alice . currency , <NUM_LIT:100> ) <EOL> def test_set_command ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . data import config <EOL> from shinymud . models . player import Player <EOL> from shinymud . commands . commands import Set <EOL> bob = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> bob . mode = None <EOL> bob . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> Set ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( '<STR_LIT>' , bob . email ) <EOL> Set ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( '<STR_LIT>' , bob . title ) <EOL> Set ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> eresult = '<STR_LIT>' <EOL> self . assertTrue ( eresult in bob . outq ) <EOL> bob . outq = [ ] <EOL> Set ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertTrue ( eresult in bob . outq ) <EOL> bob . permissions = bob . permissions | config . BUILDER <EOL> Set ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( '<STR_LIT>' , bob . goto_appear ) <EOL> bob . outq = [ ] <EOL> Set ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( '<STR_LIT:foo>' , bob . goto_disappear ) <EOL> def test_goto_command ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . data import config <EOL> from shinymud . models . player import Player <EOL> from shinymud . commands . commands import Goto <EOL> blarg_area = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> foo_area = Area . create ( { '<STR_LIT:name>' : '<STR_LIT:foo>' } ) <EOL> blarg_room = blarg_area . new_room ( ) <EOL> foo_room = foo_area . new_room ( ) <EOL> bob = Player ( ( '<STR_LIT>' , '<STR_LIT:bar>' ) ) <EOL> bob . mode = None <EOL> bob . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT>' } ) <EOL> self . world . player_add ( bob ) <EOL> bob . permissions = bob . permissions | config . BUILDER <EOL> generic_fail = '<STR_LIT>' <EOL> Goto ( bob , '<STR_LIT:%s>' % foo_room . id , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . location , None ) <EOL> bob . world . log . debug ( bob . outq ) <EOL> self . assertTrue ( generic_fail in bob . outq ) <EOL> message = '<STR_LIT>' <EOL> Goto ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . location , None ) <EOL> bob . world . log . debug ( bob . outq ) <EOL> self . assertTrue ( message in bob . outq ) <EOL> message = '<STR_LIT>' <EOL> Goto ( bob , '<STR_LIT>' , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . location , None ) <EOL> bob . world . log . debug ( bob . outq ) <EOL> self . assertTrue ( message in bob . outq ) <EOL> Goto ( bob , '<STR_LIT>' % ( foo_room . id , foo_room . area . name ) , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . location , foo_room ) <EOL> Goto ( bob , '<STR_LIT>' % ( blarg_room . id , blarg_room . area . name ) , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . location , blarg_room ) <EOL> blarg_r2 = blarg_area . new_room ( ) <EOL> Goto ( bob , '<STR_LIT:%s>' % ( blarg_r2 . id ) , '<STR_LIT>' ) . run ( ) <EOL> self . assertEqual ( bob . location , blarg_r2 ) <EOL> bob . outq = [ ] <EOL> Goto ( bob , '<STR_LIT:U+0020>' , '<STR_LIT>' ) . run ( ) <EOL> fail = '<STR_LIT>' <EOL> self . assertTrue ( fail in bob . outq ) </s>
