Skip to content

Commit

Permalink
Remove use of six.ensure_str/ensure_text in wptrunner
Browse files Browse the repository at this point in the history
ConditionalValue.set_value was by all appearances unused, with no other
matches for "set_value" in the code base.

Part of #28776.
  • Loading branch information
foolip committed Mar 31, 2022
1 parent 8678fd4 commit 90af724
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
29 changes: 13 additions & 16 deletions tools/wptrunner/wptrunner/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from typing import Dict, List, Tuple

from mozlog import structuredlog
from six import ensure_str, ensure_text
from sys import intern

from . import manifestupdate
Expand Down Expand Up @@ -438,7 +437,7 @@ def suite_start(self, data):
self.run_info = run_info_intern.store(RunInfo(data["run_info"]))

def test_start(self, data):
test_id = intern(ensure_str(data["test"]))
test_id = intern(data["test"])
try:
self.id_test_map[test_id]
except KeyError:
Expand All @@ -448,8 +447,8 @@ def test_start(self, data):
self.tests_visited[test_id] = set()

def test_status(self, data):
test_id = intern(ensure_str(data["test"]))
subtest = intern(ensure_str(data["subtest"]))
test_id = intern(data["test"])
subtest = intern(data["subtest"])
test_data = self.id_test_map.get(test_id)
if test_data is None:
return
Expand All @@ -466,7 +465,7 @@ def test_end(self, data):
if data["status"] == "SKIP":
return

test_id = intern(ensure_str(data["test"]))
test_id = intern(data["test"])
test_data = self.id_test_map.get(test_id)
if test_data is None:
return
Expand All @@ -479,7 +478,7 @@ def test_end(self, data):
del self.tests_visited[test_id]

def assertion_count(self, data):
test_id = intern(ensure_str(data["test"]))
test_id = intern(data["test"])
test_data = self.id_test_map.get(test_id)
if test_data is None:
return
Expand All @@ -490,7 +489,7 @@ def assertion_count(self, data):

def test_for_scope(self, data):
dir_path = data.get("scope", "/")
dir_id = intern(ensure_str(os.path.join(dir_path, "__dir__").replace(os.path.sep, "/")))
dir_id = intern(os.path.join(dir_path, "__dir__").replace(os.path.sep, "/"))
if dir_id.startswith("/"):
dir_id = dir_id[1:]
return dir_id, self.id_test_map[dir_id]
Expand Down Expand Up @@ -538,13 +537,13 @@ def create_test_tree(metadata_path, test_manifest):
assert all_types > exclude_types
include_types = all_types - exclude_types
for item_type, test_path, tests in test_manifest.itertypes(*include_types):
test_file_data = TestFileData(intern(ensure_str(test_manifest.url_base)),
intern(ensure_str(item_type)),
test_file_data = TestFileData(intern(test_manifest.url_base),
intern(item_type),
metadata_path,
test_path,
tests)
for test in tests:
id_test_map[intern(ensure_str(test.id))] = test_file_data
id_test_map[intern(test.id)] = test_file_data

dir_path = os.path.dirname(test_path)
while True:
Expand All @@ -553,7 +552,7 @@ def create_test_tree(metadata_path, test_manifest):
if dir_id in id_test_map:
break

test_file_data = TestFileData(intern(ensure_str(test_manifest.url_base)),
test_file_data = TestFileData(intern(test_manifest.url_base),
None,
metadata_path,
dir_meta_path,
Expand Down Expand Up @@ -622,7 +621,7 @@ def __init__(self, url_base, item_type, metadata_path, test_path, tests):
self.item_type = item_type
self.test_path = test_path
self.metadata_path = metadata_path
self.tests = {intern(ensure_str(item.id)) for item in tests}
self.tests = {intern(item.id) for item in tests}
self._requires_update = False
self.data = defaultdict(lambda: defaultdict(PackedResultList))

Expand Down Expand Up @@ -664,10 +663,10 @@ def orphan_subtests(self, expected):
rv = []

for test_id, subtests in self.data.items():
test = expected.get_test(ensure_text(test_id))
test = expected.get_test(test_id)
if not test:
continue
seen_subtests = {ensure_text(item) for item in subtests.keys() if item is not None}
seen_subtests = {item for item in subtests.keys() if item is not None}
missing_subtests = set(test.subtests.keys()) - seen_subtests
for item in missing_subtests:
expected_subtest = test.get_subtest(item)
Expand Down Expand Up @@ -737,7 +736,6 @@ def update(self, default_expected_by_type, update_properties,
expected_by_test[test_id] = test_expected

for test_id, test_data in self.data.items():
test_id = ensure_str(test_id)
for subtest_id, results_list in test_data.items():
for prop, run_info, value in results_list:
# Special case directory metadata
Expand All @@ -754,7 +752,6 @@ def update(self, default_expected_by_type, update_properties,
if subtest_id is None:
item_expected = test_expected
else:
subtest_id = ensure_text(subtest_id)
item_expected = test_expected.get_subtest(subtest_id)

if prop == "status":
Expand Down
25 changes: 12 additions & 13 deletions tools/wptrunner/wptrunner/wptmanifest/serializer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from six import ensure_text
from typing import List

from .node import NodeVisitor, ValueNode, ListNode, BinaryExpressionNode
from .node import NodeVisitor, BinaryExpressionNode, BinaryOperatorNode, ListNode, NumberNode, UnaryOperatorNode, ValueNode
from .parser import atoms, precedence

atom_names = {v: "@%s" % k for (k,v) in atoms.items()}

named_escapes = {"\a", "\b", "\f", "\n", "\r", "\t", "\v"}

def escape(string, extras=""):
# Assumes input bytes are either UTF8 bytes or unicode.
def escape(string: str, extras: str = "") -> str:
rv = ""
for c in string:
if c in named_escapes:
Expand All @@ -21,7 +20,7 @@ def escape(string, extras=""):
rv += "\\" + c
else:
rv += c
return ensure_text(rv)
return rv


class ManifestSerializer(NodeVisitor):
Expand Down Expand Up @@ -73,8 +72,8 @@ def visit_ListNode(self, node):
rv.append("]")
return ["".join(rv)]

def visit_ValueNode(self, node):
data = ensure_text(node.data)
def visit_ValueNode(self, node: ValueNode) -> List[str]:
data = node.data
if ("#" in data or
data.startswith("if ") or
(isinstance(node.parent, ListNode) and
Expand All @@ -99,8 +98,8 @@ def visit_StringNode(self, node):
rv[0] += self.visit(child)[0]
return rv

def visit_NumberNode(self, node):
return [ensure_text(node.data)]
def visit_NumberNode(self, node: NumberNode) -> List[str]:
return [str(node.data)]

def visit_VariableNode(self, node):
rv = escape(node.data)
Expand Down Expand Up @@ -133,11 +132,11 @@ def visit_BinaryExpressionNode(self, node):
children.append(child_str)
return [" ".join(children)]

def visit_UnaryOperatorNode(self, node):
return [ensure_text(node.data)]
def visit_UnaryOperatorNode(self, node: UnaryOperatorNode) -> List[str]:
return [str(node.data)]

def visit_BinaryOperatorNode(self, node):
return [ensure_text(node.data)]
def visit_BinaryOperatorNode(self, node: BinaryOperatorNode) -> List[str]:
return [str(node.data)]


def serialize(tree, *args, **kwargs):
Expand Down

0 comments on commit 90af724

Please sign in to comment.