def test_from_file3(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/dragonskin_boots.arc' with open(file, 'r') as arc: contents = arc.read().splitlines() parser = Arch2Json() items = parser.keys(contents) items.add_field('arch_filename', file) k, v = created_timestamp() items.add_field(k, v) k, v = updated_timestamp() items.add_field(k, v) assert (items.find('object', 'dragonskin_boots')) assert (items.find('name', 'dragonskin boots')) assert (items.find('arch_filename', file)) assert (items.find_key('created')) assert (items.find_key('updated')) field = Field() field.add('model', 'items.monster') for item in items.items: field.add_field(item)
def test_add_items2(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/emptybottles.arc' parser = Arch2Json() with open(file, 'r') as arc: contents = arc.read().splitlines() fields = parser.keys(contents) k, v = created_timestamp() fields.add_field(k, v) assert (fields.find('object', 'coffee_empty')) assert (fields.find('object', 'w_glass_empty')) assert (fields.find('object', 'boozebottle_empty')) assert (fields.find('object', 'winebottle_empty')) assert (fields.find('object', 'wbottle_empty')) assert (fields.find('object', 'potion_empty')) assert (fields.find('object', 'vial_empty')) assert (fields.find('object', 'bag_empty')) assert (fields.find_key('created')) item = fields.item(0) assert (item['object'] == 'coffee_empty') assert ('created' in item)
def test_message6(): contents = '''Object goldgrass name drop 10 gold coins slaying goldcoin msg Click! endmsg type 18 activate_on_push 1 activate_on_release 1 face goldgrass.111 food 10 animation goldgrass no_pick 1 move_on walk is_floor 1 end ''' #import pdb # pdb.set_trace() contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) msg = [ 'Click!', ] assert (fields.find('object', 'goldgrass')) assert (not fields.find_key('Click!')) assert (not fields.find_key('click!')) assert (fields.find('msg', msg))
def test_message3(): contents = '''Object magic_ear type 29 face magic_ear.111 msg @match sesame Click. endmsg no_pick 1 invisible 1 end ''' # import pdb # pdb.set_trace() contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) msg = ['@match sesame', 'Click.'] assert (fields.find('object', 'magic_ear')) assert (not fields.find_key('Click.')) assert (not fields.find_key('click')) assert (not fields.find_value('Click.')) assert (not fields.find_value('click')) assert (fields.find('msg', msg))
def test_python1(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/temp_summon_fog.arc' with open(file, 'r') as arc: contents = arc.read().splitlines() #import pdb # pdb.set_trace() parser = Arch2Json() items = parser.keys(contents) items.add_field('arch_filename', file) k, v = created_timestamp() items.add_field(k, v) k, v = updated_timestamp() items.add_field(k, v) assert (items.find('arch_filename', file)) assert (items.find_key('created')) assert (items.find_key('updated')) field = Field() field.add('model', 'items.ground') for item in items.items: field.add_field(item)
def test_comments1(): contents = '# This is a single line comment' contents = contents.splitlines() parser = Arch2Json() results = parser.keys(contents) assert (results.len <= 0)
def test_comments2(): contents = '''# This is a multi-line comment1 # This is a multi-line comment2 # This is a multi-line comment3 # This is a multi-line comment4''' contents = contents.splitlines() parser = Arch2Json() results = parser.keys(contents) assert (results.len <= 0)
def test_keys6(): contents = '''# Acid spehres are sort of odd creatures - they are really # only a danger if the player is not careful and runs into # them - they otherwise move slowly and are easily killed. # But they do a lot of damage if a player does run into one. Object acid_sphere race slime name acid sphere face acidsphere.111 animation acid_sphere monster 1 move_type walk sleep 1 Wis 5 alive 1 ac 5 wc 1 dam 50 weight 1 level 4 resist_fire 100 resist_electricity 100 resist_cold 100 resist_confusion 100 resist_acid 100 resist_drain 100 resist_weaponmagic 100 resist_ghosthit 100 resist_poison 100 resist_slow 100 resist_paralyze 100 resist_turn_undead 100 resist_blind 100 attacktype 64 hitback 1 hp 1 maxhp 1 speed 0.01 anim_speed 1 exp 100 one_hit 1 end''' contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) assert (fields.find('object', 'acid_sphere')) assert (fields.find('race', 'slime')) assert (fields.find('face', 'acidsphere.111')) assert (fields.find('resist_weaponmagic', '100')) assert (fields.find('speed', '0.01')) assert (fields.find('exp', '100')) assert (fields.find('one_hit', '1'))
def test_from_file1(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/dragonskin_boots.arc' with open(file, 'r') as arc: contents = arc.read().splitlines() parser = Arch2Json() fields = parser.keys(contents) assert (fields.find('object', 'dragonskin_boots')) assert (fields.find('name', 'dragonskin boots'))
def test_no_name(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/dragon_guild.arc' parser = Arch2Json() with open(file, 'r') as arc: contents = arc.read().splitlines() items = parser.keys(contents) assert (items.find('object', 'Dragon Guild')) assert (items.find('name', 'Dragon Guild'))
def test_keys4(): contents = '''# Acid spehres are sort of odd creatures - they are really # only a danger if the player is not careful and runs into # them - they otherwise move slowly and are easily killed. # But they do a lot of damage if a player does run into one. Object acid_sphere end''' contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) assert (fields.len == 1) assert (fields.find('object', 'acid_sphere'))
def test_double_ends(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/altarvalk.arc' parser = Arch2Json() with open(file, 'r') as arc: contents = arc.read().splitlines() #import pdb # pdb.set_trace() items = parser.keys(contents) assert (items.find('object', 'altar_valkyrie')) assert (items.find('name', 'Altar of Valkyrie')) assert (items.find('object', 'altar_valkyrie_pray_event')) assert (items.find('title', 'Python')) assert (items.find('slaying', '/python/gods/altar_valkyrie.py'))
def test_multiple_objects(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/emptybottles.arc' parser = Arch2Json() with open(file, 'r') as arc: contents = arc.read().splitlines() fields = parser.keys(contents) assert (fields.find('object', 'coffee_empty')) assert (fields.find('object', 'w_glass_empty')) assert (fields.find('object', 'boozebottle_empty')) assert (fields.find('object', 'winebottle_empty')) assert (fields.find('object', 'wbottle_empty')) assert (fields.find('object', 'potion_empty')) assert (fields.find('object', 'vial_empty')) assert (fields.find('object', 'bag_empty'))
def test_from_file2(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) files = [ '/tests/dragonskin_boots.arc', '/tests/elvenboots.arc', '/tests/golem_shoes.arc' ] parser = Arch2Json() for file in files: with open(BASE_PATH + file, 'r') as arc: contents = arc.read().splitlines() fields = parser.keys(contents) assert (fields.find('object', 'dragonskin_boots')) assert (fields.find('object', 'elvenboots')) assert (fields.find('object', 'golem_shoes'))
def test_message2(): contents = '''Object spell_magic_missile anim_suffix spellcasting name magic missile name_pl magic missile face spell_magic_missile.111 level 1 sp 1 casting_time 3 path_attuned 16 other_arch magic_missile dam 9 dam_modifier 1 maxsp 20 skill sorcery type 101 subtype 11 value 10 attacktype 2 no_drop 1 invisible 1 range 25 msg Fires a target-tracking magical bolt that can turn to seek out enemies. The bolt does not always track well and may run into walls or even return and strike the caster. endmsg end''' # import pdb # pdb.set_trace() contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) msg = [ "Fires a target-tracking magical bolt that can turn to seek out enemies. The bolt does not always track well and may run into walls or even return and strike the caster." ] assert (fields.find('object', 'spell_magic_missile')) assert (not fields.find_key('Fires')) assert (not fields.find_key('fires')) assert (not fields.find_value('Fires')) assert (not fields.find_value('fires')) assert (fields.find('msg', msg))
def test_multiple_objects2(): BASE_PATH = os.path.dirname(os.path.dirname((os.path.abspath(__file__)))) file = BASE_PATH + '/tests/emptybottles.arc' parser = Arch2Json() with open(file, 'r') as arc: contents = arc.read().splitlines() items = parser.keys(contents) items.add_field('arch_filename', file) k, v = created_timestamp() items.add_field(k, v) k, v = updated_timestamp() items.add_field(k, v) assert (items.find('object', 'coffee_empty')) assert (items.find('object', 'w_glass_empty')) assert (items.find('object', 'boozebottle_empty')) assert (items.find('object', 'winebottle_empty')) assert (items.find('object', 'wbottle_empty')) assert (items.find('object', 'potion_empty')) assert (items.find('object', 'vial_empty')) assert (items.find('object', 'bag_empty')) assert (items.find('arch_filename', file)) assert (items.find_key('created')) assert (items.find_key('updated')) fields = Field() fields.add('model', 'items.potion') assert (fields.find_key('fields')) assert (fields.find_key('model')) _list = [] for item in items.items: fields.add_field(item) _list.append(fields.field)
def test_message1(): contents = '''Object dwarf_wiz race dwarf tanneritems tanner_books name dwarf wizard animation dwarf_wiz msg @match * I'm too busy to answer your queries. endmsg face dwarf_wiz.111 Pow 18 sp 50 maxsp 50 monster 1 move_type walk unaggressive 1 alive 1 ac 10 wc 15 dam 5 hp 38 maxhp 38 exp 10 speed 0.06 weight 50000 level 15 can_cast_spell 1 end''' contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) msg = ["@match *", "I'm too busy to answer your queries."] assert (fields.find('object', 'dwarf_wiz')) assert (fields.find('msg', msg)) assert (fields.find('monster', '1')) assert (fields.find('maxsp', '50'))
def test_comments3(): contents = '''Object spell_reincarnation anim_suffix spellcasting name reincarnation name_pl reincarnation face spell_reincarnation.111 type 101 subtype 1 level 25 value 250 grace 350 casting_time 30 path_attuned 256 skill praying no_drop 1 invisible 1 exp 20 # tanneritems reincarnation_failure race reincarnation_races msg Brings a slain character back to life, as with the resurrection spell, but without requiring a corpse, and usually as a different race, with all the benefits and penalties associated with it. Gaea grants this spell, and it is only useful on permanent death servers. endmsg end''' # import pdb # pdb.set_trace() contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) assert (fields.find('object', 'spell_reincarnation')) assert (not fields.find_key('reincarnation_failure')) assert (not fields.find_key('tanneritems')) assert (not fields.find_key('#tanneritems')) assert (not fields.find_value('reincarnation_failure')) assert (not fields.find_value('tanneritems')) assert (not fields.find_value('#tanneritems'))
def test_animation1(): contents = '''Object werewolf face 1728 anim 1728 1729 1728 1728 1730 1728 mina monster 1 Wis 10 alive 1 hp 50 maxhp 50 Con 10 speed 0.10 exp 100 ac 5 dam 8 wc 1 level 5 protected 1 weight 80000 run_away 15 pick_up 64 can_use_weapon 1 attacktype 3 end''' contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) anim = ['1728', '1729', '1728', '1728', '1730', '1728'] assert (fields.find('object', 'werewolf')) assert (fields.find('anim', anim))
def test_message5(): contents = '''Object spell_magic_missile msg Fires a target-tracking magical bolt that can turn to seek out enemies. The bolt does not always track well and may run into walls or even return and strike the caster. endmsg end''' # import pdb # pdb.set_trace() contents = contents.splitlines() parser = Arch2Json() fields = parser.keys(contents) msg = [ "Fires a target-tracking magical bolt that can turn to seek out enemies. The bolt does not always track well and may run into walls or even return and strike the caster." ] assert (fields.find('object', 'spell_magic_missile')) assert (not fields.find_key('Fires')) assert (not fields.find_key('fires')) assert (not fields.find_value('Fires')) assert (not fields.find_value('fires')) assert (fields.find('msg', msg))
def test_keys1(): contents = ''.splitlines() parser = Arch2Json() results = parser.keys(contents) assert (results.len <= 0)
def test_model2(): parser = Arch2Json() parser.model = 'items.spells' assert (parser.model == 'items.spells')