コード例 #1
0
def test_shape_validation_without_column_constraints():
    assert (
        validate_constraints(
            DataFrame({"foo": [2], "bar": ["hello"]}), dataframe_constraints=[RowCountConstraint(1)]
        )
        is None
    )

    with pytest.raises(ConstraintViolationException):
        validate_constraints(
            DataFrame({"foo": [2], "bar": ["hello"]}), dataframe_constraints=[RowCountConstraint(2)]
        )
コード例 #2
0
def test_shape_validation_throw_error():
    with pytest.raises(ConstraintViolationException):
        validate_constraints(
            DataFrame({"foo": [2], "bar": ["hello"]}),
            pandas_columns=[
                PandasColumn.integer_column("foo", min_value=0),
                PandasColumn.string_column("bar"),
            ],
            dataframe_constraints=[RowCountConstraint(2)],
        )
コード例 #3
0
def test_shape_validation_ok():
    assert (validate_constraints(
        DataFrame({
            'foo': [2],
            'bar': ['hello']
        }),
        pandas_columns=[
            PandasColumn.integer_column('foo', min_value=0),
            PandasColumn.string_column('bar'),
        ],
        dataframe_constraints=[RowCountConstraint(1)],
    ) is None)
コード例 #4
0
def test_shape_validation_ok():
    assert (
        validate_constraints(
            DataFrame({"foo": [2], "bar": ["hello"]}),
            pandas_columns=[
                PandasColumn.integer_column("foo", min_value=0),
                PandasColumn.string_column("bar"),
            ],
            dataframe_constraints=[RowCountConstraint(1)],
        )
        is None
    )
コード例 #5
0
def test_shape_validation_throw_error():
    with pytest.raises(ConstraintViolationException):
        validate_constraints(
            DataFrame({
                'foo': [2],
                'bar': ['hello']
            }),
            pandas_columns=[
                PandasColumn.integer_column('foo', min_value=0),
                PandasColumn.string_column('bar'),
            ],
            dataframe_constraints=[RowCountConstraint(2)],
        )
コード例 #6
0
ファイル: test_constraints.py プロジェクト: hhy5277/dagster
def test_row_count_constraint():
    test_dataframe = DataFrame({'foo': [1, 2, 3, 4, 5, 6]})
    assert RowCountConstraint(6).validate(test_dataframe) is None
    with pytest.raises(ConstraintViolationException):
        RowCountConstraint(5).validate(test_dataframe)

    assert (RowCountConstraint(5, error_tolerance=1).validate(
        DataFrame({'foo': [1, 2, 3, 4]})) is None)
    with pytest.raises(ConstraintViolationException):
        assert RowCountConstraint(5, error_tolerance=1).validate(
            DataFrame({'foo': [1, 2]}))

    assert (RowCountConstraint(5, error_tolerance=1).validate(
        DataFrame({'foo': [1, 2, 3, 4, 5, 6]})) is None)
    with pytest.raises(ConstraintViolationException):
        assert RowCountConstraint(5, error_tolerance=1).validate(
            DataFrame({'foo': [1, 2, 3, 4, 5, 6, 7]}))