]> git.ipfire.org Git - thirdparty/python-fints.git/commitdiff
Automatically trim ValueList with non-fixed length to minimum length (change tests...
authorHenryk Plötz <henryk@ploetzli.ch>
Wed, 8 Aug 2018 17:59:31 +0000 (19:59 +0200)
committerRaphael Michel <mail@raphaelmichel.de>
Mon, 3 Dec 2018 18:34:17 +0000 (19:34 +0100)
fints/formals.py
tests/test_formals.py

index a3fa818730cb51850c17d97f642d034e821c3aee..7695b7446a5b0b81546f3c7166db03bdbff10271 100644 (file)
@@ -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
index 42b15390423e5e59ba7d020f5531c55ab77e8881..19b876227c96b266d0cfd771a2c685959b510c2b 100644 (file)
@@ -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):