From 05b5dfe144958b70331a84118440d6bb0e2863e2 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Tue, 5 Jul 2016 18:53:52 -0700 Subject: [PATCH] Handle Py35 fix of ast.node.col_offset bug In 3.5, the ast module returns the correct value for the col_offset of a function definition whereas earlier versions did not. The value is off by one column. Closes-Bug: #1603236 Change-Id: I7835d7ed8d652a6bd585e8e0372fab402424038d --- keystone/tests/unit/ksfixtures/hacking.py | 13 +++++++++++-- keystone/tests/unit/test_hacking_checks.py | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/keystone/tests/unit/ksfixtures/hacking.py b/keystone/tests/unit/ksfixtures/hacking.py index 5093a19a79..caf19ce718 100644 --- a/keystone/tests/unit/ksfixtures/hacking.py +++ b/keystone/tests/unit/ksfixtures/hacking.py @@ -16,6 +16,8 @@ # test_hacking_checks test cases. # flake8: noqa +import sys + import fixtures @@ -73,11 +75,18 @@ class HackingCode(fixtures.Fixture): (25, 14, 'K001'), (25, 36, 'K001'), (28, 10, 'K001'), - (28, 27, 'K001'), + (28, 26, 'K001'), (29, 21, 'K001'), - (32, 11, 'K001'), + (32, 10, 'K001'), ]} + # NOTE(browne): This is gross, but in Python 3.4 and earlier, the ast + # module returns the incorrect col_offset for two of the defined functions + # in the code sample above. + if sys.version_info < (3, 5): + mutable_default_args['expected_errors'][12] = (28, 27, 'K001') + mutable_default_args['expected_errors'][14] = (32, 11, 'K001') + comments_begin_with_space = { 'code': """ # This is a good comment diff --git a/keystone/tests/unit/test_hacking_checks.py b/keystone/tests/unit/test_hacking_checks.py index 5c95d416a5..99592d08f0 100644 --- a/keystone/tests/unit/test_hacking_checks.py +++ b/keystone/tests/unit/test_hacking_checks.py @@ -50,7 +50,7 @@ class BaseStyleCheck(unit.BaseTestCase): def assert_has_errors(self, code, expected_errors=None): actual_errors = [e[:3] for e in self.run_check(code)] - self.assertEqual(expected_errors or [], actual_errors) + self.assertItemsEqual(expected_errors or [], actual_errors) class TestCheckForMutableDefaultArgs(BaseStyleCheck):