Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Adds asset list parser
Browse files Browse the repository at this point in the history
Resolves #4
  • Loading branch information
sudorandom committed Dec 30, 2013
1 parent 18d6a48 commit fbae045
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 6 deletions.
6 changes: 4 additions & 2 deletions evepaste/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
26 changes: 24 additions & 2 deletions evepaste/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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
42 changes: 42 additions & 0 deletions evepaste/testing/tables/assets.py
Original file line number Diff line number Diff line change
@@ -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('', ([], []))
2 changes: 1 addition & 1 deletion evepaste/testing/tables/contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
4 changes: 3 additions & 1 deletion tests/parser_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))
Expand Down

0 comments on commit fbae045

Please sign in to comment.