コード例 #1
0
def test_path():
    # Check the path is read
    expected_path = 'http://schema.org/givenName'
    with open('tests/inputs/test_shape.ttl') as f:
        rdf_handler = RDFHandler(f)
    properties = rdf_handler.get_shape_no_root_iri()['properties']
    assert any(str(p['path'] == expected_path for p in properties))
コード例 #2
0
def test_empty_file():
    with pytest.raises(Exception):
        with open('tests/inputs/empty_file.ttl') as f:
            rdf_handler = RDFHandler(f)
            shape = rdf_handler.get_shape_no_root_iri()
            generate_form(shape, form_destination='result.html')
            map_destination='result.ttl'
            rdf_handler.create_rdf_map(shape, map_destination)
コード例 #3
0
def test_empty_shape():
    # Valid but empty shape
    expected_result = dict()
    expected_result['target_class'] = URIRef('http://schema.org/Person')
    expected_result['groups'] = list()
    expected_result['properties'] = list()
    expected_result['closed'] = False
    with open('tests/inputs/empty_shape.ttl') as f:
        rdf_handler = RDFHandler(f)
    result = rdf_handler.get_shape_no_root_iri()
    assert result == expected_result
コード例 #4
0
def test_shape():
    # Contents of result can't be verified due to RDF and therefore the HTML result being unordered
    if os.path.exists('results'):
        shutil.rmtree('results')
    with open('tests/inputs/test_shape.ttl') as f:
        rdf_handler = RDFHandler(f)
        shape = rdf_handler.get_shape_no_root_iri()
        generate_form(shape, form_destination='results/result.html')
        map_destination='results/result.ttl'
        rdf_handler.create_rdf_map(shape, map_destination)
    assert os.path.exists('results/result.html')
コード例 #5
0
def test_invalid_mincount():
    # Check that a non-integer minCount raises the appropriate error
    with open('tests/inputs/invalid_minCount.ttl') as f:
        rdf_handler = RDFHandler(f)
    with pytest.raises(Exception):
        rdf_handler.get_shape_no_root_iri()
コード例 #6
0
def test_missing_group():
    # Checks to make sure an exception is thrown if a group is referenced but does not exist
    with open('tests/inputs/missing_group.ttl') as f:
        rdf_handler = RDFHandler(f)
    with pytest.raises(Exception):
        rdf_handler.get_shape_no_root_iri()
コード例 #7
0
def test_empty_file():
    # Checks behaviour when an empty file is supplied
    with open('tests/inputs/empty_file.ttl') as f:
        rdf_handler = RDFHandler(f)
    assert rdf_handler.get_shape_no_root_iri() is None
コード例 #8
0
def test_implicit_target_class():
    # Checks to make sure the target class is correctly identified when implicitly declared
    with open('tests/inputs/implicit_target_class.ttl') as f:
        rdf_handler = RDFHandler(f)
    shape = rdf_handler.get_shape_no_root_iri()
    assert str(shape['target_class']) == 'http://schema.org/Person'
コード例 #9
0
def test_recursion():
    # Checks to make sure recursion isn't accepted
    with open('tests/inputs/recursion.ttl') as f:
        rdf_handler = RDFHandler(f)
    with pytest.raises(Exception):
        rdf_handler.get_shape_no_root_iri()
コード例 #10
0
def test_no_path():
    # Checks behaviour when a property doesn't have a compulsory path constraint
    with open('tests/inputs/no_path.ttl') as f:
        rdf_handler = RDFHandler(f)
    with pytest.raises(Exception):
        rdf_handler.get_shape_no_root_iri()
コード例 #11
0
def test_no_target_class():
    # Checks behavior when the shape provided doesn't have a target class
    with open('tests/inputs/no_target_class.ttl') as f:
        rdf_handler = RDFHandler(f)
    with pytest.raises(Exception):
        rdf_handler.get_shape_no_root_iri()