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)
Beispiel #2
0
def test_extending(data: DataObject, dialect_with_name: Tuple[Dialect, str],
                   metadata: MetaData, min_size: int,
                   max_size: Optional[int]) -> None:
    dialect, name = dialect_with_name

    strategy = factory(dialect=dialect,
                       metadata=metadata,
                       names=strategies.just(name),
                       min_size=min_size,
                       max_size=max_size,
                       extend_existing=strategies.just(True))

    first_result = data.draw(strategy)
    second_result = data.draw(strategy)

    assert first_result == second_result
def test_enum_types_factory(data: DataObject, dialect: Dialect, min_size: int,
                            max_size: Optional[int]) -> None:
    strategy = enums_factory(dialect, min_size=min_size, max_size=max_size)

    result = data.draw(strategy)

    assert isinstance(result, EnumType)
    assert min_size <= len(result.enums)
    assert max_size is None or len(result.enums) <= max_size
Beispiel #4
0
def test_examples(
    data: DataObject,
    table_fixed_columns_values: Tuple[Table, Dict[str,
                                                  Strategy[Any]]]) -> None:
    table, fixed_columns_values = table_fixed_columns_values

    strategy = factory(table, **fixed_columns_values)

    result = data.draw(strategy)

    assert isinstance(result, tuple)
    assert table_record_is_valid(result, table=table)
def test_examples(data: DataObject, metadatas: Strategy[MetaData],
                  min_size: int, max_size: Optional[int]) -> None:
    strategy = factory(metadatas=metadatas,
                       min_size=min_size,
                       max_size=max_size)

    result = data.draw(strategy)

    assert isinstance(result, Table)
    assert min_size <= len(result.columns)
    assert max_size is None or len(result.columns) <= max_size
    assert not all(map(is_column_unique, result.columns))
def test_examples(data: DataObject,
                  columns_with_bounds: Tuple[List[Column], Bounds]) -> None:
    columns, (min_size, max_size) = columns_with_bounds

    strategy = unique_factory(columns, min_size=min_size, max_size=max_size)

    result = data.draw(strategy)

    assert isinstance(result, UniqueConstraint)
    assert len(result.columns) >= min_size
    assert max_size is None or len(result.columns) <= max_size
    assert all(column in columns for column in result.columns)
Beispiel #7
0
def test_examples(data: DataObject, dialect: Dialect, metadata: MetaData,
                  min_size: int, max_size: Optional[int]) -> None:
    strategy = factory(dialect=dialect,
                       metadata=metadata,
                       min_size=min_size,
                       max_size=max_size)

    result = data.draw(strategy)

    assert isinstance(result, Table)
    assert min_size <= len(result.columns)
    assert max_size is None or len(result.columns) <= max_size
    assert not result.columns or result.primary_key
def test_lists_factory(data: DataObject, table_fixed_columns_values: Table,
                       min_size: int, max_size: Optional[int]) -> None:
    table, fixed_columns_values = table_fixed_columns_values

    strategy = lists_factory(table,
                             min_size=min_size,
                             max_size=max_size,
                             **fixed_columns_values)

    result = data.draw(strategy)

    assert isinstance(result, list)
    assert min_size <= len(result)
    assert max_size is None or len(result) <= max_size
    assert all(isinstance(record, tuple) for record in result)
    assert all(map(partial(table_record_is_valid, table=table), result))
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_examples(data: DataObject,
                  columns_with_bounds: Tuple[List[Column], Bounds]) -> None:
    columns, (min_size, max_size) = columns_with_bounds

    strategy = primary_keys_factory(columns,
                                    min_size=min_size,
                                    max_size=max_size)

    result = data.draw(strategy)

    existing_primary_key_columns = [
        column for column in columns if column.primary_key
    ]

    assert isinstance(result, PrimaryKeyConstraint)
    assert len(result.columns) >= min(len(existing_primary_key_columns),
                                      min_size)
    assert (max_size is None or len(result.columns) <= max(
        len(existing_primary_key_columns), max_size))
    assert all(column in columns for column in result.columns)
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)