Skip to content

Commit

Permalink
Merge pull request #9 from Gallaecio/full-coverage
Browse files Browse the repository at this point in the history
Reach 100% coverage and specify which parts are untested in coverage reports
  • Loading branch information
kmike authored Jun 21, 2019
2 parents 78f9a65 + 7cb86f8 commit 9cf1888
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[run]
branch = true

[report]
show_missing = true
5 changes: 4 additions & 1 deletion price_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def extract_price_text(price: str) -> Optional[str]:
return None


# NOTE: Keep supported separators in sync with parse_number()
_search_decimal_sep = re.compile(r"""
\d # at least one digit (there can be more before it)
([.,€]) # decimal separator
Expand Down Expand Up @@ -268,13 +269,15 @@ def parse_number(num: str) -> Optional[Decimal]:
return None
num = num.strip().replace(' ', '')
decimal_separator = get_decimal_separator(num)
# NOTE: Keep supported separators in sync with _search_decimal_sep
if decimal_separator is None:
num = num.replace('.', '').replace(',', '')
elif decimal_separator == '.':
num = num.replace(',', '')
elif decimal_separator == ',':
num = num.replace('.', '').replace(',', '.')
elif decimal_separator == '€':
else:
assert decimal_separator == '€'
num = num.replace('.', '').replace(',', '').replace('€', '.')
try:
return Decimal(num)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_price_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1975,3 +1975,14 @@ def __eq__(self, other):
def test_parsing(example: Example):
parsed = Price.fromstring(example.price_raw, example.currency_raw)
assert parsed == example


@pytest.mark.parametrize(
"amount,amount_float",
(
(None, None),
(Decimal('1.23'), 1.23),
)
)
def test_price_amount_float(amount, amount_float):
assert Price(amount, None, None).amount_float == amount_float

0 comments on commit 9cf1888

Please sign in to comment.