Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions extruct/_extruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def extract(
if errors == "ignore":
return {}
if errors == "log":
logger.exception("Failed to parse html, raises {}".format(e))
logger.exception(f"Failed to parse html, raises {e}")
return {}
if errors == "strict":
raise
Expand Down Expand Up @@ -131,7 +131,7 @@ def extract(
output[syntax] = list(extract(document, base_url=base_url))
except Exception as e:
if errors == "log":
logger.exception("Failed to extract {}, raises {}".format(syntax, e))
logger.exception(f"Failed to extract {syntax}, raises {e}")
if errors == "ignore":
pass
if errors == "strict":
Expand Down
2 changes: 1 addition & 1 deletion extruct/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def metadata_from_url(
resp = requests.get(url, timeout=30)
result: dict[str, Any] = {
"url": url,
"status": "{} {}".format(resp.status_code, resp.reason),
"status": f"{resp.status_code} {resp.reason}",
}
try:
resp.raise_for_status()
Expand Down
10 changes: 4 additions & 6 deletions tests/test_jsonld.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def assertJsonLdCorrect(self, folder, page):
self._check_jsonld(body, expected)

def _get_body_expected(self, folder, page):
body = get_testdata(folder, "{}.html".format(page))
expected = get_testdata(folder, "{}.jsonld".format(page))
body = get_testdata(folder, f"{page}.html")
expected = get_testdata(folder, f"{page}.jsonld")
return body, json.loads(expected.decode("utf8"))

def _check_jsonld(self, body, expected):
Expand All @@ -55,10 +55,8 @@ def _check_jsonld(self, body, expected):

def test_null(self):
page = "null_ld_mock"
body = get_testdata("misc", "{}.html".format(page))
expected = json.loads(
get_testdata("misc", "{}.jsonld".format(page)).decode("UTF-8")
)
body = get_testdata("misc", f"{page}.html")
expected = json.loads(get_testdata("misc", f"{page}.jsonld").decode("UTF-8"))

jsonlde = JsonLdExtractor()
data = jsonlde.extract(body)
Expand Down
28 changes: 12 additions & 16 deletions tests/test_microdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ def _test_schemaorg(self, schema, indexes=None):

def test_schemaorg_CreativeWork(self):
for i in [1]:
body = get_testdata("schema.org", "CreativeWork.{:03d}.html".format(i))
body = get_testdata("schema.org", f"CreativeWork.{i:03d}.html")
expected = json.loads(
get_testdata("schema.org", "CreativeWork.{:03d}.json".format(i)).decode(
"UTF-8"
)
get_testdata("schema.org", f"CreativeWork.{i:03d}.json").decode("UTF-8")
)

mde = MicrodataExtractor()
Expand All @@ -36,11 +34,11 @@ def test_schemaorg_CreativeWork(self):

def test_schemaorg_LocalBusiness(self):
for i in [2, 3]:
body = get_testdata("schema.org", "LocalBusiness.{:03d}.html".format(i))
body = get_testdata("schema.org", f"LocalBusiness.{i:03d}.html")
expected = json.loads(
get_testdata(
"schema.org", "LocalBusiness.{:03d}.json".format(i)
).decode("UTF-8")
get_testdata("schema.org", f"LocalBusiness.{i:03d}.json").decode(
"UTF-8"
)
)

mde = MicrodataExtractor()
Expand All @@ -49,11 +47,11 @@ def test_schemaorg_LocalBusiness(self):

def test_schemaorg_MusicRecording(self):
for i in [1]:
body = get_testdata("schema.org", "MusicRecording.{:03d}.html".format(i))
body = get_testdata("schema.org", f"MusicRecording.{i:03d}.html")
expected = json.loads(
get_testdata(
"schema.org", "MusicRecording.{:03d}.json".format(i)
).decode("UTF-8")
get_testdata("schema.org", f"MusicRecording.{i:03d}.json").decode(
"UTF-8"
)
)

mde = MicrodataExtractor()
Expand All @@ -62,11 +60,9 @@ def test_schemaorg_MusicRecording(self):

def test_schemaorg_Event(self):
for i in [1, 2, 3, 4, 8]:
body = get_testdata("schema.org", "Event.{:03d}.html".format(i))
body = get_testdata("schema.org", f"Event.{i:03d}.html")
expected = json.loads(
get_testdata("schema.org", "Event.{:03d}.json".format(i)).decode(
"UTF-8"
)
get_testdata("schema.org", f"Event.{i:03d}.json").decode("UTF-8")
)

mde = MicrodataExtractor()
Expand Down
6 changes: 3 additions & 3 deletions tests/test_rdfa.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def prettify(self, a, normalize_bnode_ids=True):

def test_w3c_rdfalite(self):
for i in [3, 4, 5]:
fileprefix = "w3c.rdfalite.example{:03d}".format(i)
fileprefix = f"w3c.rdfalite.example{i:03d}"
body = get_testdata("w3crdfa", fileprefix + ".html")
expected = json.loads(
get_testdata("w3crdfa", fileprefix + ".expanded.json").decode("UTF-8")
Expand All @@ -67,7 +67,7 @@ def test_w3c_rdfalite(self):

def test_w3c_rdf11primer(self):
for i in [14]:
fileprefix = "w3c.rdf11primer.example{:03d}".format(i)
fileprefix = f"w3c.rdf11primer.example{i:03d}"
body = get_testdata("w3crdfa", fileprefix + ".html")
expected = json.loads(
get_testdata("w3crdfa", fileprefix + ".expanded.json").decode("UTF-8")
Expand All @@ -79,7 +79,7 @@ def test_w3c_rdf11primer(self):

def test_w3c_rdfaprimer(self):
for i in [5, 6, 7, 8, 9, 10, 11, 15]:
fileprefix = "w3c.rdfaprimer.example{:03d}".format(i)
fileprefix = f"w3c.rdfaprimer.example{i:03d}"
print(fileprefix)
body = get_testdata("w3crdfa", fileprefix + ".html")
expected = json.loads(
Expand Down
12 changes: 4 additions & 8 deletions tests/test_uniform.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ def test_uopengraph_duplicated_priorities(self):
[
{
"properties": [
("prop_{}".format(k), "value_{}".format(v))
for k in range(5)
for v in range(5)
(f"prop_{k}", f"value_{v}") for k in range(5) for v in range(5)
],
"namespace": "namespace",
}
]
)
for k in range(5):
assert data[0]["prop_{}".format(k)] == "value_0"
assert data[0][f"prop_{k}"] == "value_0"

# Ensures that empty is not returned if a property contains any
# non empty value
Expand Down Expand Up @@ -104,17 +102,15 @@ def test_uopengraph_duplicated_with_og_array(self):
[
{
"properties": [
("prop_{}".format(k), "value_{}".format(v))
for k in range(5)
for v in range(5)
(f"prop_{k}", f"value_{v}") for k in range(5) for v in range(5)
],
"namespace": "namespace",
}
],
with_og_array=True,
)
for k in range(5):
assert data[0]["prop_{}".format(k)] == [
assert data[0][f"prop_{k}"] == [
"value_0",
"value_1",
"value_2",
Expand Down
Loading