From 4ce9462ad05bb49b4f34be76f6a3c48681c18454 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Henryk=20Pl=C3=B6tz?= Date: Wed, 8 Aug 2018 19:59:31 +0200 Subject: [PATCH] Automatically trim ValueList with non-fixed length to minimum length (change tests to reflect that behaviour) --- fints/formals.py | 12 +++++++++++- tests/test_formals.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) 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): -- 2.47.2