<commit_before>"""Tests for dumping."""
from typing import Any, EnumMeta, Type

from attr import asdict, astuple
from cattr.converters import Converter, UnstructureStrategy

from hypothesis import given
from hypothesis.strategies import sampled_from, data


from . import (
    dicts_of_primitives,
    enums_of_primitives,
    nested_classes,
    seqs_of_primitives,
    sets_of_primitives,
    simple_classes,
)


unstruct_strats = sampled_from(
    [UnstructureStrategy.AS_DICT, UnstructureStrategy.AS_TUPLE]
)

# Primitive stuff first.


@given(seqs_of_primitives, unstruct_strats)
def test_seq_unstructure(seq_and_type, dump_strat):
    # type: (Any, UnstructureStrategy) -> None
    """Dumping a sequence of primitives is a simple copy operation."""
    converter = Converter(unstruct_strat=dump_strat)
    assert converter.unstruct_strat is dump_strat
    seq = seq_and_type[0]
    dumped = converter.unstructure(seq)
    assert dumped == seq
    if not isinstance(seq, tuple):
        assert dumped is not seq
    assert type(dumped) is type(seq)


@given(sets_of_primitives, unstruct_strats)
def test_set_unstructure(set_and_type, dump_strat):
    # type: (Any, UnstructureStrategy) -> None
    """Dumping a set of primitives is a simple copy operation."""
    converter = Converter(unstruct_strat=dump_strat)
    assert converter.unstruct_strat is dump_strat
    set = set_and_type[0]
    dumped = converter.unstructure(set)
    assert dumped == set
    if set:
        assert dumped is not set
    assert type(dumped) is type(set)


@given(dicts_of_primitives, unstruct_strats)
def test_mapping_unstructure(map_and_type, dump_strat):
    # type: (Any, UnstructureStrategy) -> None
    """Dumping a mapping of primitives is a simple copy operation."""
    converter = Converter(unstruct_strat=dump_strat)
    mapping = map_and_type[0]
    dumped = converter.unstructure(mapping)
    assert dumped == mapping
    assert dumped is not mapping
    assert type(dumped) is type(mapping)


@given(enums_of_primitives(), unstruct_strats, data())
def test_enum_unstructure(enum, dump_strat, data):
    # type: (EnumMeta, UnstructureStrategy) -> None
    """Dumping enums of primitives converts them to their primitives."""
    converter = Converter(unstruct_strat=dump_strat)
<commit_msg>Remove type annotation to simplify.<commit_after>"""Tests for dumping."""
from typing import Any, Type

from attr import asdict, astuple
from cattr.converters import Converter, UnstructureStrategy

from hypothesis import given
from hypothesis.strategies import sampled_from, data


from . import (
    dicts_of_primitives,
    enums_of_primitives,
    nested_classes,
    seqs_of_primitives,
    sets_of_primitives,
    simple_classes,
)


unstruct_strats = sampled_from(
    [UnstructureStrategy.AS_DICT, UnstructureStrategy.AS_TUPLE]
)

# Primitive stuff first.


@given(seqs_of_primitives, unstruct_strats)
def test_seq_unstructure(seq_and_type, dump_strat):
    # type: (Any, UnstructureStrategy) -> None
    """Dumping a sequence of primitives is a simple copy operation."""
    converter = Converter(unstruct_strat=dump_strat)
    assert converter.unstruct_strat is dump_strat
    seq = seq_and_type[0]
    dumped = converter.unstructure(seq)
    assert dumped == seq
    if not isinstance(seq, tuple):
        assert dumped is not seq
    assert type(dumped) is type(seq)


@given(sets_of_primitives, unstruct_strats)
def test_set_unstructure(set_and_type, dump_strat):
    # type: (Any, UnstructureStrategy) -> None
    """Dumping a set of primitives is a simple copy operation."""
    converter = Converter(unstruct_strat=dump_strat)
    assert converter.unstruct_strat is dump_strat
    set = set_and_type[0]
    dumped = converter.unstructure(set)
    assert dumped == set
    if set:
        assert dumped is not set
    assert type(dumped) is type(set)


@given(dicts_of_primitives, unstruct_strats)
def test_mapping_unstructure(map_and_type, dump_strat):
    # type: (Any, UnstructureStrategy) -> None
    """Dumping a mapping of primitives is a simple copy operation."""
    converter = Converter(unstruct_strat=dump_strat)
    mapping = map_and_type[0]
    dumped = converter.unstructure(mapping)
    assert dumped == mapping
    assert dumped is not mapping
    assert type(dumped) is type(mapping)


@given(enums_of_primitives(), unstruct_strats, data())
def test_enum_unstructure(enum, dump_strat, data):
    """Dumping enums of primitives converts them to their primitives."""
    converter = Converter(unstruct_strat=dump_strat)

{'fraction_non_alphanumeric': 0.0830396475770925, 'fraction_numerical': 0.0013215859030837004, 'mean_word_length': 4.5513447432762835, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7429327', 'n_tokens_mistral': 1511, 'n_tokens_neox': 1424, 'n_words': 379}