Browse Source

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
changes/52/337952/10
Eric Brown 6 years ago
parent
commit
05b5dfe144
  1. 13
      keystone/tests/unit/ksfixtures/hacking.py
  2. 2
      keystone/tests/unit/test_hacking_checks.py

13
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

2
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):

Loading…
Cancel
Save