From: Henryk Plötz Date: Wed, 8 Aug 2018 17:59:31 +0000 (+0200) Subject: Automatically trim ValueList with non-fixed length to minimum length (change tests... X-Git-Tag: v2.0.0~1^2~145 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4ce9462ad05bb49b4f34be76f6a3c48681c18454;p=thirdparty%2Fpython-fints.git Automatically trim ValueList with non-fixed length to minimum length (change tests to reflect that behaviour) --- diff --git a/fints/formals.py b/fints/formals.py index a3fa818..7695b74 100644 --- a/fints/formals.py +++ b/fints/formals.py @@ -51,7 +51,17 @@ class ValueList: if self._parent.count is not None: return self._parent.count else: - retval = len(self._data) + retval = 0 + for i, val in enumerate(self._data): + if isinstance(val, Container): + if val.is_unset(): + continue + elif isinstance(val, ValueList): + if len(val) == 0: + continue + elif val is None: + continue + retval = i+1 if self._parent.min_count is not None: if self._parent.min_count > retval: retval = self._parent.min_count diff --git a/tests/test_formals.py b/tests/test_formals.py index 42b1539..19b8762 100644 --- a/tests/test_formals.py +++ b/tests/test_formals.py @@ -90,7 +90,7 @@ def test_container_count_variable_1(): assert i1.a[1] is None assert i1.a[3] is None - assert len(i1.a) == 4 + assert len(i1.a) == 2 with pytest.raises(IndexError): i1.a[5] @@ -114,7 +114,7 @@ def test_container_count_variable_1(): assert i1.a[4] is None - assert len(i1.a) == 5 + assert len(i1.a) == 4 def test_container_count_variable_2(): class A(Container):