def test_invalid_values(data: DataObject,
                        bases_invalid_values: Tuple[Strategy[Bases],
                                                    Strategy[Any]],
                        keys: Strategy[str]) -> None:
    bases, invalid_values = bases_invalid_values

    result = factory(bases=bases, keys=keys, values=invalid_values, min_size=1)

    with pytest.raises(TypeError):
        data.draw(result)
Esempio n. 2
0
def enums_factory(*,
                  values: Strategy[str] = sql_identifiers,
                  min_size: int = 1,
                  max_size: Optional[int] = None) -> Strategy[TypeEngine]:
    enums_keys = values.filter(enumerable.is_valid_key)
    return ((strategies.tuples(
        enumerable.factory(
            keys=enums_keys, min_size=min_size, max_size=max_size))
             | strategies.lists(values, min_size=min_size, max_size=max_size)
             ).map(lambda type_values: Enum(*type_values)))
def test_basic(bases_values: Tuple[Strategy[strategies.Bases],
                                   Strategy[Any]], keys: Strategy[str],
               min_size: int, max_size: Optional[int]) -> None:
    bases, values = bases_values

    result = factory(bases=bases,
                     keys=keys,
                     values=values,
                     min_size=min_size,
                     max_size=max_size)

    assert isinstance(result, Strategy)
def test_example(data: DataObject,
                 bases_values: Tuple[Strategy[strategies.Bases],
                                     Strategy[Any]], keys: Strategy[str],
                 min_size: int, max_size: Optional[int]) -> None:
    bases, values = bases_values
    strategy = factory(bases=bases,
                       keys=keys,
                       values=values,
                       min_size=min_size,
                       max_size=max_size)

    result = data.draw(strategy)

    assert isinstance(result, EnumMeta)
    # not checking `len` because of aliases
    assert min_size <= len(result.__members__)
    assert max_size is None or len(result.__members__) <= max_size
def test_unique_by(data: DataObject,
                   bases_values_unique_by: Tuple[Strategy[Bases],
                                                 Strategy[Any], UniqueBy],
                   keys: Strategy[str], min_size: int,
                   max_size: Optional[int]) -> None:
    bases, values, unique_by = bases_values_unique_by
    strategy = factory(bases=bases,
                       keys=keys,
                       values=values,
                       min_size=min_size,
                       max_size=max_size,
                       unique_by=unique_by)

    result = data.draw(strategy)

    assert isinstance(result, EnumMeta)
    assert min_size <= len(result)
    assert max_size is None or len(result) <= max_size
def test_invalid_keys_values(data: DataObject, keys: Strategy[str]) -> None:
    strategy = factory(keys=keys, min_size=1)

    with pytest.raises(ValueError):
        data.draw(strategy)