1+ import json
12import os
23import re
34import subprocess
1718DEFAULT_TEST_BASE = 'https://w3c.github.io/json-ld-api/tests'
1819
1920_SKIP_ID_PATTERN = re .compile (r'^\.\*(?P<manifest>[^#]+)#(?P<test_id>[^$]+)\$$' )
21+ _MANIFEST_PATHS = (
22+ ROOT_DIR / 'specifications' / 'json-ld-api' / 'tests' ,
23+ ROOT_DIR / 'specifications' / 'json-ld-framing' / 'tests' ,
24+ )
2025
2126
2227def _parse_skip_id_regex (pattern ):
@@ -28,7 +33,73 @@ def _parse_skip_id_regex(pattern):
2833
2934def _test_url (manifest , test_id ):
3035 base = MANIFEST_BASES .get (manifest , DEFAULT_TEST_BASE )
31- return f'{ base } /{ manifest } #{ test_id } '
36+ return f'{ base } /{ manifest } .html#{ test_id } '
37+
38+
39+ def _jsonld_values (data , key ):
40+ if key not in data :
41+ return []
42+ value = data [key ]
43+ return value if isinstance (value , list ) else [value ]
44+
45+
46+ def _entry_test_types (entry ):
47+ values = []
48+ values .extend (_jsonld_values (entry , '@type' ))
49+ values .extend (_jsonld_values (entry , 'type' ))
50+ return values
51+
52+
53+ def _manifest_entries ():
54+ for manifest_dir in _MANIFEST_PATHS :
55+ if not manifest_dir .exists ():
56+ continue
57+ for path in sorted (manifest_dir .glob ('*-manifest.jsonld' )):
58+ data = json .loads (path .read_text ())
59+ manifest = path .stem
60+ for entry in _jsonld_values (data , 'sequence' ):
61+ if not isinstance (entry , dict ):
62+ continue
63+ test_id = entry .get ('@id' , entry .get ('id' , '' ))
64+ if test_id .startswith ('#' ):
65+ test_id = test_id [1 :]
66+ yield {
67+ 'entry' : entry ,
68+ 'id' : f'{ manifest } #{ test_id } ' ,
69+ 'link' : f'[{ test_id } ]({ _test_url (manifest , test_id )} )' ,
70+ 'types' : _entry_test_types (entry ),
71+ }
72+
73+
74+ def _skip_reason (test_type , skip , test ):
75+ test_id = test ['id' ]
76+ entry = test ['entry' ]
77+ for pattern in skip .get ('idRegex' , []):
78+ if re .match (pattern , test_id ):
79+ return f'Explicit skip (`{ test_type } `)'
80+
81+ for pattern in skip .get ('descriptionRegex' , []):
82+ if re .match (pattern , entry .get ('description' , '' )):
83+ return f'Description skip (`{ test_type } `)'
84+
85+ processing_mode = entry .get ('option' , {}).get ('processingMode' )
86+ if processing_mode in skip .get ('processingMode' , []):
87+ return f'Processing mode `{ processing_mode } ` (`{ test_type } `)'
88+
89+ spec_version = entry .get ('option' , {}).get ('specVersion' )
90+ if spec_version in skip .get ('specVersion' , []):
91+ return f'Spec version `{ spec_version } ` (`{ test_type } `)'
92+
93+ return None
94+
95+
96+ def _pending_reason (test_type , pending , test ):
97+ test_id = test ['id' ]
98+ for pattern in pending .get ('idRegex' , []):
99+ if re .match (pattern , test_id ):
100+ return f'Pending expected failure (`{ test_type } `)'
101+
102+ return None
32103
33104
34105def _example_path (name ):
@@ -76,37 +147,58 @@ def bundled_contexts_table():
76147 def skipped_tests_table ():
77148 from runtests import TEST_TYPES
78149
79- rows = [
80- '| Reason | Skipped tests |' ,
81- '| --- | --- |' ,
82- ]
150+ skipped_or_pending = {}
151+ seen_links = set ()
152+ tests = list (_manifest_entries ())
83153
84- linked_tests = []
85- seen_tests = set ()
86154 for test_type , config in sorted (TEST_TYPES .items ()):
87155 skip = config .get ('skip' , {})
88- spec_versions = skip .get ('specVersion' , [])
89- if 'json-ld-1.0' in spec_versions :
90- rows .append (
91- f'| JSON-LD 1.0 processor behavior (`{ test_type } `) | '
92- f'All JSON-LD 1.0 tests |'
156+ pending = config .get ('pending' , {})
157+
158+ for test in tests :
159+ if test_type not in test ['types' ]:
160+ continue
161+ reason = _skip_reason (test_type , skip , test ) or _pending_reason (
162+ test_type , pending , test
93163 )
164+ if not reason or test ['link' ] in seen_links :
165+ continue
166+ skipped_or_pending .setdefault (reason , []).append (test ['link' ])
167+ seen_links .add (test ['link' ])
94168
95169 for pattern in skip .get ('idRegex' , []):
96170 parsed = _parse_skip_id_regex (pattern )
97171 if not parsed :
98172 continue
99173 manifest , test_id = parsed
100- url = _test_url (manifest , test_id )
101- if url in seen_tests :
174+ link = f'[{ test_id } ]({ _test_url (manifest , test_id )} )'
175+ if link in seen_links :
176+ continue
177+ skipped_or_pending .setdefault (
178+ f'Explicit skip (`{ test_type } `)' , []
179+ ).append (link )
180+ seen_links .add (link )
181+
182+ for pattern in pending .get ('idRegex' , []):
183+ parsed = _parse_skip_id_regex (pattern )
184+ if not parsed :
185+ continue
186+ manifest , test_id = parsed
187+ link = f'[{ test_id } ]({ _test_url (manifest , test_id )} )'
188+ if link in seen_links :
102189 continue
103- seen_tests .add (url )
104- linked_tests .append (f'[{ test_id } ]({ url } )' )
190+ skipped_or_pending .setdefault (
191+ f'Pending expected failure (`{ test_type } `)' , []
192+ ).append (link )
193+ seen_links .add (link )
194+
195+ rows = [
196+ '| Reason | Tests |' ,
197+ '| --- | --- |' ,
198+ ]
105199
106- if linked_tests :
107- rows .append (
108- '| Explicitly skipped test cases | ' + ', ' .join (linked_tests ) + ' |'
109- )
200+ for reason , links in sorted (skipped_or_pending .items ()):
201+ rows .append (f'| { reason } | { ", " .join (sorted (links ))} |' )
110202
111203 return '\n ' .join (rows )
112204
0 commit comments