Ejemplo n.º 1
0
def test_field_name():
    assert FieldTypes.list().name == 'List'
    assert FieldTypes.list(FieldTypes.int64, FieldTypes.float32).name == 'List[Int64, Float32]'
    assert FieldTypes.tuple(FieldTypes.int8, ...).name == 'Tuple[Int8, ...]'
    assert FieldTypes.tuple(FieldTypes.int8).name == 'Tuple[Int8, ...]'
    assert FieldTypes.dict().name == 'Dict'
    assert FieldTypes.dict(FieldTypes.int8, FieldTypes.float64).name == 'Dict[Int8, Float64]'
Ejemplo n.º 2
0
    [FieldTypes.dtype, [np.dtype(np.int32), pd.StringDtype()], [object()]],
    [FieldTypes.key, [MyClass()], [object()]],
    [FieldTypes.slice, [slice(1, 10), slice('a', 'b')], [object()]],
    [FieldTypes.datetime, [datetime.now(), pd.Timestamp(0)], [object()]],
    [FieldTypes.timedelta, [timedelta(days=1), pd.Timedelta(days=1)], [object()]],
    [FieldTypes.tzinfo, [timezone.utc], [object()]],
    [FieldTypes.index, [pd.RangeIndex(10), pd.Index([1, 2])], [object()]],
    [FieldTypes.series, [pd.Series([1, 2, 3])], [object()]],
    [FieldTypes.dataframe, [pd.DataFrame({'a': [1, 2]})], [object()]],
    [FieldTypes.interval_array, [pd.arrays.IntervalArray([])], [object()]],
    [FieldTypes.function, [MyClass.my_func], [object()]],
    [FieldTypes.namedtuple, [my_named_tuple(a=1, b=2)], [tuple()]],
    [FieldTypes.reference(MyClass), [MyClass()], [object()]],
    [FieldTypes.tuple(FieldTypes.int64, ...), [tuple(), tuple([1, 2])], [list(), tuple([1, 2.])]],
    [FieldTypes.list(FieldTypes.int64, FieldTypes.float64), [[1, 1.]], [tuple(), [1, 1]]],
    [FieldTypes.dict(FieldTypes.string, FieldTypes.int64), [{'a': 1}], [{1: 'a'}, {'a': 1.}]],
    [FieldTypes.any, [object()], []],
]


@pytest.mark.parametrize(
    'field_type, valid_values, invalid_values',
    fields_values
)
def test_field_type(field_type, valid_values, invalid_values):
    assert isinstance(field_type.type_name, str)
    assert isinstance(field_type.name, str)

    for valid_value in valid_values:
        field_type.validate(valid_value)
Ejemplo n.º 3
0
    [FieldTypes.dataframe, [pd.DataFrame({'a': [1, 2]})], [object()]],
    [FieldTypes.interval_array, [pd.arrays.IntervalArray([])], [object()]],
    [FieldTypes.function, [MyClass.my_func], [object()]],
    [FieldTypes.namedtuple, [my_named_tuple(a=1, b=2)], [tuple()]],
    [FieldTypes.reference(MyClass), [MyClass()], [object()]],
    [
        FieldTypes.tuple(FieldTypes.int64, ...), [tuple(),
                                                  tuple([1, 2])],
        [list(), tuple([1, 2.])]
    ],
    [
        FieldTypes.list(FieldTypes.int64, FieldTypes.float64), [[1, 1.]],
        [tuple(), [1, 1]]
    ],
    [
        FieldTypes.dict(FieldTypes.string, FieldTypes.int64), [{
            'a': 1
        }], [{
            1: 'a'
        }, {
            'a': 1.
        }]
    ],
    [FieldTypes.any, [object()], []],
]


@pytest.mark.parametrize('field_type, valid_values, invalid_values',
                         fields_values)
def test_field_type(field_type, valid_values, invalid_values):
    assert isinstance(field_type.type_name, str)