Browse Source

added failing ing-diba test case

Fabian Peter Hammerle 8 years ago
parent
commit
60ff8a4d62
2 changed files with 12 additions and 5 deletions
  1. 5 5
      dingguo/parser/ingdiba.py
  2. 7 0
      tests/test_parser_ingdiba.py

+ 5 - 5
dingguo/parser/ingdiba.py

@@ -34,10 +34,10 @@ def ingdiba_pdf_file_to_text(pdf_file):
     interpreter.process_page(page)
 
     chars = {}
-    for char in device.get_result():
-        if isinstance(char, pdfminer.layout.LTChar):
-            if not char.y0 in chars:
-                chars[char.y0] = {}
-            chars[char.y0][char.x0] = char.get_text()
+    for ltchar in device.get_result():
+        if isinstance(ltchar, pdfminer.layout.LTChar):
+            if not ltchar.y0 in chars:
+                chars[ltchar.y0] = {}
+            chars[ltchar.y0][ltchar.x0] = ltchar.get_text()
 
     return '\n'.join([''.join([chars[y0][x0] for x0 in sorted(chars[y0])]) for y0 in sorted(chars)[::-1]]) + '\n'

+ 7 - 0
tests/test_parser_ingdiba.py

@@ -38,6 +38,13 @@ def test_ingdiba_pdf_file_to_text_loss_compensation():
         with open(os.path.join(test_data_path, os.path.splitext(pdf_name)[0] + '.txt')) as text_file:
             assert dingguo.parser.ingdiba.ingdiba_pdf_file_to_text(pdf_file) == text_file.read().decode('utf-8')
 
+@pytest.mark.xfail(raises=IndexError)
+def test_ingdiba_pdf_file_to_text_loss_compensation_single_page():
+    pdf_name = 'ING-DiBa_Postbox_2016-04-28_Verlustausgleich.pdf'
+    with open(os.path.join(test_data_path, pdf_name)) as pdf_file:
+        with open(os.path.join(test_data_path, os.path.splitext(pdf_name)[0] + '.txt')) as text_file:
+            assert dingguo.parser.ingdiba.ingdiba_pdf_file_to_text(pdf_file) == text_file.read().decode('utf-8')
+
 def test_ingdiba_pdf_file_to_text_dividend_distribution():
     pdf_name = 'ING-DiBa_Postbox_2014-04-09_Jährl. Bestätigung Ausschüttung Fonds.pdf'
     with open(os.path.join(test_data_path, pdf_name)) as pdf_file: