Ejemplo n.º 1
0
 def _normalize(self, data):
     if len(data) == 2 and isinstance(data[1], tuple) or len(data) > 2:
         if not isinstance(data[0], tuple):
             new_struct = ndict({0: (data[0], self._normalize(data[1]))})
         else:
             new_struct = self.ordered_dict(data, use_n_dict=True)
         for i in range(len(new_struct)):
             value = new_struct.get(i)
             if is_nested_tuple(value):
                 new_struct[i] = (value[0], self._normalize(value[1]))
         if hasattr(data, 'must_validate'):
             new_struct.must_validate = data.must_validate
         return new_struct
     else:
         new_struct = ndict({0: data})
         if hasattr(data, 'must_validate'):
             new_struct.must_validate = data.must_validate
         return new_struct
Ejemplo n.º 2
0
 def _normalize(self, data):
     if len(data) == 2 and isinstance(data[1], tuple) or len(data) > 2:
         if not isinstance(data[0], tuple):
             new_struct = ndict({0: (data[0], self._normalize(data[1]))})
         else:
             new_struct = self.ordered_dict(data, use_n_dict=True)
         for i in range(len(new_struct)):
             value = new_struct.get(i)
             if is_nested_tuple(value):
                 new_struct[i] = (value[0], self._normalize(value[1]))
         if hasattr(data, 'must_validate'):
             new_struct.must_validate = data.must_validate
         return new_struct
     else:
         new_struct = ndict({0: data})
         if hasattr(data, 'must_validate'):
             new_struct.must_validate = data.must_validate
         return new_struct
Ejemplo n.º 3
0
 def test_second_value_is_not_typle(self):
     value = ('a', 'b')
     assert utils.is_nested_tuple(value) is False
Ejemplo n.º 4
0
 def test_is_single_tuple(self):
     value = (1, )
     assert utils.is_nested_tuple(value) is False
Ejemplo n.º 5
0
 def test_is_nested_tuple(self):
     value = (1, (1, 2))
     assert utils.is_nested_tuple(value) is True
Ejemplo n.º 6
0
 def test_second_value_is_not_typle(self):
     value = ("a", "b")
     assert utils.is_nested_tuple(value) is False
Ejemplo n.º 7
0
 def test_is_single_tuple(self):
     value = (1,)
     assert utils.is_nested_tuple(value) is False
Ejemplo n.º 8
0
 def test_is_nested_tuple(self):
     value = (1, (1, 2))
     assert utils.is_nested_tuple(value) is True