Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]
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()
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
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'
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)
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']
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']
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
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']
def test_valuelist_repr():
class A(Container):
a = NumericField(max_count=3)
i1 = A()
assert repr(i1.a) == "[]"