Ejemplo n.º 1
0
def test_from_yaml_unregistered_checks():
    """Test that from_yaml raises an exception when deserializing unregistered checks."""

    with pytest.raises(AttributeError, match=".*custom checks.*"):
        io.from_yaml(YAML_SCHEMA_MISSING_COLUMN_CHECK)

    with pytest.raises(AttributeError, match=".*custom checks.*"):
        io.from_yaml(YAML_SCHEMA_MISSING_GLOBAL_CHECK)
Ejemplo n.º 2
0
def test_from_yaml_load_required_fields():
    """Test that dataframe schemas do not require any field."""
    io.from_yaml("")

    with pytest.raises(pa.errors.SchemaDefinitionError,
                       match=".*must be a mapping.*"):
        io.from_yaml("""
        - value
        """)
Ejemplo n.º 3
0
def test_from_yaml():
    """Test that from_yaml reads yaml string."""

    for yml_string, schema_creator in YAML_VALIDATION_PAIRS:
        schema_from_yaml = io.from_yaml(yml_string)
        expected_schema = schema_creator()
        assert schema_from_yaml == expected_schema
        assert expected_schema == schema_from_yaml
Ejemplo n.º 4
0
def test_inferred_schema_io():
    """Test that inferred schema can be writted to yaml."""
    df = pd.DataFrame({
        "column1": [5, 10, 20],
        "column2": [5., 1., 3.],
        "column3": ["a", "b", "c"],
    })
    schema = pa.infer_schema(df)
    schema_yaml_str = schema.to_yaml()
    schema_from_yaml = io.from_yaml(schema_yaml_str)
    assert schema == schema_from_yaml
Ejemplo n.º 5
0
def test_io_yaml():
    """Test read and write operation on file names."""
    schema = _create_schema()

    # pass in a file name
    with tempfile.NamedTemporaryFile("w+") as f:
        output = io.to_yaml(schema, f.name)
        assert output is None
        schema_from_yaml = io.from_yaml(f.name)
        assert schema_from_yaml == schema

    # pass in a Path object
    with tempfile.NamedTemporaryFile("w+") as f:
        output = schema.to_yaml(Path(f.name))
        assert output is None
        schema_from_yaml = pa.DataFrameSchema.from_yaml(Path(f.name))
        assert schema_from_yaml == schema
Ejemplo n.º 6
0
def test_from_yaml(yaml_str, schema_creator):
    """Test that from_yaml reads yaml string."""
    schema_from_yaml = io.from_yaml(yaml_str)
    expected_schema = schema_creator()
    assert schema_from_yaml == expected_schema
    assert expected_schema == schema_from_yaml