Update web-platform-tests to revision 3b3585e368841b77caea8576fa56cef91c3fbdf0

This commit is contained in:
Ms2ger 2016-09-26 10:52:50 +02:00
parent d00639c55f
commit 3b4f0ec0bb
541 changed files with 14609 additions and 3288 deletions

View file

@ -12,10 +12,10 @@ import sys
from collections import defaultdict
from .. import localpaths
from ..localpaths import repo_root
from manifest.sourcefile import SourceFile
from six import iteritems
from six import iteritems, itervalues
from six.moves import range
here = os.path.abspath(os.path.split(__file__)[0])
@ -52,6 +52,7 @@ def parse_whitelist(f):
"""
data = defaultdict(lambda:defaultdict(set))
ignored_files = set()
for line in f:
line = line.strip()
@ -64,9 +65,13 @@ def parse_whitelist(f):
parts[-1] = int(parts[-1])
error_type, file_match, line_number = parts
data[file_match][error_type].add(line_number)
return data
if error_type == "*":
ignored_files.add(file_match)
else:
data[file_match][error_type].add(line_number)
return data, ignored_files
def filter_whitelist_errors(data, path, errors):
@ -79,9 +84,7 @@ def filter_whitelist_errors(data, path, errors):
for file_match, whitelist_errors in iteritems(data):
if fnmatch.fnmatch(path, file_match):
for i, (error_type, msg, path, line) in enumerate(errors):
if "*" in whitelist_errors:
whitelisted[i] = True
elif error_type in whitelist_errors:
if error_type in whitelist_errors:
allowed_lines = whitelist_errors[error_type]
if None in allowed_lines or line in allowed_lines:
whitelisted[i] = True
@ -240,6 +243,14 @@ def check_parsed(repo_root, path, f):
if all(seen_elements[name] for name in required_elements):
break
for element in source_file.root.findall(".//{http://www.w3.org/1999/xhtml}script[@src]"):
src = element.attrib["src"]
for name in ["testharness", "testharnessreport"]:
if "%s.js" % name == src or ("/%s.js" % name in src and src != "/resources/%s.js" % name):
errors.append(("%s-PATH" % name.upper(), "%s.js script seen with incorrect path" % name, path, None))
return errors
class ASTCheck(object):
@ -347,7 +358,6 @@ def parse_args():
return parser.parse_args()
def main():
repo_root = localpaths.repo_root
args = parse_args()
paths = args.paths if args.paths else all_git_paths(repo_root)
return lint(repo_root, paths, args.json)
@ -357,7 +367,7 @@ def lint(repo_root, paths, output_json):
last = None
with open(os.path.join(repo_root, "lint.whitelist")) as f:
whitelist = parse_whitelist(f)
whitelist, ignored_files = parse_whitelist(f)
if output_json:
output_errors = output_errors_json
@ -390,11 +400,14 @@ def lint(repo_root, paths, output_json):
if not os.path.exists(abs_path):
continue
if any(fnmatch.fnmatch(path, file_match) for file_match in ignored_files):
continue
errors = check_path(repo_root, path)
last = process_errors(path, errors) or last
if not os.path.isdir(abs_path):
with open(abs_path) as f:
with open(abs_path, 'rb') as f:
errors = check_file_contents(repo_root, path, f)
last = process_errors(path, errors) or last
@ -402,7 +415,7 @@ def lint(repo_root, paths, output_json):
output_error_count(error_count)
if error_count:
print(ERROR_MSG % (last[0], last[1], last[0], last[1]))
return sum(error_count.itervalues())
return sum(itervalues(error_count))
path_lints = [check_path_length]
file_lints = [check_regexp_line, check_parsed, check_python_ast]

View file

@ -0,0 +1 @@
THIS LINE HAS TRAILING WHITESPACE

View file

@ -0,0 +1 @@
THIS LINE HAS TRAILING WHITESPACE

View file

@ -0,0 +1 @@
*:broken_ignored.html

View file

@ -0,0 +1 @@
THIS LINE HAS NO TRAILING WHITESPACE

View file

@ -221,6 +221,75 @@ def test_present_testharnesscss():
]
def test_testharness_path():
code = b"""\
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="testharness.js"></script>
<script src="resources/testharness.js"></script>
<script src="../resources/testharness.js"></script>
<script src="http://w3c-test.org/resources/testharness.js"></script>
</html>
"""
error_map = check_with_files(code)
for (filename, (errors, kind)) in error_map.items():
expected = [("W3C-TEST.ORG", "External w3c-test.org domain used", filename, 5)]
if kind == "python":
expected.append(("PARSE-FAILED", "Unable to parse file", filename, 1))
elif kind in ["web-lax", "web-strict"]:
expected.extend([
("TESTHARNESS-PATH", "testharness.js script seen with incorrect path", filename, None),
("TESTHARNESS-PATH", "testharness.js script seen with incorrect path", filename, None),
("TESTHARNESS-PATH", "testharness.js script seen with incorrect path", filename, None),
("TESTHARNESS-PATH", "testharness.js script seen with incorrect path", filename, None),
])
assert errors == expected
def test_testharnessreport_path():
code = b"""\
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="testharnessreport.js"></script>
<script src="resources/testharnessreport.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="http://w3c-test.org/resources/testharnessreport.js"></script>
</html>
"""
error_map = check_with_files(code)
for (filename, (errors, kind)) in error_map.items():
expected = [("W3C-TEST.ORG", "External w3c-test.org domain used", filename, 5)]
if kind == "python":
expected.append(("PARSE-FAILED", "Unable to parse file", filename, 1))
elif kind in ["web-lax", "web-strict"]:
expected.extend([
("TESTHARNESSREPORT-PATH", "testharnessreport.js script seen with incorrect path", filename, None),
("TESTHARNESSREPORT-PATH", "testharnessreport.js script seen with incorrect path", filename, None),
("TESTHARNESSREPORT-PATH", "testharnessreport.js script seen with incorrect path", filename, None),
("TESTHARNESSREPORT-PATH", "testharnessreport.js script seen with incorrect path", filename, None),
])
assert errors == expected
def test_not_testharness_path():
code = b"""\
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/webperftestharness.js"></script>
</html>
"""
error_map = check_with_files(code)
for (filename, (errors, kind)) in error_map.items():
if kind == "python":
assert errors == [
("PARSE-FAILED", "Unable to parse file", filename, 1),
]
else:
assert errors == []
@pytest.mark.skipif(six.PY3, reason="Cannot parse print statements from python 3")
def test_print_statement():
error_map = check_with_files(b"def foo():\n print 'statement'\n print\n")

View file

@ -1,9 +1,23 @@
from __future__ import unicode_literals
from ..lint import filter_whitelist_errors, parse_whitelist
import os
import mock
import pytest
import six
def test_lint():
from .. import lint as lint_mod
from ..lint import filter_whitelist_errors, parse_whitelist, lint
_dummy_repo = os.path.join(os.path.dirname(__file__), "dummy")
def _mock_lint(name):
wrapped = getattr(lint_mod, name)
return mock.patch(lint_mod.__name__ + "." + name, wraps=wrapped)
def test_filter_whitelist_errors():
filtered = filter_whitelist_errors({}, '', [])
assert filtered == []
@ -26,10 +40,7 @@ CONSOLE:streams/resources/test-utils.js: 12
*:resources/*
""")
expected = {
'*.pdf': {
'*': {None},
},
expected_data = {
'.gitmodules': {
'INDENT TABS': {None},
},
@ -37,9 +48,6 @@ CONSOLE:streams/resources/test-utils.js: 12
'TRAILING WHITESPACE': {None},
'INDENT TABS': {None},
},
'resources/*': {
'*': {None},
},
'streams/resources/test-utils.js': {
'CONSOLE': {12},
'CR AT EOL': {None},
@ -51,4 +59,80 @@ CONSOLE:streams/resources/test-utils.js: 12
'CR AT EOL': {None},
},
}
assert parse_whitelist(input_buffer) == expected
expected_ignored = {"*.pdf", "resources/*"}
data, ignored = parse_whitelist(input_buffer)
assert data == expected_data
assert ignored == expected_ignored
def test_lint_no_files(capsys):
rv = lint(_dummy_repo, [], False)
assert rv == 0
out, err = capsys.readouterr()
assert out == ""
assert err == ""
def test_lint_ignored_file(capsys):
with _mock_lint("check_path") as mocked_check_path:
with _mock_lint("check_file_contents") as mocked_check_file_contents:
rv = lint(_dummy_repo, ["broken_ignored.html"], False)
assert rv == 0
assert not mocked_check_path.called
assert not mocked_check_file_contents.called
out, err = capsys.readouterr()
assert out == ""
assert err == ""
def test_lint_not_existing_file(capsys):
with _mock_lint("check_path") as mocked_check_path:
with _mock_lint("check_file_contents") as mocked_check_file_contents:
# really long path-linted filename
name = "a" * 256 + ".html"
rv = lint(_dummy_repo, [name], False)
assert rv == 0
assert not mocked_check_path.called
assert not mocked_check_file_contents.called
out, err = capsys.readouterr()
assert out == ""
assert err == ""
def test_lint_passing(capsys):
with _mock_lint("check_path") as mocked_check_path:
with _mock_lint("check_file_contents") as mocked_check_file_contents:
rv = lint(_dummy_repo, ["okay.html"], False)
assert rv == 0
assert mocked_check_path.call_count == 1
assert mocked_check_file_contents.call_count == 1
out, err = capsys.readouterr()
assert out == ""
assert err == ""
def test_lint_failing(capsys):
with _mock_lint("check_path") as mocked_check_path:
with _mock_lint("check_file_contents") as mocked_check_file_contents:
rv = lint(_dummy_repo, ["broken.html"], False)
assert rv == 1
assert mocked_check_path.call_count == 1
assert mocked_check_file_contents.call_count == 1
out, err = capsys.readouterr()
assert "TRAILING WHITESPACE" in out
assert "broken.html 1 " in out
assert err == ""
def test_lint_passing_and_failing(capsys):
with _mock_lint("check_path") as mocked_check_path:
with _mock_lint("check_file_contents") as mocked_check_file_contents:
rv = lint(_dummy_repo, ["broken.html", "okay.html"], False)
assert rv == 1
assert mocked_check_path.call_count == 2
assert mocked_check_file_contents.call_count == 2
out, err = capsys.readouterr()
assert "TRAILING WHITESPACE" in out
assert "broken.html 1 " in out
assert "okay.html" not in out
assert err == ""