How to use the fints.formals.NumericField function in fints

To help you get started, we’ve selected a few fints examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github raphaelm / python-fints / tests / test_formals.py View on Github external
def test_container_count_exact():
    class A(Container):
        a = NumericField(count=2)

    i1 = A()

    assert len(i1.a) == 2

    assert i1.a[0] is None
    assert i1.a[1] is None

    with pytest.raises(IndexError):
        i1.a[2]

    with pytest.raises(IndexError):
        i1.a[2] = 1

    with pytest.raises(IndexError):
        i1.a[-1]
github raphaelm / python-fints / tests / test_formals.py View on Github external
def test_unset():
    class A(Container):
        a = NumericField()

    class B(Container):
        b = ContainerField(type=A)
        c = NumericField()

    assert A().is_unset()
    assert not A(a=1).is_unset()
    assert A(a=None).is_unset()

    assert B().is_unset()
    assert B(b=A()).is_unset()
    assert not B(c=1).is_unset()
github raphaelm / python-fints / tests / test_formals.py View on Github external
def test_container_nested():
    class A(Container):
        a = NumericField()

    class B(Container):
        b = DataElementGroupField(type=A)

    i1 = B()
    assert isinstance(i1.b, A)

    i1.b.a = '1'
    assert i1.b.a == 1
github raphaelm / python-fints / tests / test_formals.py View on Github external
def test_container_naive_parse():
    class A(Container):
        a = NumericField()
        b = DigitsField()

    i1 = A.naive_parse(['23', '42'])

    assert i1.a == 23
    assert i1.b == '42'
github raphaelm / python-fints / tests / test_models.py View on Github external
def test_fints3_only_de_and_deg():
    from fints.formals import Field, Container, DataElementGroupField

    with pytest.raises(TypeError, match="b=.* is not DataElementField or DataElementGroupField"):
        class Foo(FinTS3Segment):
            a = NumericField()
            b = Field()

    class A(Container):
        a = Field()

    class B(Container):
        b = DataElementGroupField(type=A)

    with pytest.raises(TypeError, match="a=.* is not DataElementField or DataElementGroupField"):
        class Foo(FinTS3Segment):
            c = DataElementGroupField(type=B)
github raphaelm / python-fints / tests / test_message_parser.py View on Github external
def test_parse_counted():
    from fints.segments.base import FinTS3Segment
    from fints.formals import NumericField, Container, ContainerField

    class ITST1(FinTS3Segment):
        a = NumericField(count=3)

    m1 = FinTS3Parser().parse_message(b"ITST:1:1+1+2+3'")
    assert m1.segments[0].header.type == 'ITST'
    assert len(m1.segments[0].a) == 3
    assert m1.segments[0].a[0] == 1
    assert m1.segments[0].a[1] == 2
    assert m1.segments[0].a[2] == 3

    class ITST2(FinTS3Segment):
        a = NumericField(max_count=3)

    m2 = FinTS3Parser().parse_message(b"ITST:1:2+1+2+3'")
    assert m2.segments[0].a[2] == 3

    m3 = FinTS3Parser().parse_message(b"ITST:1:2+1+2+3+4'")
    assert m3.segments[0]._additional_data == ['4']
github raphaelm / python-fints / tests / test_models.py View on Github external
def test_segment_subclassing():
    class Base1(FinTS3Segment):
        a = NumericField()

    class Base2(Base1):
        b = NumericField()

    class ISUBTST1(Base2):
        c = NumericField()

    assert list(ISUBTST1._fields.keys()) == ['header', 'a', 'b', 'c']
github raphaelm / python-fints / tests / test_formals.py View on Github external
def test_container_count_variable_1():
    class A(Container):
        a = NumericField(min_count=2, max_count=5)

    i1 = A()

    assert len(i1.a) == 2

    assert i1.a[0] is None
    assert i1.a[1] is None
    assert i1.a[3] is None

    assert len(i1.a) == 2

    with pytest.raises(IndexError):
        i1.a[5]

    with pytest.raises(IndexError):
        i1.a[5] = 1
github raphaelm / python-fints / tests / test_models.py View on Github external
def test_segment_subclassing():
    class Base1(FinTS3Segment):
        a = NumericField()

    class Base2(Base1):
        b = NumericField()

    class ISUBTST1(Base2):
        c = NumericField()

    assert list(ISUBTST1._fields.keys()) == ['header', 'a', 'b', 'c']
github raphaelm / python-fints / tests / test_formals.py View on Github external
def test_valuelist_repr():
    class A(Container):
        a = NumericField(max_count=3)

    i1 = A()
    assert repr(i1.a) == "[]"