diff --git a/evepaste/__init__.py b/evepaste/__init__.py index 9e54351..cca9303 100644 --- a/evepaste/__init__.py +++ b/evepaste/__init__.py @@ -9,13 +9,15 @@ parse_eft, parse_dscan, parse_loot_history, - parse_contract) + parse_contract, + parse_asset_list) __all__ = ['parse_cargo_scan', 'parse_human_listing', 'parse_eft', 'parse_dscan', 'parse_loot_history', - 'parse_contract'] + 'parse_contract', + 'parse_asset_list'] __version__ = '0.1' diff --git a/evepaste/parsers.py b/evepaste/parsers.py index 63b4f17..616940a 100644 --- a/evepaste/parsers.py +++ b/evepaste/parsers.py @@ -20,6 +20,8 @@ LOOT_HIST_RE = re.compile( r"(\d\d:\d\d:\d\d) ([\S ]+) has looted (\d+) x ([\S ]+)") CONTRACT_RE = re.compile(r"^([\S ]+)\t([\d]+)\t([\S ]*)\t([\S ]*)\t?(Fitted|)") +ASSET_LIST_RE = re.compile( + r"^([\S ]*)\t([\d]+)\t([\S ]*)\t([\S ]*)\t([\S ]*)\t([\S ,]*)") def parse_cargo_scan(paste_string): @@ -103,8 +105,11 @@ def parse_loot_history(paste_string): return result, bad_lines -# Item Name\tCount\tCategory\tFitted def parse_contract(paste_string): + """ Parse contract format + + :param string paste_string: A contract result string + """ paste_lines = split_and_strip(paste_string) matches, bad_lines = regex_match_lines(CONTRACT_RE, paste_lines) @@ -117,7 +122,24 @@ def parse_contract(paste_string): return result, bad_lines +def parse_asset_list(paste_string): + """ Parse asset list + + :param string paste_string: An asset list string + """ + paste_lines = split_and_strip(paste_string) + matches, bad_lines = regex_match_lines(ASSET_LIST_RE, paste_lines) + + result = [{'name': name, + 'quantity': int(quantity), + 'group': group, + 'size': size, + 'slot': slot, + 'volume': volume} + for name, quantity, group, size, slot, volume in matches] + return result, bad_lines + + # TODO: Manufactoring -# TODO: Assets # TODO: Inventory # TODO: Bill of Materials diff --git a/evepaste/testing/tables/assets.py b/evepaste/testing/tables/assets.py new file mode 100644 index 0000000..9d8e85c --- /dev/null +++ b/evepaste/testing/tables/assets.py @@ -0,0 +1,42 @@ +""" +evepaste.testing.tables.assets +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +Asset list table tests + +""" +from evepaste import parse_asset_list +from evepaste.testing import TableTestGroup + + +ASSET_TABLE = TableTestGroup(parse_asset_list) +ASSET_TABLE.add_test('Hurricane\t1\tCombat Battlecruiser\t\t\t15,000 m3', + ([{'name': 'Hurricane', + 'quantity': 1, + 'group': 'Combat Battlecruiser', + 'size': '', + 'slot': '', + 'volume': '15,000 m3'}], [])) +ASSET_TABLE.add_test(''' +720mm Gallium Cannon\t1\tProjectile Weapon\tMedium\tHigh\t10 m3 +Damage Control II\t1\tDamage Control\t\tLow\t5 m3 +Experimental 10MN Microwarpdrive I\t1\tPropulsion Module\t\tMedium\t10 m3''', + ([{'slot': 'High', + 'group': 'Projectile Weapon', + 'name': '720mm Gallium Cannon', + 'volume': '10 m3', + 'quantity': 1, + 'size': 'Medium'}, + {'slot': 'Low', + 'group': 'Damage Control', + 'name': 'Damage Control II', + 'volume': '5 m3', + 'quantity': 1, + 'size': ''}, + {'slot': 'Medium', + 'group': 'Propulsion Module', + 'name': 'Experimental 10MN Microwarpdrive I', + 'volume': '10 m3', + 'quantity': 1, + 'size': ''}], [])) +ASSET_TABLE.add_test('hurricane', ([], ['hurricane'])) +ASSET_TABLE.add_test('', ([], [])) diff --git a/evepaste/testing/tables/contract.py b/evepaste/testing/tables/contract.py index 02fffab..70caa50 100644 --- a/evepaste/testing/tables/contract.py +++ b/evepaste/testing/tables/contract.py @@ -9,7 +9,7 @@ CONTRACT_TABLE = TableTestGroup(parse_contract) -CONTRACT_TABLE.add_test('''Rokh\t1\tBattleship\tShip\t''', +CONTRACT_TABLE.add_test('Rokh\t1\tBattleship\tShip\t', ([{'name': 'Rokh', 'quantity': 1, 'type': 'Battleship', diff --git a/tests/parser_tests.py b/tests/parser_tests.py index bdce7d1..c5c1982 100644 --- a/tests/parser_tests.py +++ b/tests/parser_tests.py @@ -4,6 +4,7 @@ from evepaste.testing.tables.dscan import DSCAN_TABLE from evepaste.testing.tables.loot_history import LOOT_HISTORY_TABLE from evepaste.testing.tables.contract import CONTRACT_TABLE +from evepaste.testing.tables.assets import ASSET_TABLE import inspect @@ -29,7 +30,8 @@ def test_generator(): EFT_TABLE, DSCAN_TABLE, LOOT_HISTORY_TABLE, - CONTRACT_TABLE]: + CONTRACT_TABLE, + ASSET_TABLE]: for i, (input_str, expected) in enumerate(table.tests): check_table.description = ('TableTest: %s[%s]' % (str(table.funct.__name__), i))