<s> from shinytest import ShinyTestCase <EOL> import os <EOL> import shutil <EOL> class TestSport ( ShinyTestCase ) : <EOL> def test_shiny_area_format ( self ) : <EOL> """<STR_LIT>""" <EOL> from shinymud . lib . sport_plugins . formatters . area_write_shiny_format import format as writeshiny <EOL> from shinymud . lib . sport_plugins . formatters . area_read_shiny_format import format as readshiny <EOL> area = self . _create_area ( ) <EOL> area_txt = writeshiny ( area ) <EOL> self . world . log . debug ( area_txt ) <EOL> self . world . destroy_area ( area . name , '<STR_LIT:test>' ) <EOL> self . assertFalse ( self . world . area_exists ( '<STR_LIT:foo>' ) ) <EOL> readshiny ( self . world , area_txt ) <EOL> self . assertTrue ( self . world . area_exists ( '<STR_LIT:foo>' ) ) <EOL> nufoo = self . world . get_area ( '<STR_LIT:foo>' ) <EOL> self . assertEqual ( len ( nufoo . scripts . keys ( ) ) , <NUM_LIT:1> ) <EOL> s1 = nufoo . get_script ( '<STR_LIT:1>' ) <EOL> self . assertEqual ( '<STR_LIT>' , s1 . body ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , s1 . name ) <EOL> i1 = nufoo . get_item ( '<STR_LIT:1>' ) <EOL> self . assertEqual ( '<STR_LIT>' , i1 . name ) <EOL> self . assertTrue ( i1 . has_type ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( i1 . item_types [ '<STR_LIT>' ] . capacity , <NUM_LIT:1> ) <EOL> n1 = nufoo . get_npc ( '<STR_LIT:1>' ) <EOL> self . assertEqual ( '<STR_LIT>' , n1 . name ) <EOL> self . assertEqual ( '<STR_LIT>' , n1 . description ) <EOL> nevent = n1 . events [ '<STR_LIT>' ] [ <NUM_LIT:0> ] <EOL> self . assertEqual ( nevent . event_trigger , '<STR_LIT>' ) <EOL> self . assertTrue ( nevent . script is s1 ) <EOL> self . assertEqual ( nevent . condition , '<STR_LIT>' ) <EOL> r1 = nufoo . get_room ( '<STR_LIT:1>' ) <EOL> r2 = nufoo . get_room ( '<STR_LIT:2>' ) <EOL> self . assertEqual ( '<STR_LIT>' , r1 . name ) <EOL> self . assertEqual ( '<STR_LIT>' , r1 . description ) <EOL> self . assertTrue ( r1 . exits [ '<STR_LIT>' ] . to_room is r2 ) <EOL> self . assertTrue ( r2 . exits [ '<STR_LIT>' ] . to_room is r1 ) <EOL> self . assertTrue ( r1 . spawns [ '<STR_LIT:1>' ] . spawn_object is i1 ) <EOL> self . assertTrue ( r2 . spawns [ '<STR_LIT:1>' ] . spawn_object is n1 ) <EOL> self . assertEqual ( len ( r1 . items ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( r2 . npcs ) , <NUM_LIT:1> ) <EOL> def _create_area ( self ) : <EOL> from shinymud . models . area import Area <EOL> area = Area . create ( { '<STR_LIT:name>' : '<STR_LIT:foo>' } ) <EOL> script = area . new_script ( ) <EOL> script . name = '<STR_LIT:bar>' <EOL> script . body = '<STR_LIT>' <EOL> script . save ( ) <EOL> item = area . new_item ( ) <EOL> item . build_set_name ( '<STR_LIT>' ) <EOL> item . build_add_type ( '<STR_LIT>' ) <EOL> item . item_types [ '<STR_LIT>' ] . capacity = <NUM_LIT:5> <EOL> item . save ( ) <EOL> npc = area . new_npc ( ) <EOL> npc . name = '<STR_LIT>' <EOL> npc . description = '<STR_LIT>' <EOL> npc . save ( ) <EOL> npc . build_add_event ( "<STR_LIT>" ) <EOL> rd = { '<STR_LIT:id>' : '<STR_LIT:1>' , '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:description>' : '<STR_LIT>' } <EOL> room = area . new_room ( rd ) <EOL> room2 = area . new_room ( ) <EOL> room . link_exits ( '<STR_LIT>' , room2 ) <EOL> room . build_add_spawn ( '<STR_LIT>' ) <EOL> room2 . build_add_spawn ( '<STR_LIT>' ) <EOL> return area <EOL> def _clean_test_file ( self , path ) : <EOL> try : <EOL> os . remove ( path ) <EOL> except Exception , e : <EOL> self . world . log . debug ( '<STR_LIT>' + str ( e ) ) <EOL> def test_list_areas ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . lib . sport import export , list_importable <EOL> from shinymud . data . config import AREAS_EXPORT_DIR , AREAS_IMPORT_DIR <EOL> a = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> b = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> export ( '<STR_LIT>' , a ) <EOL> export ( '<STR_LIT>' , b ) <EOL> self . world . destroy_area ( '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> self . world . destroy_area ( '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> txt = list_importable ( '<STR_LIT>' ) <EOL> self . assertNotEqual ( txt . find ( '<STR_LIT>' ) , - <NUM_LIT:1> ) <EOL> self . assertNotEqual ( txt . find ( '<STR_LIT>' ) , - <NUM_LIT:1> ) <EOL> self . world . log . debug ( txt ) <EOL> self . _clean_test_file ( AREAS_EXPORT_DIR + '<STR_LIT>' ) <EOL> self . _clean_test_file ( AREAS_EXPORT_DIR + '<STR_LIT>' ) <EOL> def test_inport_dir ( self ) : <EOL> from shinymud . models . area import Area <EOL> from shinymud . lib . sport import export , inport_dir <EOL> from shinymud . data . config import AREAS_EXPORT_DIR <EOL> epath = AREAS_EXPORT_DIR + '<STR_LIT>' <EOL> a = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> b = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> c = Area . create ( { '<STR_LIT:name>' : '<STR_LIT>' } ) <EOL> export ( '<STR_LIT>' , a , dest_path = epath ) <EOL> export ( '<STR_LIT>' , b , dest_path = epath ) <EOL> export ( '<STR_LIT>' , c , dest_path = epath ) <EOL> self . world . destroy_area ( '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> self . world . destroy_area ( '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> self . world . destroy_area ( '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> txt = inport_dir ( '<STR_LIT>' , source_path = epath ) <EOL> self . world . log . debug ( txt ) <EOL> self . assertTrue ( self . world . area_exists ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . world . area_exists ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . world . area_exists ( '<STR_LIT>' ) ) <EOL> shutil . rmtree ( epath , True ) <EOL> def test_shiny_player_format ( self ) : <EOL> from shinymud . lib . sport_plugins . formatters . player_write_shiny_format import format as writeshiny <EOL> from shinymud . lib . sport_plugins . formatters . player_read_shiny_format import format as readshiny <EOL> from shinymud . models . player import Player <EOL> sven = Player ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) <EOL> sven . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT:foo>' } ) <EOL> sven . permissions = <NUM_LIT> <EOL> sven . description = "<STR_LIT>" <EOL> sven . title = '<STR_LIT>' <EOL> sven . save ( ) <EOL> area = self . _create_area ( ) <EOL> sven . item_add ( area . get_item ( '<STR_LIT:1>' ) . load ( ) ) <EOL> txt = writeshiny ( sven ) <EOL> self . world . log . debug ( txt ) <EOL> sven . destruct ( ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> self . assertFalse ( row ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ sven . dbid ] ) <EOL> self . assertFalse ( row ) <EOL> result = readshiny ( self . world , txt ) <EOL> self . world . log . debug ( result ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> self . assertTrue ( row ) <EOL> self . assertFalse ( self . world . get_player ( '<STR_LIT>' ) ) <EOL> isven = Player ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) <EOL> isven . playerize ( row ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ isven . dbid ] ) <EOL> self . assertTrue ( row ) <EOL> self . assertEqual ( sven . password , isven . password ) <EOL> self . assertEqual ( sven . description , isven . description ) <EOL> self . assertEqual ( sven . name , isven . name ) <EOL> self . assertEqual ( sven . title , isven . title ) <EOL> self . assertEqual ( sven . permissions , isven . permissions ) <EOL> self . assertEqual ( len ( sven . inventory ) , len ( isven . inventory ) ) <EOL> item = isven . inventory [ <NUM_LIT:0> ] <EOL> self . world . log . debug ( item . create_save_dict ( ) ) <EOL> self . world . log . debug ( item . item_types ) <EOL> self . assertFalse ( sven . inventory [ <NUM_LIT:0> ] is isven . inventory [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( item . name , '<STR_LIT>' ) <EOL> self . assertTrue ( item . has_type ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( item . item_types [ '<STR_LIT>' ] . capacity , <NUM_LIT:5> ) <EOL> def test_shiny_player_format_containers ( self ) : <EOL> """<STR_LIT>""" <EOL> from shinymud . lib . sport_plugins . formatters . player_write_shiny_format import format as writeshiny <EOL> from shinymud . lib . sport_plugins . formatters . player_read_shiny_format import format as readshiny <EOL> from shinymud . lib . connection_handlers . shiny_connections import ShinyConnection <EOL> from shinymud . models . player import Player <EOL> sven = Player ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) <EOL> sven . playerize ( { '<STR_LIT:name>' : '<STR_LIT>' , '<STR_LIT:password>' : '<STR_LIT:foo>' } ) <EOL> sven . save ( ) <EOL> area = self . _create_area ( ) <EOL> item1 = area . new_item ( ) <EOL> item1 . build_set_keywords ( '<STR_LIT>' ) <EOL> item1 . build_add_type ( '<STR_LIT>' ) <EOL> game1 = item1 . load ( ) <EOL> item2 = area . new_item ( ) <EOL> item2 . build_set_keywords ( '<STR_LIT>' ) <EOL> item2 . build_add_type ( '<STR_LIT>' ) <EOL> game2 = item2 . load ( ) <EOL> self . assertTrue ( game1 . item_types [ '<STR_LIT>' ] . item_add ( game2 ) ) <EOL> item3 = area . new_item ( ) <EOL> item3 . build_set_keywords ( '<STR_LIT>' ) <EOL> game3 = item3 . load ( ) <EOL> self . assertTrue ( game2 . item_types [ '<STR_LIT>' ] . item_add ( game3 ) ) <EOL> sven . item_add ( game1 ) <EOL> txt = writeshiny ( sven ) <EOL> self . world . log . debug ( txt ) <EOL> sven . destruct ( ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> self . assertFalse ( row ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ sven . dbid ] ) <EOL> self . assertFalse ( row ) <EOL> result = readshiny ( self . world , txt ) <EOL> self . world . log . debug ( result ) <EOL> self . assertEqual ( result , '<STR_LIT>' ) <EOL> row = self . world . db . select ( '<STR_LIT>' , [ '<STR_LIT>' ] ) [ <NUM_LIT:0> ] <EOL> isven = Player ( ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) ) <EOL> isven . playerize ( row ) <EOL> self . assertEqual ( len ( isven . inventory ) , <NUM_LIT:1> ) <EOL> s1 = isven . inventory [ <NUM_LIT:0> ] <EOL> self . assertEqual ( s1 . keywords , [ '<STR_LIT>' ] ) <EOL> s2 = s1 . item_types [ '<STR_LIT>' ] . get_item_by_kw ( '<STR_LIT>' ) <EOL> self . assertEqual ( s2 . keywords , [ '<STR_LIT>' ] ) <EOL> s3 = s2 . item_types [ '<STR_LIT>' ] . get_item_by_kw ( '<STR_LIT>' ) <EOL> self . assertEqual ( s3 . keywords , [ '<STR_LIT>' ] ) </s>
