diff --git a/hotprices_au/units.py b/hotprices_au/units.py index 07d9e26..a302abe 100644 --- a/hotprices_au/units.py +++ b/hotprices_au/units.py @@ -61,15 +61,18 @@ def parse_str_unit(unit_str): if matched: try: count_group = matched.group('count') - # We might match on 4x4 and not just 4, so we split by x, type case each and then multiply them - if 'x' in count_group: - counts = count_group.split('x') + if count_group is None: + count = 1 else: - counts = [count_group] - counts = [float(c) for c in counts] - count = 1 - for count_elem in counts: - count *= count_elem + # We might match on 4x4 and not just 4, so we split by x, type case each and then multiply them + if count_group and 'x' in count_group: + counts = count_group.split('x') + else: + counts = [count_group] + counts = [float(c) for c in counts] + count = 1 + for count_elem in counts: + count *= count_elem except IndexError: count = 1 diff --git a/tests/stores/test_woolies.py b/tests/stores/test_woolies.py index 2daa76d..200a14d 100644 --- a/tests/stores/test_woolies.py +++ b/tests/stores/test_woolies.py @@ -166,6 +166,11 @@ def test_get_canonical(): assert can_item['unit'] == 'ml' assert can_item['quantity'] == 9000 + item = get_item(PackageSize='200ml X Pack') + can_item = woolies.get_canonical(item, today) + assert can_item['unit'] == 'ml' + assert can_item['quantity'] == 200 + if __name__ == '__main__': test_get_canonical() \ No newline at end of file