|
@@ -151,3 +151,25 @@ def test_sum_regex_currency_first(haystack, expected_needles):
|
|
|
haystack,
|
|
|
)
|
|
|
assert expected_needles == [m.groupdict() for m in matches]
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.parametrize(('haystack', 'expected_needles'), [
|
|
|
+ ["0,50 US$", [{'post_currency': 'US$', 'pre_value': '0,50'}]],
|
|
|
+ ["0,50 €", [{'post_currency': '€', 'pre_value': '0,50'}]],
|
|
|
+ ["1234 ¥", [{'post_currency': '¥', 'pre_value': '1234'}]],
|
|
|
+ ["1.23 US$", [{'post_currency': 'US$', 'pre_value': '1.23'}]],
|
|
|
+ ["1.23 €", [{'post_currency': '€', 'pre_value': '1.23'}]],
|
|
|
+ ["US$ 0,50", [{'pre_currency': 'US$', 'post_value': '0,50'}]],
|
|
|
+ ["€ 0,50", [{'pre_currency': '€', 'post_value': '0,50'}]],
|
|
|
+ ["¥1234", [{'pre_currency': '¥', 'post_value': '1234'}]],
|
|
|
+ ["US$ 1.23", [{'pre_currency': 'US$', 'post_value': '1.23'}]],
|
|
|
+ ["€1.23", [{'pre_currency': '€', 'post_value': '1.23'}]],
|
|
|
+])
|
|
|
+def test_sum_regex(haystack, expected_needles):
|
|
|
+ matches = re.finditer(
|
|
|
+ finoex.Sum.sum_regex,
|
|
|
+ haystack,
|
|
|
+ )
|
|
|
+ attr = [{k: v for k, v in m.groupdict().items() if v is not None}
|
|
|
+ for m in matches]
|
|
|
+ assert expected_needles == attr
|