From 8b2633ec23e01c8eb74eee91f1b77745dea3a861 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Sat, 9 Jan 2021 13:20:15 -0500 Subject: [PATCH] extract: Fill YAML with Python values, not PS/FDF values. --- conservancy_beancount/pdfforms/extract.py | 2 +- setup.py | 2 +- tests/pdfforms/form1_fill.fdf | 68 +++++++++++++++++++++++ tests/test_pdfforms_extract.py | 9 +++ 4 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/pdfforms/form1_fill.fdf diff --git a/conservancy_beancount/pdfforms/extract.py b/conservancy_beancount/pdfforms/extract.py index 3ed18ae..01c7921 100644 --- a/conservancy_beancount/pdfforms/extract.py +++ b/conservancy_beancount/pdfforms/extract.py @@ -91,7 +91,7 @@ class FormExtractor: 'name': name, }, 'description': f'{field_type} {name}', - 'value': field.fill_value(), + 'value': field.value(), } if isinstance(field, fieldmod.CheckboxField): retval['fdf']['options'] = field.options() diff --git a/setup.py b/setup.py index bfef667..c2b7897 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.15.1', + version='1.15.2', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/pdfforms/form1_fill.fdf b/tests/pdfforms/form1_fill.fdf new file mode 100644 index 0000000..0e75683 --- /dev/null +++ b/tests/pdfforms/form1_fill.fdf @@ -0,0 +1,68 @@ +%FDF-1.2 +%âãÏÓ +1 0 obj +<< +/FDF +<< +/Fields [ +<< +/T (topform) +/Kids [ + << + /T (text1_0) + /FT /Tx + /V (text 1.0) + >> + << + /T (button1) + /Kids [ + << + /FT /Btn + /T (button1_0) + /AP << /N << /1 1 0 R >> >> + /V /1 + >> + << + /FT /Btn + /T (button1_1) + /AP << /N << /2 1 0 R >> >> + >> + ] + >> + << + /T (text1_1) + /FT /Tx + /V (text 1.1) + >> + << + /T (text2_0) + /FT /Tx + /V (text 2.0) + >> + << + /T (button2) + /Kids [ + << + /FT /Btn + /T (button2_0) + /AP << /N << /1 1 0 R >> >> + >> + << + /FT /Btn + /T (button2_1) + /AP << /N << /2 1 0 R >> >> + /V /2 + >> + ] + >> +] +>>] +>> +>> +endobj +trailer + +<< +/Root 1 0 R +>> +%%EOF diff --git a/tests/test_pdfforms_extract.py b/tests/test_pdfforms_extract.py index dbacd48..1f6180a 100644 --- a/tests/test_pdfforms_extract.py +++ b/tests/test_pdfforms_extract.py @@ -46,6 +46,15 @@ def test_extract_from_file(fdf_filename, form_key, fields_yaml): actual = extractor.extract() compare_to_yaml(actual, fields_yaml, fdf_filename, form_key) +@pytest.mark.parametrize('fdf_filename,form_key,fields_yaml', [ + ('form1_fill.fdf', 'FDF', 'form1_fill.yml'), +]) +def test_extract_from_file(fdf_filename, form_key, fields_yaml): + with testutil.test_path(f'pdfforms/{fdf_filename}').open('rb') as fdf_file: + extractor = extractmod.FormExtractor.from_file(fdf_file) + actual = extractor.extract() + compare_to_yaml(actual, fields_yaml, fdf_filename, form_key) + @pytest.mark.parametrize('fdf_filename,form_key,fields_yaml', [ ('form1.fdf', 'FDF', 'form1.yml'), ])