Skip to content

Commit 3aaebd5

Browse files
author
Cristi Constantin
committed
Sort the unsorted RDFa values in the tests
1 parent 8e69411 commit 3aaebd5

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

extruct/opengraph.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ def extract_items(self, document, base_url=None):
3030
namespaces.update(self.get_namespaces(head))
3131
props = []
3232
for el in head.xpath('meta[@property and @content]'):
33-
prop = el.attrib['property']
34-
val = el.attrib['content']
33+
prop = el.attrib['property'].strip()
34+
val = el.attrib['content'].strip()
3535
if prop == '' or val == '':
3636
continue
3737
ns = prop.partition(':')[0]

tests/samples/songkick/elysianfields.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,18 @@
231231
],
232232
"http://ogp.me/ns#description": [
233233
{
234-
"@value": "Buy tickets for an upcoming Elysian Fields concert near you. List of all Elysian Fields tickets and tour dates for 2017."
234+
"@value": ""
235235
},
236236
{
237-
"@value": ""
237+
"@value": "Buy tickets for an upcoming Elysian Fields concert near you. List of all Elysian Fields tickets and tour dates for 2017."
238238
}
239239
],
240240
"http://ogp.me/ns#image": [
241241
{
242-
"@value": "http://images.sk-static.com/images/media/img/col4/20100330-103600-169450.jpg"
242+
"@value": "http://images.sk-static.com/SECONDARY_IMAGE.jpg"
243243
},
244244
{
245-
"@value": "http://images.sk-static.com/SECONDARY_IMAGE.jpg"
245+
"@value": "http://images.sk-static.com/images/media/img/col4/20100330-103600-169450.jpg"
246246
}
247247
],
248248
"http://ogp.me/ns#site_name": [

tests/test_extruct.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ def test_all(self):
1616
body = get_testdata('songkick', 'elysianfields.html')
1717
expected = json.loads(get_testdata('songkick', 'elysianfields.json').decode('UTF-8'))
1818
data = extruct.extract(body, base_url='http://www.songkick.com/artists/236156-elysian-fields')
19-
# See test_rdfa_not_preserving_order()
20-
del data['rdfa'][0]['http://ogp.me/ns#image']
21-
del expected['rdfa'][0]['http://ogp.me/ns#image']
19+
for rdf in data['rdfa']:
20+
for key, pairs in rdf.items():
21+
if ':' in key and isinstance(pairs, list):
22+
rdf[key] = sorted(pairs, key=lambda e: e["@value"])
2223
self.assertEqual(jsonize_dict(data), expected)
2324

2425
@pytest.mark.xfail

0 commit comments

Comments
 (0)