Skip to content

Commit eb45ba8

Browse files
committed
Format Python code with Black via pre-commit
Signed-off-by: Alex Nelson <alexander.nelson@nist.gov>
1 parent eaf8465 commit eb45ba8

File tree

7 files changed

+116
-70
lines changed

7 files changed

+116
-70
lines changed

examples/asgard/src/asgard_json.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import json
2323
import sys
2424

25+
2526
def main():
2627
obj = None
2728
sys.stderr.write("args.in_json = %r." % args.in_json)
@@ -36,8 +37,10 @@ def main():
3637

3738
json.dump(obj, sys.stdout, indent=4)
3839

40+
3941
if __name__ == "__main__":
4042
import argparse
43+
4144
parser = argparse.ArgumentParser()
4245
parser.add_argument("in_json", nargs="+")
4346
args = parser.parse_args()

examples/asgard/src/test_asgard.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020

2121
NSDICT = {"sh": NS_SH}
2222

23-
def load_validation_graph(
24-
filename : str,
25-
expected_conformance : bool
26-
) -> rdflib.Graph:
23+
24+
def load_validation_graph(filename: str, expected_conformance: bool) -> rdflib.Graph:
2725
g = rdflib.Graph()
2826
g.parse(filename, format="turtle")
2927
g.namespace_manager.bind("sh", NS_SH)
3028

31-
query = rdflib.plugins.sparql.prepareQuery("""\
29+
query = rdflib.plugins.sparql.prepareQuery(
30+
"""\
3231
SELECT ?lConforms
3332
WHERE {
3433
?nReport
3534
a sh:ValidationReport ;
3635
sh:conforms ?lConforms ;
3736
.
3837
}
39-
""", initNs=NSDICT)
38+
""",
39+
initNs=NSDICT,
40+
)
4041

