Various regression tests for pyffi.object_models.array_type.

ValidatedList
=============

>>> from pyffi.object_models.array_type import ValidatedList
>>> class IntList(ValidatedList):
...     def validate(self, item):
...         if not isinstance(item, int):
...             raise TypeError("item must be int")
>>> x = IntList([1,2,3.0]) # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...
>>> x = IntList([1,2,3])
>>> x[0] = "a" # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...
>>> x[0] = 10
>>> x[0]
10
>>> x.append(3.14) # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...
>>> x.append(314)
>>> len(x)
4
>>> x[-1]
314
>>> x.extend([1,2,3,4,"woops"]) # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...
>>> x.extend([1,2,3,4,0])
>>> len(x)
9
>>> x[-2:]
[4, 0]

AnyArray
========

Elements must be AnyType
------------------------

>>> from pyffi.object_models.array_type import UniformArray
>>> class ListOfInts(UniformArray):
...     ItemType = int # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...
>>> from pyffi.object_models.simple_type import SimpleType
>>> class MyInt(SimpleType):
...     pass
>>> class ListOfInts(UniformArray):
...     ItemType = MyInt

UniformArray
============

The append method
-----------------

>>> from pyffi.object_models.array_type import UniformArray
>>> from pyffi.object_models.simple_type import SimpleType
>>> class MyInt(SimpleType):
...     def __init__(self, value=0):
...         self._value = value
>>> class ListOfInts(UniformArray):
...     ItemType = MyInt
>>> testlist = ListOfInts()
>>> # append an item
>>> #   item must be type testlist.ItemType, try with invalid type
>>> testlist.append(0) # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
TypeError: ...
>>> #   now with valid type
>>> x = MyInt(value=123)
>>> testlist.append(x)
>>> print(testlist)
MyInt array:
  [00] 123
<BLANKLINE>

The extend method
-----------------

>>> from pyffi.object_models.array_type import UniformArray
>>> from pyffi.object_models.simple_type import SimpleType
>>> class MyInt(SimpleType):
...     def __init__(self, value=0):
...         self._value = value
>>> class ListOfInts(UniformArray):
...     ItemType = MyInt
>>> testlist = ListOfInts()
>>> testlist.extend([MyInt(value=val) for val in range(2, 10, 2)])
>>> print(testlist)
MyInt array:
  [00] 2
  [01] 4
  [02] 6
  [03] 8
<BLANKLINE>


