Skip to content

Commit

Permalink
Use single quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
webb-ben committed Feb 11, 2025
1 parent ca0ac44 commit adcbbc4
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions tests/test_linked_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,29 @@
@pytest.fixture
def feature():
return {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [125.6, 10.1]
'type': 'Feature',
'geometry': {
'type': 'Point',
'coordinates': [125.6, 10.1]
},
"properties": {
"name": "Test Point"
'properties': {
'name': 'Test Point'
},
"id": "test1",
"links": []
'id': 'test1',
'links': []
}


def test_geojson2jsonld_single_feature(api_, feature):
"""Test conversion of single GeoJSON feature to JSON-LD"""

result = geojson2jsonld(api_, feature,
"obs", "http://example.org/feature/1")
'obs', 'http://example.org/feature/1')
result_dict = json.loads(result)

assert "@context" in result_dict
assert result_dict["@id"] == "http://example.org/feature/1"
assert "schema:geo" in result_dict
assert '@context' in result_dict
assert result_dict['@id'] == 'http://example.org/feature/1'
assert 'schema:geo' in result_dict


def test_geom2schemageo():
Expand All @@ -79,32 +79,32 @@ def test_geom2schemageo():
# Test Point
point = Point(125.6, 10.1)
point_result = geom2schemageo(point)
assert point_result["@type"] == "schema:GeoCoordinates"
assert point_result["schema:longitude"] == 125.6
assert point_result["schema:latitude"] == 10.1
assert point_result['@type'] == 'schema:GeoCoordinates'
assert point_result['schema:longitude'] == 125.6
assert point_result['schema:latitude'] == 10.1

# Test LineString
line = LineString([(0, 0), (1, 1)])
line_result = geom2schemageo(line)
assert line_result["@type"] == "schema:GeoShape"
assert "schema:line" in line_result
assert line_result['@type'] == 'schema:GeoShape'
assert 'schema:line' in line_result

# Test Polygon
polygon = Polygon([(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)])
poly_result = geom2schemageo(polygon)
assert poly_result["@type"] == "schema:GeoShape"
assert "schema:polygon" in poly_result
assert poly_result['@type'] == 'schema:GeoShape'
assert 'schema:polygon' in poly_result


def test_jsonldify_geometry(feature):
"""Test addition of multiple geometry encodings to a feature"""

jsonldify_geometry(feature)

assert feature["type"] == "schema:Place"
assert "gsp:hasGeometry" in feature
assert "schema:geo" in feature
assert feature["schema:geo"]["@type"] == "schema:GeoCoordinates"
assert feature['type'] == 'schema:Place'
assert 'gsp:hasGeometry' in feature
assert 'schema:geo' in feature
assert feature['schema:geo']['@type'] == 'schema:GeoCoordinates'


def test_jsonldify_invalid_geometry(feature):
Expand All @@ -113,36 +113,36 @@ def test_jsonldify_invalid_geometry(feature):
feature['geometry']['coordinates'] = []
jsonldify_geometry(feature)

assert feature["type"] == "schema:Place"
assert "schema:geo" not in feature
assert feature['type'] == 'schema:Place'
assert 'schema:geo' not in feature


@pytest.mark.parametrize("geom_type,coords", [
("Point", [125.6, 10.1]),
("LineString", [(0, 0), (1, 1)]),
("Polygon", [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]),
("MultiPoint", [(0, 0), (1, 1)]),
("MultiLineString", [[(0, 0), (1, 1)], [(2, 2), (3, 3)]]),
("MultiPolygon", [[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],
@pytest.mark.parametrize('geom_type,coords', [
('Point', [125.6, 10.1]),
('LineString', [(0, 0), (1, 1)]),
('Polygon', [(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)]),
('MultiPoint', [(0, 0), (1, 1)]),
('MultiLineString', [[(0, 0), (1, 1)], [(2, 2), (3, 3)]]),
('MultiPolygon', [[(0, 0), (1, 0), (1, 1), (0, 1), (0, 0)],
[(2, 2), (3, 2), (3, 3), (2, 3), (2, 2)]])
])
def test_geometry_conversions(geom_type, coords):
"""Test conversion of different geometry types"""
if geom_type == "Point":
if geom_type == 'Point':
geom = Point(coords)
elif geom_type == "LineString":
elif geom_type == 'LineString':
geom = LineString(coords)
elif geom_type == "Polygon":
elif geom_type == 'Polygon':
geom = Polygon(coords)
elif geom_type == "MultiPoint":
elif geom_type == 'MultiPoint':
geom = MultiPoint(coords)
elif geom_type == "MultiLineString":
elif geom_type == 'MultiLineString':
geom = MultiLineString(coords)
elif geom_type == "MultiPolygon":
elif geom_type == 'MultiPolygon':
geom = MultiPolygon([Polygon(poly) for poly in coords])

result = geom2schemageo(geom)
assert result["@type"] in ["schema:GeoCoordinates", "schema:GeoShape"]
assert result['@type'] in ['schema:GeoCoordinates', 'schema:GeoShape']


def test_render_item_template(api_, feature):
Expand All @@ -168,8 +168,8 @@ def test_render_items_template(api_, feature):
'links': []
}

# Use "objects" collection which has item list json-ld template
result = geojson2jsonld(api_, fc, "objects")
# Use 'objects' collection which has item list json-ld template
result = geojson2jsonld(api_, fc, 'objects')
feature_list = json.loads(result)

assert len(feature_list['schema:itemListElement']) == len(fc['features'])
Expand Down

0 comments on commit adcbbc4

Please sign in to comment.