Ejemplo n.º 1
0
def test_expect_report_failure_flags(capsys):
    """ Arguments to expect are all tuples"""

    target = '''
Failed Expectations: 2

1: File test_expect.py, line 9, in check_df1()
    "within_n_sds(4, df.mpg)" is not True
        -- Not all mpg values within 4 SDs

2: File test_expect.py, line 10, in check_df1()
    "df.vs.isin([0, 1]).all()" is not True
        -- Values of vs are not all in set{0,1}\n\n'''

    check_df1(mtcars_df, display=False)
    out, err = capsys.readouterr()
    assert out is ''

    with pytest.raises(FailedValidationError) as err:
        check_df1(mtcars_df2, error=True)
    assert str(err.value) == '\n' + target

    check_df1(mtcars_df2, clear=False, display=False)
    out, err = capsys.readouterr()
    assert out is ''
    report_failures()
    out, err = capsys.readouterr()
    assert out == target + '\n'
Ejemplo n.º 2
0
def check_mylist2(mylist, clear=True):
    """ Validator for mtcars, inputs are statements """    
            
    data_types = [type(x) for x in mylist]

    expect(
        len(mylist) <= 10, 
        str not in data_types,
    )
        
    report_failures(error=False, display=True, clear=clear)
Ejemplo n.º 3
0
def check_mylist1(mylist, clear=True):
    """ Validator for mtcars, inputs are tuples """    
            
    data_types = [type(x) for x in mylist]

    expect(
        (len(mylist) <= 10, "List should not be bigger than length 10"), 
        (str not in data_types, "List should not contain strings"),
    )
        
    report_failures(error=False, display=True, clear=clear)
Ejemplo n.º 4
0
def check_df1(df, **kwds):
    """ Validator for mtcars """    

    na_rows = df.isnull().any(axis=1).sum()
    
    expect(
        (len(df) > 10, "Num rows must be greater than 10"), 
        ((df.mpg > 0).all(), "Not all values in mpg are over 0"),
        (within_n_sds(4, df.mpg), "Not all mpg values within 4 SDs"),
        (df.vs.isin([0, 1]).all(), "Values of vs are not all in set{0,1}"),
        (df.am.isin([0, 1]).all(), "Values of am are not all in set{0,1}"),
        (na_rows >= 0 and na_rows <= 2, "Number of NA rows is not within bounds [0, 2]"),
        (within_n_mads(10, maha_dist(df)), "Not all maha_dist values within 10 MADs")
    )
    
    report_failures(**kwds)
Ejemplo n.º 5
0
def check_mylist3(mylist, clear=True):
    """ Validator for mtcars, inputs are statements """    

    expect(len(mylist) <= 10, "List should not be bigger than length 10")
        
    report_failures(error=False, display=True, clear=clear)