Browse Source

Sum.sum_regex_value_first: space between value and currency is now optional

Fabian Peter Hammerle 6 years ago
parent
commit
9bacce5573
3 changed files with 14 additions and 4 deletions
  1. 2 2
      finoex/__init__.py
  2. 2 2
      setup.py
  3. 10 0
      tests/test_sum.py

+ 2 - 2
finoex/__init__.py

@@ -95,8 +95,8 @@ class Sum(ioex.calcex.Figure):
 
     space_regex = '[\xa0 ]'
     value_regex = r"-?\d+([\.,]\d+)?"
-    currency_regex = r"[^\d\s-]+"
-    sum_regex_value_first = r'\$?(?P<value>{}){}(?P<currency>{})'.format(
+    currency_regex = r"[^\d,\.\s-]+"
+    sum_regex_value_first = r'\$?(?P<value>{}){}?(?P<currency>{})'.format(
         value_regex, space_regex, currency_regex,
     )
     sum_regex_currency_first = r'(?P<currency>{}){}?(?P<value>{})'.format(

+ 2 - 2
setup.py

@@ -4,12 +4,12 @@ import glob
 
 setup(
     name = 'finoex',
-    version = '0.14.0',
+    version = '0.14.1',
     # description = '',
     author = 'Fabian Peter Hammerle',
     author_email = 'fabian.hammerle@gmail.com',
     url = 'https://git.hammerle.me/fphammerle/finoex',
-    download_url = 'https://git.hammerle.me/fphammerle/finoex/archive/0.14.0.tar.gz',
+    download_url = 'https://git.hammerle.me/fphammerle/finoex/archive/0.14.1.tar.gz',
     keywords = ['finances'],
     # classifiers = [],
     packages = ['finoex'],

+ 10 - 0
tests/test_sum.py

@@ -85,9 +85,12 @@ def test_mul(dividend, divisor, quotient):
 
 
 @pytest.mark.parametrize(('loc', 'text', 'expected_sum'), [
+    ['de_AT.UTF-8', "-1,23 US$", finoex.Sum(-1.23, 'USD')],
     ['de_AT.UTF-8', "-1,23 USD", finoex.Sum(-1.23, 'USD')],
+    ['de_AT.UTF-8', "-1,23US$", finoex.Sum(-1.23, 'USD')],
     ['de_AT.UTF-8', "2,50 EUR", finoex.Sum(2.5, 'EUR')],
     ['de_AT.UTF-8', "2,50 €", finoex.Sum(2.5, 'EUR')],
+    ['de_AT.UTF-8', "2,50EUR", finoex.Sum(2.5, 'EUR')],
     ['de_AT.UTF-8', "EUR 1234,56", finoex.Sum(1234.56, 'EUR')],
     ['de_AT.UTF-8', "US$ 0,50", finoex.Sum(0.5, 'USD')],
     ['de_AT.UTF-8', "US$0,50", finoex.Sum(0.5, 'USD')],
@@ -98,9 +101,12 @@ def test_mul(dividend, divisor, quotient):
     ['en_US.UTF-8', "-1.23 USD", finoex.Sum(-1.23, 'USD')],
     ['en_US.UTF-8', "-1.23\xa0USD", finoex.Sum(-1.23, 'USD')],
     ['en_US.UTF-8', "1.23 ¥", finoex.Sum(1.23, 'CNY')],
+    ['en_US.UTF-8', "1.23¥", finoex.Sum(1.23, 'CNY')],
     ['en_US.UTF-8', "2.2 US$", finoex.Sum(2.2, 'US$')],
+    ['en_US.UTF-8', "2.2US$", finoex.Sum(2.2, 'US$')],
     ['en_US.UTF-8', "2.50 EUR", finoex.Sum(2.5, 'EUR')],
     ['en_US.UTF-8', "2.50 €", finoex.Sum(2.5, 'EUR')],
+    ['en_US.UTF-8', "2.50€", finoex.Sum(2.5, 'EUR')],
     ['en_US.UTF-8', "US$-0.50", finoex.Sum(-0.5, 'USD')],
     ['en_US.UTF-8', "\u20ac10.26", finoex.Sum(10.26, 'EUR')],
     ['en_US.UTF-8', "¥1.23", finoex.Sum(1.23, 'CNY')],
@@ -123,12 +129,16 @@ def test_parse_text_fail(text):
 @pytest.mark.parametrize(('haystack', 'expected_needles'), [
     ["Preis: 0,50 US$", [{'currency': 'US$', 'value': '0,50'}]],
     ["Preis: 0,50 €", [{'currency': '€', 'value': '0,50'}]],
+    ["Preis: 0,50US$", [{'currency': 'US$', 'value': '0,50'}]],
+    ["Preis: 0,50€", [{'currency': '€', 'value': '0,50'}]],
     ["Preis: 1234 ¥", [{'currency': '¥', 'value': '1234'}]],
     ["Preis: US$ 0,50", []],
     ["Preis: € 0,50", []],
     ["Preis: ¥1234", []],
     ["price: 1.23 US$", [{'currency': 'US$', 'value': '1.23'}]],
     ["price: 1.23 €", [{'currency': '€', 'value': '1.23'}]],
+    ["price: 1.23US$", [{'currency': 'US$', 'value': '1.23'}]],
+    ["price: 1.23€", [{'currency': '€', 'value': '1.23'}]],
     ["price: US$ 1.23", []],
     ["price: €1.23", []],
 ])