예제 #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))
예제 #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)
    )
예제 #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',
        ),
    )
예제 #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',
        ),
    )
예제 #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}
예제 #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'
예제 #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}
예제 #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'