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