Changeset - 6a3d64ff2250
[Not reviewed]
0 3 0
Brett Smith - 3 years ago 2021-01-09 15:49:04
brettcsmith@brettcsmith.org
fields: Change FieldType capitalization.

This is friendlier to the YAML input and consistent with FieldFlags.
Less consistent with the rest of the codebase, but local consistency matters
more IMO.
3 files changed with 10 insertions and 11 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/pdfforms/fields.py
Show inline comments
...
 
@@ -50,20 +50,19 @@ class FieldFlags(enum.IntFlag):
 
    Comb = 2 ** 24
 
    RichText = 2 ** 25
 

	
 

	
 
class FieldType(enum.Enum):
 
    Btn = 'Btn'
 
    BUTTON = Btn
 
    Button = Btn
 
    Ch = 'Ch'
 
    CHOICE = Ch
 
    Choice = Ch
 
    Sig = 'Sig'
 
    SIG = Sig
 
    SIGNATURE = Sig
 
    Signature = Sig
 
    Tx = 'Tx'
 
    TEXT = Tx
 
    Text = Tx
 

	
 

	
 
class FormField:
 
    __slots__ = ['_source']
 
    _SENTINEL = object()
 
    DEFAULT_FILL: object = None
...
 
@@ -84,20 +83,20 @@ class FormField:
 
        retval = cls(source)
 
        try:
 
            field_type = retval.field_type()
 
        except ValueError:
 
            return retval
 
        flags = retval.flags()
 
        if field_type is FieldType.BUTTON:
 
        if field_type is FieldType.Button:
 
            if flags & FieldFlags.Radio:
 
                pass
 
            elif flags & FieldFlags.Pushbutton:
 
                pass
 
            else:
 
                retval.__class__ = CheckboxField
 
        elif field_type is FieldType.TEXT:
 
        elif field_type is FieldType.Text:
 
            retval.__class__ = TextField
 
        return retval
 

	
 
    def _get_value(self, key: str, default: Any=_SENTINEL) -> Any:
 
        can_inherit = key in self.INHERITABLE
 
        source: Optional[FieldSource] = self._source
setup.py
Show inline comments
...
 
@@ -2,13 +2,13 @@
 

	
 
from setuptools import setup
 

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

	
 
    install_requires=[
 
        'babel>=2.6',  # Debian:python3-babel
tests/test_pdfforms_fields.py
Show inline comments
...
 
@@ -62,21 +62,21 @@ def test_empty_field():
 
    with pytest.raises(ValueError):
 
        field.field_type()
 

	
 
def test_text_field_base():
 
    source = field_source(b's', b'string of text', 'Tx')
 
    field = fieldsmod.FormField(source)
 
    assert field.field_type() is fieldsmod.FieldType.TEXT
 
    assert field.field_type() is fieldsmod.FieldType.Text
 
    assert field.name() == 's'
 
    assert field.value() == b'string of text'
 

	
 
@pytest.mark.parametrize('value', ['Off', 'Yes', 'On'])
 
def test_checkbox_field_base(value):
 
    source = field_source(b'cb', value, 'Btn', literal=True)
 
    field = fieldsmod.FormField(source)
 
    assert field.field_type() is fieldsmod.FieldType.BUTTON
 
    assert field.field_type() is fieldsmod.FieldType.Button
 
    assert field.name() == 'cb'
 
    assert field.value().name == value
 

	
 
@pytest.mark.parametrize('flags', range(4))
 
def test_readonly_flag(flags):
 
    source = field_source(flags=flags)
...
 
@@ -111,13 +111,13 @@ def test_inheritance():
 
    parent = field.parent()
 
    assert parent is not None
 
    assert parent.name() == 'parent'
 
    assert not parent.is_terminal()
 
    assert field.is_terminal()
 
    assert field.name() == 'kid'
 
    assert field.field_type() is fieldsmod.FieldType.TEXT
 
    assert field.field_type() is fieldsmod.FieldType.Text
 
    assert field.value() == 'parent value'
 
    assert field.flags() == 17
 
    assert not list(field.kids())
 

	
 
@pytest.mark.parametrize('field_type,value', [
 
    ('Tx', b'new value'),
0 comments (0 inline, 0 general)