def test_context(capsys):
    context = new_context()
    context = shell.base(context, '<http://example.org/stuff#>')
    context = shell.prefix(context, 'c: <http://example.org/concepts#>')
    context = shell.parse(context, input_file)
    context = shell.context(context, '')
    (out, err) = capsys.readouterr()
    assert out.index('BASE <http://example.org/stuff#>') >= 0
    assert out.index('PREFIX c: <http://example.org/concepts#>') >= 0
    assert out.index('size 25 statements') >= 0
def test_subjects(capsys):
    context = new_context()
    context = shell.parse(context, input_file)
    context = shell.subjects(context, '')
    (out, err) = capsys.readouterr()
    # Skip first line (result of parse) and last line (blank)
    subjects = out.split('\n')[1:-1]
    assert len(subjects) == 11
    for subject in subjects:
        assert subject.startswith('http://example.org/social/')
def test_predicates(capsys):
    context = new_context()
    context = shell.parse(context, input_file)
    context = shell.predicates(context, '')
    (out, err) = capsys.readouterr()
    # Skip first line (result of parse) and last line (blank)
    predicates = out.split('\n')[1:-1]
    assert len(predicates) == 6
    for predicate in predicates[:-1]:
        assert (predicate.startswith('http://example.org/social/') or predicate
                == 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
def test_show(capsys):
    context = new_context()
    context = shell.parse(context, input_file)
    context = shell.show(context, 'nt')
    (out, err) = capsys.readouterr()
    lines = [line for line in out.split('\n')[1:] if not line == '']
    assert len(lines) == input_file_count
    for line in lines:
        if not line == '':
            assert line.startswith('<')
            assert line.endswith('> .')
def test_query(capsys, query, cols, rows):
    context = new_context()
    context = shell.parse(context, input_file)
    context = shell.query(context, query)
    (out, err) = capsys.readouterr()
    lines = [line for line in out.split('\n')[1:] if not line == '']
    header = [
        col.strip() for col in lines[0].split('|') if not col.strip() == ''
    ]
    assert set(header) == set(cols.split(','))
    assert set(lines[1]) == {'|', '='}
    assert lines[-1].startswith('%d rows returned' % rows)
def test_parse_no_file(capsys):
    context = new_context()
    context = shell.parse(context, input_file + '_noexist')
    (out, err) = capsys.readouterr()
    assert out.index('Error, unexpected problem reading file.') == 0
def test_parse_bad_format(capsys):
    context = new_context()
    context = shell.parse(context, input_file + ' text')
    (out, err) = capsys.readouterr()
    assert out.index('Warning') == 0
def test_parse(capsys):
    context = new_context()
    context = shell.parse(context, input_file)
    assert len(context.graph) == input_file_count