4142
computed_conformance = None
4243
for result in g.query(query):
@@ -45,11 +46,17 @@ def load_validation_graph(
4546
assert expected_conformance == computed_conformance
4647
return g
4748

48-
#TODO
49-
@pytest.mark.xfail(reason="At least one issue known present with vocabulary items. Once UCO ticket OC-12 is resolved, this xfail annotation should be removed.", strict=True)
49+
50+
# TODO
51+
@pytest.mark.xfail(
52+
reason="At least one issue known present with vocabulary items. Once UCO ticket OC-12 is resolved, this xfail annotation should be removed.",
53+
strict=True,
54+
)
5055
def test_asgard_validation():
5156
"""
5257
Confirm the instance data passes validation.
5358
"""
54-
g = load_validation_graph(os.path.join(os.path.dirname(__file__), "asgard_validation.ttl"), True)
59+
g = load_validation_graph(
60+
os.path.join(os.path.dirname(__file__), "asgard_validation.ttl"), True
61+
)
5562
assert isinstance(g, rdflib.Graph)

examples/crossover/src/crossover_json.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
_logger = logging.getLogger(os.path.basename(__file__))
2828

29+
2930
def main():
3031
obj = None
3132
with open(args.in_base_json, "r") as in_fh:
@@ -48,12 +49,14 @@ def main():
4849

4950
json.dump(obj, sys.stdout, indent=4)
5051

52+
5153
if __name__ == "__main__":
5254
import argparse
55+
5356
parser = argparse.ArgumentParser()
5457
parser.add_argument("in_base_json")
5558
parser.add_argument("in_json", nargs="*")
5659
args = parser.parse_args()
57-
#logging.basicConfig(level=logging.DEBUG)
60+
# logging.basicConfig(level=logging.DEBUG)
5861
logging.basicConfig(level=logging.INFO)
5962
main()

examples/owl_trafficking/src/owl_trafficking_json.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
_logger = logging.getLogger(os.path.basename(__file__))
2828

29+
2930
def main():
3031
obj = None
3132
with open(args.in_base_json, "r") as in_fh:
@@ -44,12 +45,14 @@ def main():
4445

4546
json.dump(obj, sys.stdout, indent=4)
4647

48+
4749
if __name__ == "__main__":
4850
import argparse
51+
4952
parser = argparse.ArgumentParser()
5053
parser.add_argument("in_base_json")
5154
parser.add_argument("in_json", nargs="+")
5255
args = parser.parse_args()
53-
#logging.basicConfig(level=logging.DEBUG)
56+
# logging.basicConfig(level=logging.DEBUG)
5457
logging.basicConfig(level=logging.INFO)
5558
main()

examples/owl_trafficking/test_owl_trafficking.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020

2121
NSDICT = {"sh": NS_SH}
2222

23-
def load_validation_graph(
24-
filename : str,
25-
expected_conformance : bool
26-
) -> rdflib.Graph:
23+
24+
def load_validation_graph(filename: str, expected_conformance: bool) -> rdflib.Graph:
2725
g = rdflib.Graph()
2826
g.parse(filename, format="turtle")
2927
g.namespace_manager.bind("sh", NS_SH)
3028

31-
query = rdflib.plugins.sparql.prepareQuery("""\
29+
query = rdflib.plugins.sparql.prepareQuery(
30+
"""\
3231
SELECT ?lConforms
3332
WHERE {
3433
?nReport
3534
a sh:ValidationReport ;
3635
sh:conforms ?lConforms ;
3736
.
3837
}
39-
""", initNs=NSDICT)
38+
""",
39+
initNs=NSDICT,
40+
)
4041

4142
computed_conformance = None
4243
for result in g.query(query):
@@ -45,11 +46,17 @@ def load_validation_graph(
4546
assert expected_conformance == computed_conformance
4647
return g
4748

48-
#TODO
49-
@pytest.mark.xfail(reason="At least one issue known present with vocabulary items. Once UCO ticket OC-12 is resolved, this xfail annotation should be removed.", strict=True)
49+
50+
# TODO
51+
@pytest.mark.xfail(
52+
reason="At least one issue known present with vocabulary items. Once UCO ticket OC-12 is resolved, this xfail annotation should be removed.",
53+
strict=True,
54+
)
5055
def test_owl_trafficking_validation():
5156
"""
5257
Confirm the instance data passes validation.
5358
"""
54-
g = load_validation_graph(os.path.join(os.path.dirname(__file__), "owl_trafficking_validation.ttl"), True)
59+
g = load_validation_graph(
60+
os.path.join(os.path.dirname(__file__), "owl_trafficking_validation.ttl"), True
61+
)
5562
assert isinstance(g, rdflib.Graph)

examples/urgent_evidence/src/test_urgent_evidence.py

Lines changed: 71 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,27 @@
3232
graph.parse(str(top_srcdir / "dependencies" / "CASE-unstable.ttl"))
3333

3434
# Inherit prefixes defined in input context dictionary.
35-
nsdict = {k:v for (k,v) in graph.namespace_manager.namespaces()}
35+
nsdict = {k: v for (k, v) in graph.namespace_manager.namespaces()}
3636
nsdict["sh"] = NS_SH
3737

38-
def load_validation_graph(
39-
filename : str,
40-
expected_conformance : bool
41-
) -> rdflib.Graph:
38+
39+
def load_validation_graph(filename: str, expected_conformance: bool) -> rdflib.Graph:
4240
g = rdflib.Graph()
4341
g.parse(filename, format="turtle")
4442
g.namespace_manager.bind("sh", NS_SH)
4543

46-
query = rdflib.plugins.sparql.prepareQuery("""\
44+
query = rdflib.plugins.sparql.prepareQuery(
45+
"""\
4746
SELECT ?lConforms
4847
WHERE {
4948
?nReport
5049
a sh:ValidationReport ;
5150
sh:conforms ?lConforms ;
5251
.
5352
}
54-
""", initNs=nsdict)
53+
""",
54+
initNs=nsdict,
55+
)
5556

5657
computed_conformance = None
5758
for result in g.query(query):
@@ -60,76 +61,91 @@ def load_validation_graph(
6061
assert expected_conformance == computed_conformance
6162
return g
6263

64+
6365
@pytest.fixture
6466
def action_iris_all():
6567
retval = set()
66-
select_query_object = rdflib.plugins.sparql.prepareQuery("""\
68+
select_query_object = rdflib.plugins.sparql.prepareQuery(
69+
"""\
6770
SELECT ?nAction
6871
WHERE {
6972
?nAction a case-investigation:InvestigativeAction .
7073
}
71-
""", initNs=nsdict)
74+
""",
75+
initNs=nsdict,
76+
)
7277
for record in graph.query(select_query_object):
7378
retval.add(record[0].toPython())
7479
assert len(retval) > 0, "Failed to retrieve investigative actions."
7580
return retval
7681

82+
7783
def test_actions_to_photo(action_iris_all):
7884
action_iris_computed = set()
7985
action_iris_ground_truth_positive = {
80-
"http://example.org/kb/action-uuid-1",
81-
"http://example.org/kb/action-uuid-3",
82-
"http://example.org/kb/action-uuid-7"
86+
"http://example.org/kb/action-uuid-1",
87+
"http://example.org/kb/action-uuid-3",
88+
"http://example.org/kb/action-uuid-7",
8389
}
84-
action_iris_ground_truth_negative = action_iris_all - action_iris_ground_truth_positive
90+
action_iris_ground_truth_negative = (
91+
action_iris_all - action_iris_ground_truth_positive
92+
)
8593

8694
_logger.debug("len(action_iris_all) = %d.", len(action_iris_all))
87-
_logger.debug("len(action_iris_ground_truth_positive) = %d.", len(action_iris_ground_truth_positive))
88-
_logger.debug("len(action_iris_ground_truth_negative) = %d.", len(action_iris_ground_truth_negative))
95+
_logger.debug(
96+
"len(action_iris_ground_truth_positive) = %d.",
97+
len(action_iris_ground_truth_positive),
98+
)
99+
_logger.debug(
100+
"len(action_iris_ground_truth_negative) = %d.",
101+
len(action_iris_ground_truth_negative),
102+
)
89103

90104
select_query_text = None
91105
with open("query-actions_to_artifact.sparql", "r") as in_fh:
92106
select_query_text = in_fh.read().strip()
93107
_logger.debug("select_query_text = %r." % select_query_text)
94-
select_query_object = rdflib.plugins.sparql.prepareQuery(select_query_text, initNs=nsdict)
108+
select_query_object = rdflib.plugins.sparql.prepareQuery(
109+
select_query_text, initNs=nsdict
110+
)
95111
for record in graph.query(select_query_object):
96-
(
97-
n_deriving_action,
98-
l_description
99-
) = record
112+
(n_deriving_action, l_description) = record
100113
action_iris_computed.add(n_deriving_action.toPython())
101114

102115
action_iris_true_positive = action_iris_computed & action_iris_ground_truth_positive
103116
assert action_iris_ground_truth_positive == action_iris_true_positive
104117

105-
action_iris_false_positive = action_iris_computed & action_iris_ground_truth_negative
118+
action_iris_false_positive = (
119+
action_iris_computed & action_iris_ground_truth_negative
120+
)
106121
assert set() == action_iris_false_positive
107122

123+
108124
def test_exhibit_photos():
109125
file_names_computed = set()
110126
file_names_ground_truth_positive = {
111-
"IMG_4829.jpg",
112-
"IMG_4830.jpg",
113-
"IMG_4831.jpg",
114-
"IMG_4832.jpg",
115-
"IMG_4833.jpg",
116-
"IMG_4834.jpg"
117-
}
118-
file_names_ground_truth_negative = {
119-
"IMG_1863.jpg"
127+
"IMG_4829.jpg",
128+
"IMG_4830.jpg",
129+
"IMG_4831.jpg",
130+
"IMG_4832.jpg",
131+
"IMG_4833.jpg",
132+
"IMG_4834.jpg",
120133
}
134+
file_names_ground_truth_negative = {"IMG_1863.jpg"}
121135

122136
select_query_text = None
123137
with open("query-exhibit_photos.sparql", "r") as in_fh:
124138
select_query_text = in_fh.read().strip()
125139
_logger.debug("select_query_text = %r." % select_query_text)
126-
select_query_object = rdflib.plugins.sparql.prepareQuery(select_query_text, initNs=nsdict)
140+
select_query_object = rdflib.plugins.sparql.prepareQuery(
141+
select_query_text, initNs=nsdict
142+
)
127143
for record in graph.query(select_query_object):
128144
(
129-
l_exhibit_number,
130-
l_file_name,
131-
l_modified_time,
132-
l_hash_value,
145+
l_exhibit_number,
146+
l_file_name,
147+
l_modified_time,
148+
l_hash_value,
133149
) = record
134150
file_names_computed.add(l_file_name.toPython())
135151
_logger.debug("file_names_computed = %r.", file_names_computed)
@@ -140,36 +156,41 @@ def test_exhibit_photos():
140156
file_names_false_positive = file_names_computed & file_names_ground_truth_negative
141157
assert set() == file_names_false_positive
142158

159+
143160
def test_photo_selection():
144161
file_name_status_computed = set()
145162
file_name_status_expected = {
146-
("IMG_1863.jpg", "Selected"),
147-
("IMG_1864.jpg", "Displayed"),
148-
("IMG_1865.jpg", "Not displayed")
163+
("IMG_1863.jpg", "Selected"),
164+
("IMG_1864.jpg", "Displayed"),
165+
("IMG_1865.jpg", "Not displayed"),
149166
}
150167

151168
select_query_text = None
152169
with open("query-selection_from_automated_exhibit_extraction.sparql", "r") as in_fh:
153170
select_query_text = in_fh.read().strip()
154171
_logger.debug("select_query_text = %r." % select_query_text)
155-
select_query_object = rdflib.plugins.sparql.prepareQuery(select_query_text, initNs=nsdict)
172+
select_query_object = rdflib.plugins.sparql.prepareQuery(
173+
select_query_text, initNs=nsdict
174+
)
156175
for record in graph.query(select_query_object):
157-
(
158-
l_file_name,
159-
l_review_status
160-
) = record
161-
file_name_status_computed.add((
162-
l_file_name.toPython(),
163-
l_review_status.toPython()
164-
))
176+
(l_file_name, l_review_status) = record
177+
file_name_status_computed.add(
178+
(l_file_name.toPython(), l_review_status.toPython())
179+
)
165180

166181
assert file_name_status_expected == file_name_status_computed
167182

168-
#TODO
169-
@pytest.mark.xfail(reason="At least one issue known present with vocabulary items. Once UCO ticket OC-12 is resolved, this xfail annotation should be removed.", strict=True)
183+
184+
# TODO
185+
@pytest.mark.xfail(
186+
reason="At least one issue known present with vocabulary items. Once UCO ticket OC-12 is resolved, this xfail annotation should be removed.",
187+
strict=True,
188+
)
170189
def test_urgent_evidence_validation():
171190
"""
172191
Confirm the instance data passes validation.
173192
"""
174-
g = load_validation_graph(os.path.join(os.path.dirname(__file__), "urgent_evidence_validation.ttl"), True)
193+
g = load_validation_graph(
194+
os.path.join(os.path.dirname(__file__), "urgent_evidence_validation.ttl"), True
195+
)
175196
assert isinstance(g, rdflib.Graph)

examples/urgent_evidence/src/urgent_evidence_json.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import argparse
2424
import sys
2525

26+
2627
def main():
2728
parser = argparse.ArgumentParser()
2829
parser.add_argument("in_json")
@@ -31,5 +32,6 @@ def main():
3132
with open(args.in_json, "r") as in_fh:
3233
sys.stdout.write(in_fh.read())
3334

35+
3436
if __name__ == "__main__":
3537
main()

0 commit comments

Comments
 (0)