Bug 1604356 [wpt PR 20801] - Improve compatibility of wptmanifest with Python3, a=testonly

Automatic update from web-platform-tests
Make conditional tests of wptrunner/wptmanifest compatible with Python3

--
Make serialiazer tests of wptrunner/wptmanifest compatible with Python3

--
Make static tests of wptrunner/wptmanifest compatible with Python3

--
Remove Python3 warning in parser tests of wptrunner/wptmanifest

--

wpt-commits: 2c1056bc94b7f2b420b8c586c0a601179bb1c1e9, 0aeb5c3a498847759234d4f0cee0684dca1bdfd3, 9c60cbbec1bb47083a06532fc0de28ae18c71edd, 08f3e37808d3b46e1697fe365c3fb3206cbf8320
wpt-pr: 20801
This commit is contained in:
marmeladema 2019-12-20 11:37:01 +00:00 коммит произвёл moz-wptsync-bot
Родитель 207cb86aee
Коммит 76317be0ad
8 изменённых файлов: 109 добавлений и 123 удалений

Просмотреть файл

@ -1,4 +1,5 @@
import abc
from six import iteritems, iterkeys, itervalues
from ..node import NodeVisitor
from ..parser import parse
@ -186,21 +187,21 @@ class ManifestItem(object):
def _flatten(self):
rv = {}
for node in [self, self.root]:
for name, value in node._data.iteritems():
for name, value in iteritems(node._data):
if name not in rv:
rv[name] = value
return rv
def iteritems(self):
for item in self._flatten().iteritems():
for item in iteritems(self._flatten()):
yield item
def iterkeys(self):
for item in self._flatten().iterkeys():
for item in iterkeys(self._flatten()):
yield item
def itervalues(self):
for item in self._flatten().itervalues():
for item in itervalues(self._flatten()):
yield item
def append(self, child):

Просмотреть файл

