extract: Fill YAML with Python values, not PS/FDF values.

This commit is contained in:
Brett Smith 2021-01-09 13:20:15 -05:00
parent 6a3d64ff22
commit 8b2633ec23
4 changed files with 79 additions and 2 deletions

View file

@ -91,7 +91,7 @@ class FormExtractor:
'name': name, 'name': name,
}, },
'description': f'{field_type} {name}', 'description': f'{field_type} {name}',
'value': field.fill_value(), 'value': field.value(),
} }
if isinstance(field, fieldmod.CheckboxField): if isinstance(field, fieldmod.CheckboxField):
retval['fdf']['options'] = field.options() retval['fdf']['options'] = field.options()

View file

@ -5,7 +5,7 @@ from setuptools import setup
setup( setup(
name='conservancy_beancount', name='conservancy_beancount',
description="Plugin, library, and reports for reading Conservancy's books", description="Plugin, library, and reports for reading Conservancy's books",
version='1.15.1', version='1.15.2',
author='Software Freedom Conservancy', author='Software Freedom Conservancy',
author_email='info@sfconservancy.org', author_email='info@sfconservancy.org',
license='GNU AGPLv3+', license='GNU AGPLv3+',

View file

@ -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

View file

@ -46,6 +46,15 @@ def test_extract_from_file(fdf_filename, form_key, fields_yaml):
actual = extractor.extract() actual = extractor.extract()
compare_to_yaml(actual, fields_yaml, fdf_filename, form_key) 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', [ @pytest.mark.parametrize('fdf_filename,form_key,fields_yaml', [
('form1.fdf', 'FDF', 'form1.yml'), ('form1.fdf', 'FDF', 'form1.yml'),
]) ])