コード例 #1
0
def test_get_caster_fails_with_too_many_empty_sample_values(format):
    datapackage, just_enough_empty_samples_to_fail = _prepare(
        'date', format,
        nb_bad_rows=_TOO_MANY_BAD_ROWS - 1,
        nb_empty_rows=floor(1 / SNIFFER_MAX_FAILURE_RATIO + 1)
    )
    with raises(CasterNotFound):
        get_casters(datapackage, just_enough_empty_samples_to_fail)
コード例 #2
0
def test_get_caster_returns_valid_caster_from_good_number_samples(format):
    datapackage, sample_rows = _prepare('number', format)
    casters = get_casters(datapackage, sample_rows)
    result = casters['foo'].cast(str(sample_rows))
    assert abs(float(result) - sample_rows.value) < 0.0001
コード例 #3
0
def test_get_caster_raises_caster_not_found_from_bad_number_samples(format):
    datapackage, bad_sample_rows = _prepare('number', format,
                                            nb_bad_rows=_TOO_MANY_BAD_ROWS)
    with raises(CasterNotFound):
        get_casters(datapackage, bad_sample_rows)
コード例 #4
0
def test_get_caster_returns_valid_caster_from_good_date_samples(format):
    datapackage, sample_rows = _prepare('date', format)
    casters = get_casters(datapackage, sample_rows)
    assert casters['foo'].cast(str(sample_rows)) == sample_rows.value