Ejemplo n.º 1
0
def test_load_from_filename_fails_load_strategy(tmpdir):
    f = tmpdir.join('foo.notjson')
    f.write('totes not json')
    with pytest.raises(Error) as excinfo:
        load_from_filename(f.strpath, map_required, json.loads, Error)
    _assert_exception_trace(
        excinfo.value.args[0],
        # ANY is json's error message
        ('File {}'.format(f.strpath), mock.ANY))
Ejemplo n.º 2
0
def test_load_from_filename_fails_load_strategy(tmpdir):
    f = tmpdir.join('foo.notjson')
    f.write('totes not json')
    with pytest.raises(Error) as excinfo:
        load_from_filename(f.strpath, map_required, json.loads, Error)
    _assert_exception_trace(
        excinfo.value.args[0],
        # ANY is json's error message
        ('File {}'.format(f.strpath), mock.ANY)
    )
Ejemplo n.º 3
0
def test_load_from_filename_validation_error(tmpdir):
    f = tmpdir.join('foo.json')
    f.write('{}')
    with pytest.raises(Error) as excinfo:
        load_from_filename(f.strpath, map_required, json.loads, Error)
    _assert_exception_trace(
        excinfo.value.args[0],
        (
            'File {}'.format(f.strpath), 'At foo(key=MISSING)',
            'Missing required key: key',
        ),
    )
Ejemplo n.º 4
0
def test_load_from_filename_validation_error(tmpdir):
    f = tmpdir.join('foo.json')
    f.write('{}')
    with pytest.raises(Error) as excinfo:
        load_from_filename(f.strpath, map_required, json.loads, Error)
    _assert_exception_trace(
        excinfo.value.args[0],
        (
            'File {}'.format(f.strpath),
            'At foo(key=MISSING)',
            'Missing required key: key',
        ),
    )
Ejemplo n.º 5
0
def test_load_from_filename_applies_defaults(tmpdir):
    f = tmpdir.join('foo.json')
    f.write('{}')
    ret = load_from_filename(f.strpath, map_optional, json.loads, Error)
    assert ret == {'key': False}
Ejemplo n.º 6
0
def test_load_from_filename_file_does_not_exist():
    with pytest.raises(Error) as excinfo:
        load_from_filename('does_not_exist', map_required, json.loads, Error)
    assert excinfo.value.args[0].error_msg == 'does_not_exist does not exist'
Ejemplo n.º 7
0
def test_load_from_filename_applies_defaults(tmpdir):
    f = tmpdir.join('foo.json')
    f.write('{}')
    ret = load_from_filename(f.strpath, map_optional, json.loads, Error)
    assert ret == {'key': False}
Ejemplo n.º 8
0
def test_load_from_filename_file_does_not_exist():
    with pytest.raises(Error) as excinfo:
        load_from_filename('does_not_exist', map_required, json.loads, Error)
    assert excinfo.value.args[0].error_msg == 'does_not_exist does not exist'