Exemplo n.º 1
0
def test_data_valid_rows():
    refrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }, {
        '_id': '3'
    }]
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }, {
        '_id': '3'
    }]
    validate_data(testrows, vschema)
    assert testrows == refrows
    clean_data(testrows, vschema)
    assert testrows == refrows
Exemplo n.º 2
0
def test_data_nonstring_id_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id':2, 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool':False}]
    clean_data(testrows, vschema)
    assert testrows[1]['_id'] == '2'
    validate_data(testrows, vschema)
Exemplo n.º 3
0
def test_data_extrafield_pass():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColEx':4, 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b',
         'ColBool':False}]
    validate_data(testrows, vschema)
    assert testrows[1]['ColEx'] == 4
Exemplo n.º 4
0
def test_data_missing_id_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool':False}]
    clean_data(testrows, vschema, assign_ids=True)
    assert testrows[0]['_id'] != testrows[1]['_id']
    validate_data(testrows, vschema)
Exemplo n.º 5
0
def test_data_non_bool_boolean_truefix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': '1'
    }, {
        '_id': '4',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': '2'
    }, {
        '_id': '5',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'True'
    }, {
        '_id': '6',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'true'
    }, {
        '_id': '7',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'Yes'
    }, {
        '_id': '8',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'YES'
    }, {
        '_id': '9',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'Y'
    }, {
        '_id': '10',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'y'
    }]
    clean_data(testrows, vschema)
    for r in testrows:
        assert r['ColBool'] == True
    validate_data(testrows, vschema)
Exemplo n.º 6
0
def test_data_non_str_cat_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat':3, 'ColBool':False}]
    clean_data(testrows, vschema)
    assert testrows[1]['ColCat'] == '3'
    validate_data(testrows, vschema)
Exemplo n.º 7
0
def test_data_nonvalid_bool_boolean_fix():
    testrows = [{'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a',
        'ColBool':True}, {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b',
        'ColBool': 'jello'}]
    clean_data(testrows, vschema)
    assert not('ColBool' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 8
0
def test_data_int_count_limit_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt': 100001, 'ColFloat':4.1, 'ColCat': 'b',
         'ColBool':False}]
    clean_data(testrows, vschema)
    assert not('ColInt' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 9
0
def test_data_nonefield_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat':None,
         'ColBool':False}]
    clean_data(testrows, vschema)
    assert not('ColCat' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 10
0
def test_data_extrafield_fix():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColEx':4, 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b',
         'ColBool':False}]
    clean_data(testrows, vschema, remove_extra_fields=True)
    assert not('ColEx' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 11
0
def test_data_missing_id_fail():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool':False}]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
Exemplo n.º 12
0
def test_data_empty_col_fail():
    testrows = [{'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColBool':True},
                {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColBool':False}]
    assert_raises(VeritableError, validate_data,
        testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.col == 'ColCat'
Exemplo n.º 13
0
def test_data_non_bool_boolean_fail():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': '0'}]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColBool'
Exemplo n.º 14
0
def test_data_nonstring_id_fail():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id':2, 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool':False}]
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == '_id'
        raise
Exemplo n.º 15
0
def test_data_inf_float_real_fail():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt':4, 'ColFloat': float('Inf'), 'ColCat': 'b',
         'ColBool':False}]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColFloat'
Exemplo n.º 16
0
def test_data_non_bool_boolean_falsefix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': False
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': '0'
    }, {
        '_id': '5',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'False'
    }, {
        '_id': '6',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'false'
    }, {
        '_id': '7',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'No'
    }, {
        '_id': '8',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'NO'
    }, {
        '_id': '9',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'N'
    }, {
        '_id': '10',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'n'
    }]
    clean_data(testrows, vschema)
    for r in testrows:
        assert r['ColBool'] == False
    validate_data(testrows, vschema)