@ -1,4 +1,5 @@
import operator
from six import ensure_text, iteritems, iterkeys, text_type
from ..node import NodeVisitor, DataNode, ConditionalNode, KeyValueNode, ListNode, ValueNode, BinaryExpressionNode, VariableNode
from ..parser import parse
@ -42,9 +43,7 @@ class ConditionalValue(object):
return self.condition_func(run_info)
def set_value(self, value):
if type(value) not in (str, unicode):
value = unicode(value)
self.value = value
self.value = ensure_text(value)
def value_as(self, type_func):
"""Get value and convert to a given type.
@ -301,9 +300,9 @@ class ManifestItem(object):
if isinstance(value, list):
value_node = ListNode()
for item in value:
value_node.append(ValueNode(unicode(item)))
value_node.append(ValueNode(text_type(item)))
else:
value_node = ValueNode(unicode(value))
value_node = ValueNode(text_type(value))
if condition is not None:
if not isinstance(condition, ConditionalNode):
conditional_node = ConditionalNode()
@ -369,17 +368,17 @@ class ManifestItem(object):
def _flatten(self):
rv = {}
for node in [self, self.root]:
for name, value in node._data.iteritems():
for name, value in iteritems(node._data):
if name not in rv:
rv[name] = value
return rv
def iteritems(self):
for item in self._flatten().iteritems():
for item in iteritems(self._flatten()):
yield item
def iterkeys(self):
for item in self._flatten().iterkeys():
for item in iterkeys(self._flatten()):
yield item
def iter_properties(self):

Просмотреть файл

@ -14,7 +14,7 @@
from __future__ import unicode_literals
from six import binary_type, text_type, BytesIO
from six import binary_type, text_type, BytesIO, unichr
from six.moves import xrange
from .node import (Node, AtomNode, BinaryExpressionNode, BinaryOperatorNode,

Просмотреть файл

@ -1,3 +1,5 @@
from six import ensure_str, ensure_text
from .node import NodeVisitor, ValueNode, ListNode, BinaryExpressionNode
from .parser import atoms, precedence
@ -10,7 +12,7 @@ def escape(string, extras=""):
rv = ""
for c in string:
if c in named_escapes:
rv += c.encode("unicode_escape")
rv += c.encode("unicode_escape").decode()
elif c == "\\":
rv += "\\\\"
elif c < '\x20':
@ -19,10 +21,7 @@ def escape(string, extras=""):
rv += "\\" + c
else:
rv += c
if isinstance(rv, unicode):
return rv.encode("utf8")
else:
return rv
return ensure_str(rv)
class ManifestSerializer(NodeVisitor):
@ -74,10 +73,7 @@ class ManifestSerializer(NodeVisitor):
return ["".join(rv)]
def visit_ValueNode(self, node):
if not isinstance(node.data, (str, unicode)):
data = unicode(node.data)
else:
data = node.data
data = ensure_text(node.data)
if ("#" in data or
data.startswith("if ") or
(isinstance(node.parent, ListNode) and

Просмотреть файл

@ -1,19 +1,15 @@
import pytest
import sys
import unittest
from ..backends import conditional
from ..node import BinaryExpressionNode, BinaryOperatorNode, VariableNode, NumberNode
@pytest.mark.xfail(sys.version[0] == "3",
reason="wptmanifest.parser doesn't support py3")
class TestConditional(unittest.TestCase):
def compile(self, input_text):
return conditional.compile(input_text)
def test_get_0(self):
data = """
data = b"""
key: value
[Heading 1]
@ -25,19 +21,19 @@ key: value
manifest = self.compile(data)
self.assertEquals(manifest.get("key"), "value")
self.assertEqual(manifest.get("key"), "value")
children = list(item for item in manifest.iterchildren())
self.assertEquals(len(children), 1)
self.assertEqual(len(children), 1)
section = children[0]
self.assertEquals(section.name, "Heading 1")
self.assertEqual(section.name, "Heading 1")
self.assertEquals(section.get("other_key", {"a": 1}), "value_1")
self.assertEquals(section.get("other_key", {"a": 2}), "value_2")
self.assertEquals(section.get("other_key", {"a": 7}), "value_3")
self.assertEquals(section.get("key"), "value")
self.assertEqual(section.get("other_key", {"a": 1}), "value_1")
self.assertEqual(section.get("other_key", {"a": 2}), "value_2")
self.assertEqual(section.get("other_key", {"a": 7}), "value_3")
self.assertEqual(section.get("key"), "value")
def test_get_1(self):
data = """
data = b"""
key: value
[Heading 1]
@ -52,11 +48,11 @@ key: value
children = list(item for item in manifest.iterchildren())
section = children[0]
self.assertEquals(section.get("other_key", {"a": "1"}), "value_1")
self.assertEquals(section.get("other_key", {"a": 1}), "value_3")
self.assertEqual(section.get("other_key", {"a": "1"}), "value_1")
self.assertEqual(section.get("other_key", {"a": 1}), "value_3")
def test_get_2(self):
data = """
data = b"""
key:
if a[1] == "b": value_1
if a[1] == 2: value_2
@ -65,11 +61,11 @@ key:
manifest = self.compile(data)
self.assertEquals(manifest.get("key", {"a": "ab"}), "value_1")
self.assertEquals(manifest.get("key", {"a": [1, 2]}), "value_2")
self.assertEqual(manifest.get("key", {"a": "ab"}), "value_1")
self.assertEqual(manifest.get("key", {"a": [1, 2]}), "value_2")
def test_get_3(self):
data = """
data = b"""
key:
if a[1] == "ab"[1]: value_1
if a[1] == 2: value_2
@ -78,11 +74,11 @@ key:
manifest = self.compile(data)
self.assertEquals(manifest.get("key", {"a": "ab"}), "value_1")
self.assertEquals(manifest.get("key", {"a": [1, 2]}), "value_2")
self.assertEqual(manifest.get("key", {"a": "ab"}), "value_1")
self.assertEqual(manifest.get("key", {"a": [1, 2]}), "value_2")
def test_set_0(self):
data = """
data = b"""
key:
if a == "a": value_1
if a == "b": value_2
@ -92,10 +88,10 @@ key:
manifest.set("new_key", "value_new")
self.assertEquals(manifest.get("new_key"), "value_new")
self.assertEqual(manifest.get("new_key"), "value_new")
def test_set_1(self):
data = """
data = b"""
key:
if a == "a": value_1
if a == "b": value_2
@ -106,11 +102,11 @@ key:
manifest.set("key", "value_new")
self.assertEquals(manifest.get("key"), "value_new")
self.assertEquals(manifest.get("key", {"a": "a"}), "value_1")
self.assertEqual(manifest.get("key"), "value_new")
self.assertEqual(manifest.get("key", {"a": "a"}), "value_1")
def test_set_2(self):
data = """
data = b"""
key:
if a == "a": value_1
if a == "b": value_2
@ -125,11 +121,11 @@ key:
manifest.set("key", "value_new", expr)
self.assertEquals(manifest.get("key", {"a": 1}), "value_new")
self.assertEquals(manifest.get("key", {"a": "a"}), "value_1")
self.assertEqual(manifest.get("key", {"a": 1}), "value_new")
self.assertEqual(manifest.get("key", {"a": "a"}), "value_1")
def test_api_0(self):
data = """
data = b"""
key:
if a == 1.5: value_1
value_2
@ -138,8 +134,8 @@ key_1: other_value
manifest = self.compile(data)
self.assertFalse(manifest.is_empty)
self.assertEquals(manifest.root, manifest)
self.assertEqual(manifest.root, manifest)
self.assertTrue(manifest.has_key("key_1"))
self.assertFalse(manifest.has_key("key_2"))
self.assertEquals(set(manifest.iterkeys()), {"key", "key_1"})
self.assertEqual(set(manifest.iterkeys()), {"key", "key_1"})

Просмотреть файл

@ -18,9 +18,9 @@ class TestExpression(unittest.TestCase):
self.match(expected, actual)
def match(self, expected_node, actual_node):
self.assertEquals(expected_node[0], actual_node.__class__.__name__)
self.assertEquals(expected_node[1], actual_node.data)
self.assertEquals(len(expected_node[2]), len(actual_node.children))
self.assertEqual(expected_node[0], actual_node.__class__.__name__)
self.assertEqual(expected_node[1], actual_node.data)
self.assertEqual(len(expected_node[2]), len(actual_node.children))
for expected_child, actual_child in zip(expected_node[2], actual_node.children):
self.match(expected_child, actual_child)

Просмотреть файл

@ -1,3 +1,4 @@
import six
import sys
import unittest
@ -8,8 +9,6 @@ import pytest
from .. import parser, serializer
@pytest.mark.xfail(sys.version[0] == "3",
reason="wptmanifest.parser doesn't support py3")
class TokenizerTest(unittest.TestCase):
def setUp(self):
self.serializer = serializer.ManifestSerializer()
@ -20,26 +19,25 @@ class TokenizerTest(unittest.TestCase):
def compare(self, input_str, expected=None):
if expected is None:
expected = input_str
expected = expected.encode("utf8")
actual = self.serialize(input_str)
self.assertEquals(actual, expected)
expected = input_str.decode("utf-8")
actual = six.ensure_text(self.serialize(input_str))
self.assertEqual(actual, expected)
def test_0(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key: other_value
""")
def test_1(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a or b: other_value
""")
def test_2(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a or b: other_value
@ -47,7 +45,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_3(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a == 1: other_value
@ -55,7 +53,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_4(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a == "1": other_value
@ -63,7 +61,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_5(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a == "abc"[1]: other_value
@ -71,7 +69,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_6(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a == "abc"[c]: other_value
@ -79,7 +77,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_7(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if (a or b) and c: other_value
@ -93,7 +91,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_8(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if a or (b and c): other_value
@ -101,7 +99,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_9(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
other_key:
if not (a and b): other_value
@ -109,7 +107,7 @@ class TokenizerTest(unittest.TestCase):
""")
def test_10(self):
self.compare("""key: value
self.compare(b"""key: value
[Heading 1]
some_key: some_value
@ -118,121 +116,121 @@ class TokenizerTest(unittest.TestCase):
""")
def test_11(self):
self.compare("""key:
self.compare(b"""key:
if not a and b and c and d: true
""")
def test_12(self):
self.compare("""[Heading 1]
self.compare(b"""[Heading 1]
key: [a:1, b:2]
""")
def test_13(self):
self.compare("""key: [a:1, "b:#"]
self.compare(b"""key: [a:1, "b:#"]
""")
def test_14(self):
self.compare("""key: [","]
self.compare(b"""key: [","]
""")
def test_15(self):
self.compare("""key: ,
self.compare(b"""key: ,
""")
def test_16(self):
self.compare("""key: ["]", b]
self.compare(b"""key: ["]", b]
""")
def test_17(self):
self.compare("""key: ]
self.compare(b"""key: ]
""")
def test_18(self):
self.compare(r"""key: \]
self.compare(br"""key: \]
""", """key: ]
""")
def test_escape_0(self):
self.compare(r"""k\t\:y: \a\b\f\n\r\t\v""",
self.compare(br"""k\t\:y: \a\b\f\n\r\t\v""",
r"""k\t\:y: \x07\x08\x0c\n\r\t\x0b
""")
def test_escape_1(self):
self.compare(r"""k\x00: \x12A\x45""",
self.compare(br"""k\x00: \x12A\x45""",
r"""k\x00: \x12AE
""")
def test_escape_2(self):
self.compare(r"""k\u0045y: \u1234A\uABc6""",
self.compare(br"""k\u0045y: \u1234A\uABc6""",
u"""kEy: \u1234A\uabc6
""")
def test_escape_3(self):
self.compare(r"""k\u0045y: \u1234A\uABc6""",
self.compare(br"""k\u0045y: \u1234A\uABc6""",
u"""kEy: \u1234A\uabc6
""")
def test_escape_4(self):
self.compare(r"""key: '\u1234A\uABc6'""",
self.compare(br"""key: '\u1234A\uABc6'""",
u"""key: \u1234A\uabc6
""")
def test_escape_5(self):
self.compare(r"""key: [\u1234A\uABc6]""",
self.compare(br"""key: [\u1234A\uABc6]""",
u"""key: [\u1234A\uabc6]
""")
def test_escape_6(self):
self.compare(r"""key: [\u1234A\uABc6\,]""",
self.compare(br"""key: [\u1234A\uABc6\,]""",
u"""key: ["\u1234A\uabc6,"]
""")
def test_escape_7(self):
self.compare(r"""key: [\,\]\#]""",
self.compare(br"""key: [\,\]\#]""",
r"""key: [",]#"]
""")
def test_escape_8(self):
self.compare(r"""key: \#""",
self.compare(br"""key: \#""",
r"""key: "#"
""")
@pytest.mark.xfail(sys.maxunicode == 0xFFFF, reason="narrow unicode")
def test_escape_9(self):
self.compare(r"""key: \U10FFFFabc""",
self.compare(br"""key: \U10FFFFabc""",
u"""key: \U0010FFFFabc
""")
def test_escape_10(self):
self.compare(r"""key: \u10FFab""",
self.compare(br"""key: \u10FFab""",
u"""key: \u10FFab
""")
def test_escape_11(self):
self.compare(r"""key: \\ab
self.compare(br"""key: \\ab
""")
def test_atom_1(self):
self.compare(r"""key: @True
self.compare(br"""key: @True
""")
def test_atom_2(self):
self.compare(r"""key: @False
self.compare(br"""key: @False
""")
def test_atom_3(self):
self.compare(r"""key: @Reset
self.compare(br"""key: @Reset
""")
def test_atom_4(self):
self.compare(r"""key: [a, @Reset, b]
self.compare(br"""key: [a, @Reset, b]
""")
def test_conditional_1(self):
self.compare("""foo:
self.compare(b"""foo:
if a or b: [1, 2]
""")
def test_if_string_0(self):
self.compare("""foo: "if bar"
self.compare(b"""foo: "if bar"
""")

Просмотреть файл

@ -1,5 +1,3 @@
import pytest
import sys
import unittest
from ..backends import static
@ -8,14 +6,12 @@ from ..backends import static
# use test_serializer for the majority of cases
@pytest.mark.xfail(sys.version[0] == "3",
reason="wptmanifest.parser doesn't support py3")
class TestStatic(unittest.TestCase):
def compile(self, input_text, input_data):
return static.compile(input_text, input_data)
def test_get_0(self):
data = """
data = b"""
key: value
[Heading 1]
@ -27,17 +23,17 @@ key: value
manifest = self.compile(data, {"a": 2})
self.assertEquals(manifest.get("key"), "value")
self.assertEqual(manifest.get("key"), "value")
children = list(item for item in manifest.iterchildren())
self.assertEquals(len(children), 1)
self.assertEqual(len(children), 1)
section = children[0]
self.assertEquals(section.name, "Heading 1")
self.assertEqual(section.name, "Heading 1")
self.assertEquals(section.get("other_key"), "value_2")
self.assertEquals(section.get("key"), "value")
self.assertEqual(section.get("other_key"), "value_2")
self.assertEqual(section.get("key"), "value")
def test_get_1(self):
data = """
data = b"""
key: value
[Heading 1]
@ -50,32 +46,32 @@ key: value
children = list(item for item in manifest.iterchildren())
section = children[0]
self.assertEquals(section.get("other_key"), "value_3")
self.assertEqual(section.get("other_key"), "value_3")
def test_get_3(self):
data = """key:
data = b"""key:
if a == "1": value_1
if a[0] == "ab"[0]: value_2
"""
manifest = self.compile(data, {"a": "1"})
self.assertEquals(manifest.get("key"), "value_1")
self.assertEqual(manifest.get("key"), "value_1")
manifest = self.compile(data, {"a": "ac"})
self.assertEquals(manifest.get("key"), "value_2")
self.assertEqual(manifest.get("key"), "value_2")
def test_get_4(self):
data = """key:
data = b"""key:
if not a: value_1
value_2
"""
manifest = self.compile(data, {"a": True})
self.assertEquals(manifest.get("key"), "value_2")
self.assertEqual(manifest.get("key"), "value_2")
manifest = self.compile(data, {"a": False})
self.assertEquals(manifest.get("key"), "value_1")
self.assertEqual(manifest.get("key"), "value_1")
def test_api(self):
data = """key:
data = b"""key:
if a == 1.5: value_1
value_2
key_1: other_value
@ -83,15 +79,15 @@ key_1: other_value
manifest = self.compile(data, {"a": 1.5})
self.assertFalse(manifest.is_empty)
self.assertEquals(manifest.root, manifest)
self.assertEqual(manifest.root, manifest)
self.assertTrue(manifest.has_key("key_1"))
self.assertFalse(manifest.has_key("key_2"))
self.assertEquals(set(manifest.iterkeys()), {"key", "key_1"})
self.assertEquals(set(manifest.itervalues()), {"value_1", "other_value"})
self.assertEqual(set(manifest.iterkeys()), {"key", "key_1"})
self.assertEqual(set(manifest.itervalues()), {"value_1", "other_value"})
def test_is_empty_1(self):
data = """
data = b"""
[Section]
[Subsection]
"""