Changeset - 8b2633ec23e0
[Not reviewed]
0 3 1
Brett Smith - 3 years ago 2021-01-09 18:20:15
brettcsmith@brettcsmith.org
extract: Fill YAML with Python values, not PS/FDF values.
4 files changed with 79 insertions and 2 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/pdfforms/extract.py
Show inline comments
...
 
@@ -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()
setup.py
Show inline comments
...
 
@@ -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+',
tests/pdfforms/form1_fill.fdf
Show inline comments
 
new file 100644
 
%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
tests/test_pdfforms_extract.py
Show inline comments
...
 
@@ -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'),
 
])
0 comments (0 inline, 0 general)