Exemplo n.º 17
0
def test_data_negative_int_count_fail():
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt': -4, 'ColFloat':4.1, 'ColCat': 'b',
         'ColBool':False}]
    assert_raises(VeritableError, validate_data, testrows,
        vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColInt'
Exemplo n.º 18
0
def test_data_non_bool_boolean_falsefix():
    testrows = [
    {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':False},
    {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': '0'},
    {'_id': '5', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'False'},
    {'_id': '6', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'false'},
    {'_id': '7', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'No'},
    {'_id': '8', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'NO'},
    {'_id': '9', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'N'},
    {'_id': '10', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'n'}]
    clean_data(testrows, vschema)
    for r in testrows:
        assert r['ColBool'] == False
    validate_data(testrows, vschema)
Exemplo n.º 19
0
def test_data_too_many_cats_fix():
    eschema = {'ColCat': {'type': 'categorical'}}
    testrows = []
    rid = 0
    maxCols = 256
    for i in range(maxCols - 1):
        testrows.append({'_id': str(rid), 'ColCat': str(i)})
        testrows.append({'_id': str(rid + 1), 'ColCat': str(i)})
        rid = rid + 2
    testrows.append({'_id': str(rid), 'ColCat': str(maxCols - 1)})
    testrows.append({'_id': str(rid + 1), 'ColCat': str(maxCols)})
    clean_data(testrows, eschema)
    assert testrows[510]['ColCat'] == 'Other'
    assert testrows[511]['ColCat'] == 'Other'
    validate_data(testrows, eschema)
Exemplo n.º 20
0
def test_data_valid_rows():
    refrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b',
         'ColBool':False},
        {'_id': '3'}]
    testrows = [
        {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
        {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b',
         'ColBool':False},
        {'_id': '3'}]
    validate_data(testrows, vschema)
    assert testrows == refrows
    clean_data(testrows, vschema)
    assert testrows == refrows
Exemplo n.º 21
0
def test_data_non_bool_boolean_truefix():
    testrows = [
    {'_id': '1', 'ColInt':3, 'ColFloat':3.1, 'ColCat': 'a', 'ColBool':True},
    {'_id': '2', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': '1'},
    {'_id': '4', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': '2'},
    {'_id': '5', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'True'},
    {'_id': '6', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'true'},
    {'_id': '7', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'Yes'},
    {'_id': '8', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'YES'},
    {'_id': '9', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'Y'},
    {'_id': '10', 'ColInt':4, 'ColFloat':4.1, 'ColCat': 'b', 'ColBool': 'y'}]
    clean_data(testrows, vschema)
    for r in testrows:
        assert r['ColBool'] == True
    validate_data(testrows, vschema)
Exemplo n.º 22
0
def test_data_too_many_cats_fail():
    eschema = {'ColCat': {'type': 'categorical'}}
    testrows = []
    rid = 0
    maxCols = 256
    for i in range(maxCols - 1):
        testrows.append({'_id': str(rid), 'ColCat': str(i)})
        testrows.append({'_id': str(rid + 1), 'ColCat': str(i)})
        rid = rid + 2
    testrows.append({'_id': str(rid), 'ColCat': str(maxCols - 1)})
    testrows.append({'_id': str(rid + 1), 'ColCat': str(maxCols)})
    assert_raises(VeritableError, validate_data, testrows, eschema)
    try:
        validate_data(testrows, eschema)
    except VeritableError as e:
        assert e.col == 'ColCat'
Exemplo n.º 23
0
def test_data_missing_id_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_data(testrows, vschema, assign_ids=True)
    assert testrows[0]['_id'] != testrows[1]['_id']
    validate_data(testrows, vschema)
Exemplo n.º 24
0
def test_data_empty_col_fail():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColBool': False
    }]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.col == 'ColCat'
Exemplo n.º 25
0
def test_data_nonvalid_bool_boolean_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': 'jello'
    }]
    clean_data(testrows, vschema)
    assert not ('ColBool' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 26
0
def test_data_too_many_cats_fix():
    eschema = {
        'ColCat': {'type': 'categorical'}
    }
    testrows = []
    rid = 0
    maxCols = 256
    for i in range(maxCols - 1):
        testrows.append({'_id':str(rid), 'ColCat':str(i)})
        testrows.append({'_id':str(rid + 1), 'ColCat':str(i)})
        rid = rid + 2
    testrows.append({'_id':str(rid), 'ColCat':str(maxCols - 1)})
    testrows.append({'_id':str(rid + 1), 'ColCat':str(maxCols)})
    clean_data(testrows, eschema)
    assert testrows[510]['ColCat'] == 'Other'
    assert testrows[511]['ColCat'] == 'Other'
    validate_data(testrows, eschema)
Exemplo n.º 27
0
def test_data_int_count_limit_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 100001,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_data(testrows, vschema)
    assert not ('ColInt' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 28
0
def test_data_non_int_count_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': '4',
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_data(testrows, vschema)
    assert testrows[1]['ColInt'] == 4
    validate_data(testrows, vschema)
Exemplo n.º 29
0
def test_data_extrafield_pass():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColEx': 4,
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    validate_data(testrows, vschema)
    assert testrows[1]['ColEx'] == 4
Exemplo n.º 30
0
def test_data_nonefield_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': None,
        'ColBool': False
    }]
    clean_data(testrows, vschema)
    assert not ('ColCat' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 31
0
def test_data_nonstring_id_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': 2,
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_data(testrows, vschema)
    assert testrows[1]['_id'] == '2'
    validate_data(testrows, vschema)
Exemplo n.º 32
0
def test_data_extrafield_fix():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColEx': 4,
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    clean_data(testrows, vschema, remove_extra_fields=True)
    assert not ('ColEx' in testrows[1])
    validate_data(testrows, vschema)
Exemplo n.º 33
0
def test_data_missing_id_fail():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
Exemplo n.º 34
0
def test_data_too_many_cats_fail():
    eschema = {
        'ColCat': {'type': 'categorical'}
    }
    testrows = []
    rid = 0
    maxCols = 256
    for i in range(maxCols - 1):
        testrows.append({'_id':str(rid), 'ColCat':str(i)})
        testrows.append({'_id':str(rid + 1), 'ColCat':str(i)})
        rid = rid + 2
    testrows.append({'_id':str(rid), 'ColCat':str(maxCols - 1)})
    testrows.append({'_id':str(rid + 1), 'ColCat':str(maxCols)})
    assert_raises(VeritableError, validate_data,
        testrows, eschema)
    try:
        validate_data(testrows, eschema)
    except VeritableError as e:
        assert e.col == 'ColCat'
Exemplo n.º 35
0
def test_data_nonvalid_int_count_fail():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 'jello',
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColInt'
Exemplo n.º 36
0
def test_data_nonstring_id_fail():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': 2,
        'ColInt': 4,
        'ColFloat': 4.1,
        'ColCat': 'b',
        'ColBool': False
    }]
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == '_id'
        raise
Exemplo n.º 37
0
def test_data_inf_float_real_fail():
    testrows = [{
        '_id': '1',
        'ColInt': 3,
        'ColFloat': 3.1,
        'ColCat': 'a',
        'ColBool': True
    }, {
        '_id': '2',
        'ColInt': 4,
        'ColFloat': float('Inf'),
        'ColCat': 'b',
        'ColBool': False
    }]
    assert_raises(VeritableError, validate_data, testrows, vschema)
    try:
        validate_data(testrows, vschema)
    except VeritableError as e:
        assert e.row == 1
        assert e.col == 'ColFloat'