Bug 1638990: [taskgraph] Make test_util_parameterization.py pass on python 3; r=ahal
authorTom Prince <mozilla@hocat.ca>
Mon, 20 Jul 2020 19:27:07 +0000
changeset 541326 0d981c7058f6d728344fa498a2358c97749b11ca
parent 541325 2f5586dcfdf8bce1119fd3ef20d00414bcdc21f1
child 541327 8d0f64bb22386c3db76418ec38a00159a4e7dcdd
push id122172
push usermozilla@hocat.ca
push dateMon, 20 Jul 2020 20:16:13 +0000
treeherderautoland@7b1128e12c72 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersahal
bugs1638990
milestone80.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1638990: [taskgraph] Make test_util_parameterization.py pass on python 3; r=ahal Differential Revision: https://phabricator.services.mozilla.com/D84076
taskcluster/taskgraph/test/test_util_parameterization.py
taskcluster/taskgraph/util/parameterization.py
--- a/taskcluster/taskgraph/test/test_util_parameterization.py
+++ b/taskcluster/taskgraph/test/test_util_parameterization.py
@@ -1,21 +1,19 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import, print_function, unicode_literals
 
-import sys
 import unittest
 import datetime
 import mock
 import os
 
-import pytest
 from mozunit import main
 from taskgraph.util.parameterization import (
     resolve_timestamps,
     resolve_task_references,
 )
 
 
 class TestTimestamps(unittest.TestCase):
@@ -24,19 +22,16 @@ class TestTimestamps(unittest.TestCase):
         now = datetime.datetime(2018, 1, 1)
         input = {
             "key": "value",
             "numeric": 10,
             "list": ["a", True, False, None],
         }
         self.assertEqual(resolve_timestamps(now, input), input)
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_buried_replacement(self):
         now = datetime.datetime(2018, 1, 1)
         input = {"key": [{"key2": [{'relative-datestamp': '1 day'}]}]}
         self.assertEqual(resolve_timestamps(now, input),
                          {"key": [{"key2": ['2018-01-02T00:00:00Z']}]})
 
     def test_appears_with_other_keys(self):
         now = datetime.datetime(2018, 1, 1)
@@ -56,94 +51,67 @@ class TestTaskRefs(unittest.TestCase):
             output,
         )
 
     def test_no_change(self):
         "resolve_task_references does nothing when there are no task references"
         self.do({'in-a-list': ['stuff', {'property': '<edge1>'}]},
                 {'in-a-list': ['stuff', {'property': '<edge1>'}]})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_in_list(self):
         "resolve_task_references resolves task references in a list"
         self.do({'in-a-list': ['stuff', {'task-reference': '<edge1>'}]},
                 {'in-a-list': ['stuff', 'tid1']})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_in_dict(self):
         "resolve_task_references resolves task references in a dict"
         self.do({'in-a-dict': {'stuff': {'task-reference': '<edge2>'}}},
                 {'in-a-dict': {'stuff': 'tid2'}})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_multiple(self):
         "resolve_task_references resolves multiple references in the same string"
         self.do({'multiple': {'task-reference': 'stuff <edge1> stuff <edge2> after'}},
                 {'multiple': 'stuff tid1 stuff tid2 after'})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_embedded(self):
         "resolve_task_references resolves ebmedded references"
         self.do({'embedded': {'task-reference': 'stuff before <edge3> stuff after'}},
                 {'embedded': 'stuff before tid3 stuff after'})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_escaping(self):
         "resolve_task_references resolves escapes in task references"
         self.do({'escape': {'task-reference': '<<><edge3>>'}},
                 {'escape': '<tid3>'})
 
     def test_multikey(self):
         "resolve_task_references is ignored when there is another key in the dict"
         self.do({'escape': {'task-reference': '<edge3>', 'another-key': True}},
                 {'escape': {'task-reference': '<edge3>', 'another-key': True}})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_self(self):
         "resolve_task_references resolves `self` to the provided task id"
         self.do({'escape': {'task-reference': '<self>'}},
                 {'escape': 'tid-self'})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_decision(self):
         "resolve_task_references resolves `decision` to the provided decision task id"
         self.do({'escape': {'task-reference': '<decision>'}},
                 {'escape': 'tid-decision'})
 
-    @pytest.mark.xfail(
-        sys.version_info >= (3, 0), reason="python3 migration is not complete"
-    )
     def test_invalid(self):
         "resolve_task_references raises a KeyError on reference to an invalid task"
         self.assertRaisesRegexp(
             KeyError,
             "task 'subject' has no dependency named 'no-such'",
             lambda: resolve_task_references(
                 "subject", {"task-reference": "<no-such>"}, "tid-self", "tid-decision", {}
             ),
         )
 
 
-@pytest.mark.xfail(
-    sys.version_info >= (3, 0), reason="python3 migration is not complete"
-)
 class TestArtifactRefs(unittest.TestCase):
 
     def do(self, input, output):
         taskid_for_edge_name = {'edge%d' % n: 'tid%d' % n for n in range(1, 4)}
         with mock.patch.dict(os.environ, {'TASKCLUSTER_ROOT_URL': 'https://tc-tests.localhost'}):
             self.assertEqual(
                 resolve_task_references(
                     "subject", input, "tid-self", "tid-decision", taskid_for_edge_name
--- a/taskcluster/taskgraph/util/parameterization.py
+++ b/taskcluster/taskgraph/util/parameterization.py
@@ -17,17 +17,17 @@ ARTIFACT_REFERENCE_PATTERN = re.compile(
 
 def _recurse(val, param_fns):
     def recurse(val):
         if isinstance(val, list):
             return [recurse(v) for v in val]
         elif isinstance(val, dict):
             if len(val) == 1:
                 for param_key, param_fn in param_fns.items():
-                    if val.keys() == [param_key]:
+                    if set(six.iterkeys(val)) == {param_key}:
                         return param_fn(val[param_key])
             return {k: recurse(v) for k, v in six.iteritems(val)}
         else:
             return val
     return recurse(val)
 
 
 def resolve_timestamps(now, task_def):