Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Dec 6, 2024
1 parent fea994b commit 225ded7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
12 changes: 6 additions & 6 deletions tools/lint/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def is_path_correct(script: Text, src: Text) -> bool:
"/resources/%s?" % script)

def is_query_string_correct(script: Text, src: Text,
allowed_query_string_params: Dict[str, List[str]] = {}):
allowed_query_string_params: Dict[str, List[str]] = {}) -> bool:
if not ("%s" % src).startswith("/resources/%s?" % script):
# The src is not related to the script.
return True
Expand All @@ -545,7 +545,7 @@ def is_query_string_correct(script: Text, src: Text,
query_string = urlsplit(urljoin(source_file.url, src)).query
query_string_params = parse_qs(query_string,
keep_blank_values=True)
except ValueError as e:
except ValueError:
# Parsing error means that the query string is incorrect.
return False

Expand All @@ -562,18 +562,18 @@ def is_query_string_correct(script: Text, src: Text,
# Allow for vendor-specific values in query parameters.
continue
if param_value not in allowed_query_string_params[
param_name]:
param_name]:
return False
return True

if not is_path_correct("testharness.js",
src) or not is_query_string_correct(
"testharness.js", src):
"testharness.js", src):
errors.append(rules.TestharnessPath.error(path))

if not is_path_correct("testharnessreport.js",
src) or not is_query_string_correct(
"testharnessreport.js", src):
"testharnessreport.js", src):
errors.append(rules.TestharnessReportPath.error(path))

if not is_path_correct("testdriver.js", src):
Expand All @@ -584,7 +584,7 @@ def is_query_string_correct(script: Text, src: Text,

if not is_path_correct("testdriver-vendor.js",
src) or not is_query_string_correct(
"testdriver-vendor.js", src):
"testdriver-vendor.js", src):
errors.append(rules.TestdriverVendorPath.error(path))

script_path = None
Expand Down
7 changes: 3 additions & 4 deletions tools/manifest/sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,8 +728,7 @@ def testdriver_nodes(self) -> List[ElementTree.Element]:
return [node for node in
self.root.findall(".//{http://www.w3.org/1999/xhtml}script")
if node.attrib.get('src',
"") == '/resources/testdriver.js'
or
"") == '/resources/testdriver.js' or
node.attrib.get('src', "").startswith(
'/resources/testdriver.js?')]

Expand All @@ -741,7 +740,7 @@ def has_testdriver(self) -> Optional[bool]:
return None
return bool(self.testdriver_nodes)

def ___get_testdriver_include_path(self):
def ___get_testdriver_include_path(self) -> str | None:
if self.script_metadata:
for (meta, content) in self.script_metadata:
if meta.strip() == 'script' and content.startswith(
Expand All @@ -758,7 +757,7 @@ def ___get_testdriver_include_path(self):
return None

@cached_property
def testdriver_features(self) -> Optional[Text]:
def testdriver_features(self) -> Optional[List[Text]]:
"""
List of requested testdriver features.
"""
Expand Down
14 changes: 7 additions & 7 deletions tools/manifest/tests/test_sourcefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ def test_hash():
@pytest.mark.parametrize("file_name",
["html/test.worker.js", "html/test.window.js"])
def test_script_testdriver_missing_features(file_name):
contents = f"""// META: title=TEST_TITLE
contents = """// META: title=TEST_TITLE
// META: script=/resources/testdriver.js
test()""".encode("utf-8")

Expand All @@ -981,7 +981,7 @@ def test_script_testdriver_missing_features(file_name):
["html/test.worker.js", "html/test.window.js"])
def test_script_testdriver_features(file_name, features):
contents = f"""// META: title=TEST_TITLE
// META: script=/resources/testdriver.js?{"&".join('feature=' + f for f in features)}
// META: script=/resources/testdriver.js?{"&".join('feature=' + f for f in features)}
test()""".encode("utf-8")

s = create(file_name, contents=contents)
Expand All @@ -992,14 +992,14 @@ def test_script_testdriver_features(file_name, features):


def test_html_testdriver_missing_features():
contents = f"""
contents = """
<!--Required to make test type `testharness` -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharness.js"></script>
<script src="/resources/testdriver.js?feature=bidi"></script>
""".encode("utf-8")

s = create("html/test.html", contents=contents)
s.testdriver_features == None
assert s.testdriver_features is None


@pytest.mark.parametrize("features",
Expand All @@ -1008,8 +1008,8 @@ def test_html_testdriver_features(features):
contents = f"""
<script src="/resources/testdriver.js?{"&".join('feature=' + f for f in features)}"></script>
<!--Required to make test type `testharness` -->
<script src="/resources/testharness.js?feature=bidi"></script>
<script src="/resources/testharness.js?feature=bidi"></script>
""".encode("utf-8")

s = create("html/test.html", contents=contents)
s.testdriver_features == ['bidi']
assert s.testdriver_features == ['bidi']
2 changes: 1 addition & 1 deletion tools/wptrunner/wptrunner/browsers/chrome.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def __init__(self,
super().__init__(logger, **kwargs)
self._leak_check = leak_check
self._actual_port = None
self._require_webdriver_bidi = None
self._require_webdriver_bidi: Optional[bool] = None

def restart_on_test_type_change(self, new_test_type: str, old_test_type: str) -> bool:
# Restart the test runner when switch from/to wdspec tests. Wdspec test
Expand Down

0 comments on commit 225ded7

Please sign in to comment.