mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Update web-platform-tests to revision bf71b1f245ce34e447b7bde8ed46694574a63da7
This commit is contained in:
parent
7256d123ff
commit
e17a773b4e
35 changed files with 1567 additions and 467 deletions
|
@ -9,24 +9,29 @@ import spec_validator
|
|||
import argparse
|
||||
|
||||
|
||||
def expand_test_expansion_pattern(spec_test_expansion, test_expansion_schema):
|
||||
def expand_pattern(expansion_pattern, test_expansion_schema):
|
||||
expansion = {}
|
||||
for artifact in spec_test_expansion:
|
||||
artifact_value = spec_test_expansion[artifact]
|
||||
for artifact_key in expansion_pattern:
|
||||
artifact_value = expansion_pattern[artifact_key]
|
||||
if artifact_value == '*':
|
||||
expansion[artifact] = test_expansion_schema[artifact]
|
||||
expansion[artifact_key] = test_expansion_schema[artifact_key]
|
||||
elif isinstance(artifact_value, list):
|
||||
expansion[artifact] = artifact_value
|
||||
expansion[artifact_key] = artifact_value
|
||||
elif isinstance(artifact_value, dict):
|
||||
# Flattened expansion.
|
||||
expansion[artifact_key] = []
|
||||
values_dict = expand_pattern(artifact_value,
|
||||
test_expansion_schema[artifact_key])
|
||||
for sub_key in values_dict.keys():
|
||||
expansion[artifact_key] += values_dict[sub_key]
|
||||
else:
|
||||
expansion[artifact] = [artifact_value]
|
||||
expansion[artifact_key] = [artifact_value]
|
||||
|
||||
return expansion
|
||||
|
||||
|
||||
def permute_expansion(expansion, selection = {}, artifact_index = 0):
|
||||
artifact_order = ['delivery_method', 'redirection', 'origin',
|
||||
'source_protocol', 'target_protocol', 'subresource',
|
||||
'referrer_url', 'name']
|
||||
def permute_expansion(expansion, artifact_order, selection = {}, artifact_index = 0):
|
||||
assert isinstance(artifact_order, list), "artifact_order should be a list"
|
||||
|
||||
if artifact_index >= len(artifact_order):
|
||||
yield selection
|
||||
|
@ -37,6 +42,7 @@ def permute_expansion(expansion, selection = {}, artifact_index = 0):
|
|||
for artifact_value in expansion[artifact_key]:
|
||||
selection[artifact_key] = artifact_value
|
||||
for next_selection in permute_expansion(expansion,
|
||||
artifact_order,
|
||||
selection,
|
||||
artifact_index + 1):
|
||||
yield next_selection
|
||||
|
@ -116,8 +122,8 @@ def generate_selection(selection, spec, subresource_path,
|
|||
selection['meta_delivery_method'] = "\n " + \
|
||||
selection['meta_delivery_method']
|
||||
|
||||
with open(test_filename, 'w') as f:
|
||||
f.write(test_html_template % selection)
|
||||
# Write out the generated HTML file.
|
||||
write_file(test_filename, test_html_template % selection)
|
||||
|
||||
|
||||
def generate_test_source_files(spec_json, target):
|
||||
|
@ -125,20 +131,22 @@ def generate_test_source_files(spec_json, target):
|
|||
specification = spec_json['specification']
|
||||
|
||||
spec_json_js_template = get_template('spec_json.js.template')
|
||||
with open(generated_spec_json_filename, 'w') as f:
|
||||
f.write(spec_json_js_template
|
||||
% {'spec_json': json.dumps(spec_json)})
|
||||
write_file(generated_spec_json_filename,
|
||||
spec_json_js_template % {'spec_json': json.dumps(spec_json)})
|
||||
|
||||
# Choose a debug/release template depending on the target.
|
||||
html_template = "test.%s.html.template" % target
|
||||
|
||||
artifact_order = test_expansion_schema.keys() + ['name']
|
||||
artifact_order.remove('expansion')
|
||||
|
||||
# Create list of excluded tests.
|
||||
exclusion_dict = {}
|
||||
for excluded_pattern in spec_json['excluded_tests']:
|
||||
excluded_expansion = \
|
||||
expand_test_expansion_pattern(excluded_pattern,
|
||||
test_expansion_schema)
|
||||
for excluded_selection in permute_expansion(excluded_expansion):
|
||||
expand_pattern(excluded_pattern, test_expansion_schema)
|
||||
for excluded_selection in permute_expansion(excluded_expansion,
|
||||
artifact_order):
|
||||
excluded_selection_path = selection_pattern % excluded_selection
|
||||
exclusion_dict[excluded_selection_path] = True
|
||||
|
||||
|
@ -147,14 +155,13 @@ def generate_test_source_files(spec_json, target):
|
|||
# entries with the same |selection_path|.
|
||||
output_dict = {}
|
||||
|
||||
for spec_test_expansion in spec['test_expansion']:
|
||||
expansion = expand_test_expansion_pattern(spec_test_expansion,
|
||||
test_expansion_schema)
|
||||
for selection in permute_expansion(expansion):
|
||||
for expansion_pattern in spec['test_expansion']:
|
||||
expansion = expand_pattern(expansion_pattern, test_expansion_schema)
|
||||
for selection in permute_expansion(expansion, artifact_order):
|
||||
selection_path = selection_pattern % selection
|
||||
if not selection_path in exclusion_dict:
|
||||
if selection_path in output_dict:
|
||||
if spec_test_expansion['expansion'] != 'override':
|
||||
if expansion_pattern['expansion'] != 'override':
|
||||
print("Error: %s's expansion is default but overrides %s" % (selection['name'], output_dict[selection_path]['name']))
|
||||
sys.exit(1)
|
||||
output_dict[selection_path] = copy.deepcopy(selection)
|
||||
|
@ -166,13 +173,13 @@ def generate_test_source_files(spec_json, target):
|
|||
subresource_path = \
|
||||
spec_json["subresource_path"][selection["subresource"]]
|
||||
generate_selection(selection,
|
||||
spec,
|
||||
subresource_path,
|
||||
html_template)
|
||||
spec,
|
||||
subresource_path,
|
||||
html_template)
|
||||
|
||||
|
||||
def main(target):
|
||||
spec_json = load_spec_json();
|
||||
def main(target, spec_filename):
|
||||
spec_json = load_spec_json(spec_filename)
|
||||
spec_validator.assert_valid_spec_json(spec_json)
|
||||
generate_test_source_files(spec_json, target)
|
||||
|
||||
|
@ -182,6 +189,8 @@ if __name__ == '__main__':
|
|||
parser.add_argument('-t', '--target', type = str,
|
||||
choices = ("release", "debug"), default = "release",
|
||||
help = 'Sets the appropriate template for generating tests')
|
||||
parser.add_argument('-s', '--spec', type = str, default = None,
|
||||
help = 'Specify a file used for describing and generating the tests')
|
||||
# TODO(kristijanburnik): Add option for the spec_json file.
|
||||
args = parser.parse_args()
|
||||
main(args.target)
|
||||
main(args.target, args.spec)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue