import pytest
from datatyping.datatyping import validate


def test_empty():
    with pytest.raises(TypeError):
        assert validate([], ()) is None


def test_empty_reversed():
    with pytest.raises(TypeError):
        assert validate((), []) is None


def test_plain():
    with pytest.raises(TypeError):
        assert validate([int], (1, 2, 3, 4, 5)) is None


def test_plain_reversed():
    with pytest.raises(TypeError):
        assert validate((int, ), [1, 2, 3, 4, 5]) is None


from types import SimpleNamespace


def test_mapping_empty():
    with pytest.raises(TypeError):
        assert validate([dict], [SimpleNamespace(),
                                 SimpleNamespace(), SimpleNamespace()]) is None


def test_mapping_empty_reversed():
    with pytest.raises(TypeError):
        assert validate([SimpleNamespace], [{}, {}, {}]) is None


def test_dict_nested():
    with pytest.raises(TypeError):
        assert validate([{'a': {'b': [dict]}}],
                        [
            {'a': {'b': [{}, SimpleNamespace()]}},
            {'a': {'b': [{'any': 'key'}, {'used': 'here'}]}},
        ]) is None

from collections import OrderedDict

import pytest
from hypothesis import given
from hypothesis.strategies import lists, tuples, integers, dictionaries, \
    fixed_dictionaries

from datatyping.datatyping import validate


@given(lst=lists(integers()), tpl=tuples(integers()))
def test_different_sequences(lst, tpl):
    with pytest.raises(TypeError):
        if tpl:
            validate([int], tpl)
        else:
            validate([], tpl)

    with pytest.raises(TypeError):
        if lst:
            validate((int), lst)
        else:
            validate((), lst)


@given(dct=dictionaries(integers(), integers()))
def test_different_mappings(dct):
    with pytest.raises(TypeError):
        validate(dict, OrderedDict(dct))
        validate(OrderedDict, dct)


@given(lst=lists(
    fixed_dictionaries({
        'a': fixed_dictionaries({
            'b': lists(
                dictionaries(integers(), integers(), min_size=1),
                min_size=1
            )
        })
    }),
    min_size=1
))
def test_dict_nested(lst):
    assert validate([{'a': {'b': [dict]}}], lst) is None

Rewrite structure_check tests with hypothesis `OrderedDict` chosen instead of `SimpleNamespace` as the former supports the dictionary-like item access, unlike the latter.