Skip to content

Commit 5bea382

Browse files
API: removed unneeded pragma: no cover comments
1 parent d6f2dce commit 5bea382

File tree

10 files changed

+41
-61
lines changed

10 files changed

+41
-61
lines changed

openatlas/api/endpoints/endpoint.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,7 @@ def get_entities_formatted(self) -> None:
264264
self.formated_entities = [
265265
self.get_linked_places_entity(_id)
266266
for _id in self.entities_with_links]
267-
case _ if self.parser.format \
268-
in app.config['RDF_FORMATS']: # pragma: no cover
267+
case _ if self.parser.format in app.config['RDF_FORMATS']:
269268
license_links = get_license_ids_with_links()
270269
parsed_context = parse_loud_context()
271270
self.generator_entities = (

openatlas/api/endpoints/file.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
from openatlas.api.resources.parser import files, image
1616
from openatlas.api.resources.resolve_endpoints import download
1717
from openatlas.api.resources.templates import licensed_file_template
18-
from openatlas.api.resources.util import get_iiif_manifest_and_path, \
19-
get_license_name
18+
from openatlas.api.resources.util import (
19+
get_iiif_manifest_and_path, get_license_name)
2020
from openatlas.database.overlay import get_by_object
2121
from openatlas.display.util import (
2222
check_iiif_activation, check_iiif_file_exist, get_file_path)
@@ -118,10 +118,11 @@ def get() -> Response:
118118
def get_file_dict(
119119
entity: Entity,
120120
overlay: Optional[Overlay] = None) -> dict[str, Any]:
121-
path = get_file_path(entity.id)
121+
url = 'N/A'
122122
mime_type = None
123-
if path:
124-
mime_type, _ = mimetypes.guess_type(path) # pragma: no cover
123+
if path := get_file_path(entity.id):
124+
url = url_for('api.display', filename=path.stem, _external=True)
125+
mime_type, _ = mimetypes.guess_type(path)
125126
data = {
126127
'id': entity.id,
127128
'title': entity.name,
@@ -130,10 +131,7 @@ def get_file_dict(
130131
'licenseHolder': entity.license_holder,
131132
'publicShareable': entity.public,
132133
'mimetype': mime_type,
133-
'url': url_for(
134-
'api.display',
135-
filename=path.stem,
136-
_external=True) if path else 'N/A'}
134+
'url': url}
137135
data.update(get_iiif_manifest_and_path(entity.id))
138136
if overlay:
139137
data.update({'overlay': overlay.bounding_box})

openatlas/api/external/arche.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def is_arche_likeable_uri(uri: str) -> bool:
2727
for rule in g.arche_uri_rules:
2828
if search(rule['match'], uri):
2929
return True
30-
return False # pragma: no cover
30+
return False
3131

3232

3333
def is_valid_url(url: str) -> bool:
@@ -56,12 +56,9 @@ def create_uri(value: str | list[str]) -> list[URIRef]:
5656
return [create_single_uri(value)]
5757

5858

59-
def ensure_person_exist(
60-
graph: Graph,
61-
names: str | list[str]) -> None:
59+
def ensure_person_exist(graph: Graph, names: str | list[str]) -> None:
6260
names = names if isinstance(names, list) else [names]
6361
for name in names:
64-
6562
if not name or is_valid_url(name):
6663
continue # pragma: no cover
6764
uri = create_single_uri(name)
@@ -117,13 +114,11 @@ def ensure_entity_exist(
117114

118115
def transliterate_url(url: str) -> str:
119116
parsed = urlparse(url)
120-
path = parsed.path
121-
ascii_path = unidecode(path)
122-
ascii_path = ascii_path.replace(' ', '_')
117+
ascii_path = unidecode(parsed.path)
123118
return urlunparse((
124119
parsed.scheme,
125120
parsed.netloc,
126-
ascii_path,
121+
ascii_path.replace(' ', '_'),
127122
parsed.params,
128123
parsed.query,
129124
parsed.fragment))

openatlas/api/formats/linked_places.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
from __future__ import annotations
22

33
import mimetypes
4-
from typing import Any, Optional, TYPE_CHECKING
4+
from typing import Any, Optional
55

66
from flask import g, url_for
77

8+
from openatlas.api.endpoints.parser import Parser
89
from openatlas.api.resources.util import (
910
date_to_str, get_crm_relation, get_crm_relation_label_x,
1011
get_crm_relation_x, get_iiif_manifest_and_path, get_license_name,
1112
to_camel_case)
1213
from openatlas.display.util import get_file_path
1314
from openatlas.models.entity import Entity, Link
1415

15-
if TYPE_CHECKING: # pragma: no cover
16-
from openatlas.api.endpoints.parser import Parser
17-
1816

1917
def link_dict(link_: Link, inverse: bool = False) -> dict[str, Any]:
2018
return {
@@ -81,10 +79,9 @@ def get_lp_time(entity: Entity | Link) -> Optional[dict[str, Any]]:
8179

8280

8381
def get_lp_file(file: Entity) -> dict[str, Any]:
84-
path = get_file_path(file.id)
85-
url = "N/A"
82+
url = 'N/A'
8683
mime_type = None
87-
if path:
84+
if path := get_file_path(file.id):
8885
url = url_for('api.display', filename=path.stem, _external=True)
8986
mime_type, _ = mimetypes.guess_type(path)
9087
data = {

openatlas/api/formats/presentation_view.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,9 @@ def get_file_dict(
5252
link: Link,
5353
overlay: Optional[Overlay] = None,
5454
root: Optional[bool] = False) -> dict[str, Any]:
55-
path = get_file_path(link.domain.id)
5655
url = 'N/A'
5756
mime_type = None
58-
if path:
57+
if path := get_file_path(link.domain.id):
5958
url_for('api.display', filename=path.stem, _external=True)
6059
mime_type, _ = mimetypes.guess_type(path)
6160
data = {

openatlas/api/formats/rdf.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ def _add_namespaces(graph: Graph, context: dict[str, Any]) -> None:
3030
graph.bind("rdf", Namespace("http://www.w3.org/1999/02/22-rdf-syntax-ns#"))
3131

3232

33-
def _expand_curie(curie: str) -> str: # pragma: no cover
33+
def _expand_curie(curie: str) -> str:
3434
if ":" not in curie:
35-
return curie
35+
return curie # pragma: no cover
3636
ctx = _linked_art_context.get("@context", {})
3737
prefix, local = curie.split(":", 1)
3838
base = ctx.get(prefix)
3939
if isinstance(base, str):
4040
return base + local
41-
return curie
41+
return curie # pragma: no cover
4242

4343

4444
def _resolve_predicate(
4545
key: str,
46-
data_type: str | None = None) -> URIRef | None: # pragma: no cover
46+
data_type: str | None = None) -> URIRef | None:
4747
ctx = _linked_art_context.get("@context", {})
4848

4949
if data_type and data_type in ctx:
@@ -54,16 +54,15 @@ def _resolve_predicate(
5454
entry = tctx[key]
5555
if isinstance(entry, dict) and "@id" in entry:
5656
return URIRef(_expand_curie(entry["@id"]))
57-
if isinstance(entry, str):
57+
if isinstance(entry, str): # pragma: no cover
5858
return URIRef(_expand_curie(entry))
5959

6060
entry = ctx.get(key)
6161
if isinstance(entry, dict) and "@id" in entry:
6262
return URIRef(_expand_curie(entry["@id"]))
63-
if isinstance(entry, str):
63+
if isinstance(entry, str): # pragma: no cover
6464
return URIRef(_expand_curie(entry))
65-
66-
return None
65+
return None # pragma: no cover
6766

6867

6968
def _get_subject(
@@ -106,41 +105,36 @@ def _add_triples_from_linked_art(
106105
graph: Graph,
107106
data: list[dict[str, Any]] | dict[str, Any],
108107
parent_subject: URIRef | BNode | None = None,
109-
parent_predicate: URIRef | None = None) -> None: # pragma: no cover
110-
if not isinstance(data, dict): # pragma: no cover - mypy
111-
return
108+
parent_predicate: URIRef | None = None) -> None:
109+
if not isinstance(data, dict):
110+
return # pragma: no cover
112111

113112
subject = _get_subject(data, graph, parent_subject, parent_predicate)
114-
115-
data_type = data.get("type")
116-
if data_type:
113+
if data_type := data.get("type"):
117114
ctx = _linked_art_context.get("@context", {})
118115
type_uri: str | None = None
119116

120117
if ":" in data_type:
121-
type_uri = _expand_curie(data_type)
122-
118+
type_uri = _expand_curie(data_type) # pragma: no cover
123119
elif isinstance(ctx.get(data_type), dict):
124120
entry = ctx[data_type]
125121
if "@id" in entry:
126122
type_uri = _expand_curie(entry["@id"])
127123

128-
if not type_uri:
124+
if not type_uri: # pragma: no cover
129125
la_base = ctx.get("la") or "https://linked.art/ns/terms/"
130126
type_uri = la_base + data_type
131127

132-
if not type_uri: # pragma: no cover - mypy
133-
return
128+
if not type_uri:
129+
return # pragma: no cover
134130

135131
graph.add((subject, RDF.type, URIRef(type_uri)))
136132

137133
for key, value in data.items():
138134
if key in {"id", "type", "@context"}:
139135
continue
140-
141-
predicate = _resolve_predicate(key, data_type)
142-
if not predicate: # pragma: no cover - mypy
143-
continue
136+
if not (predicate := _resolve_predicate(key, data_type)):
137+
continue # pragma: no cover
144138

145139
_handle_value(graph, subject, predicate, value)
146140

openatlas/api/formats/subunits.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
from flask import g
55

66
from openatlas.api.resources.util import (
7-
geometry_to_geojson, get_license_name,
8-
get_reference_systems, remove_duplicate_entities,
9-
replace_empty_list_values_in_dict_with_none)
7+
geometry_to_geojson, get_license_name, get_reference_systems,
8+
remove_duplicate_entities, replace_empty_list_values_in_dict_with_none)
109
from openatlas.display.util import get_file_path
1110
from openatlas.models.entity import Entity, Link
1211
from openatlas.models.gis import Gis

openatlas/api/import_scripts/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ def vocabs_requests(
5353
parameter: Optional[dict[str, str]] = None) -> dict[str, Any]:
5454
base = g.settings['vocabs_base_url']
5555
url = f'{base}{g.settings['vocabs_endpoint']}{id_}/{endpoint}'
56-
sleep(0.1) # fix connection abort
56+
sleep(0.1) # Fix connection abort
5757
try:
5858
resp = requests.get(
5959
url,
6060
params=parameter or "",
6161
timeout=60,
6262
auth=(g.settings['vocabs_user'], app.config['VOCABS_PASS']))
6363
resp.raise_for_status()
64-
except requests.exceptions.RequestException as e: # pragma: no cover
64+
except requests.exceptions.RequestException as e:
6565
abort(400, f'Request failed for {url}: {e}')
6666

6767
try:
6868
result = resp.json()
69-
except ValueError: # pragma: no cover
69+
except ValueError:
7070
abort(400, f'Invalid JSON from {url}')
7171
return result

openatlas/api/import_scripts/vocabs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ def import_children(
118118
children = []
119119
child = None
120120
for entry in req['narrower']:
121-
if not entry['prefLabel']: # pragma: no cover
121+
if not entry['prefLabel']:
122122
g.logger.log(
123123
'warn',
124124
'import',

openatlas/api/resources/templates.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,7 @@ def subunit_template(id_: str) -> dict[str, List]:
310310
'description': fields.String,
311311
'standardType': fields.Nested(standard_type),
312312
'timespan': fields.Nested(timespan),
313-
'externalReferences': fields.List(
314-
fields.Nested(external_references)),
313+
'externalReferences': fields.List(fields.Nested(external_references)),
315314
'references': fields.List(fields.Nested(references)),
316315
'files': fields.List(fields.Nested(files)),
317316
'types': fields.List(fields.Nested(types))}

0 commit comments

Comments
 (0)