Exemple #1
0
def test_missing_file(tmpdir):
    filepath = '{}.foo'.format(str(tmpdir.join('not-found.json')))

    with pytest.raises(gluetool.GlueError,
                       match=r"File '{}' does not exist".format(
                           re.escape(filepath))):
        load_json(filepath)
Exemple #2
0
def test_error(tmpdir):
    filepath = create_file(tmpdir, 'test-error.json',
                           lambda stream: stream.write('{'))

    with pytest.raises(
            gluetool.GlueError,
            match=
            r"(?ms)Unable to load JSON file '{}': Expecting object: line 1 column 1 \(char 0\)"
            .format(re.escape(filepath))):
        print load_json(filepath)
Exemple #3
0
def test_load(json_data, log, tmpdir):
    filepath = create_json(tmpdir, 'test-load.json', json_data)

    loaded = load_json(filepath)

    assert json_data == loaded
    assert log.match(message="loaded JSON data from '{}':\n{}".format(
        filepath, gluetool.log.format_dict(json_data)))
Exemple #4
0
def test_error(tmpdir):
    filepath = create_file(tmpdir, 'test-error.json',
                           lambda stream: stream.write('{'))

    if six.PY2:
        pattern = r"(?ms)Unable to load JSON file '{}': Expecting object: line 1 column 1 \(char 0\)".format(
            re.escape(filepath))

    else:
        pattern = r"(?ms)Unable to load JSON file '{}': Expecting property name enclosed in double quotes: line 1 column 2 \(char 1\)".format(
            re.escape(filepath))

    with pytest.raises(gluetool.GlueError, match=pattern):
        print(load_json(filepath))
Exemple #5
0
def test_illegal_filepath(filepath):
    with pytest.raises(gluetool.GlueError,
                       match=r'File path is not valid: {}'.format(filepath)):
        load_json(filepath)