Blob Blame History Raw
From b4a5456b126f2c5bc548e77b421ecaf34ec2ec4e Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Sat, 24 Dec 2016 10:20:37 -0800
Subject: [PATCH] Work with pep8 and pycodestyle, don't use pep8 internals

pep8 was renamed pycodestyle; this test should work fine with
either, so just use whichever we find. Also, it's really not
necessary to fiddle with the library's internals using mock,
you can use the public API properly to select the check you
want to run, like this.

Signed-off-by: Adam Williamson <awilliam@redhat.com>
---
 keystoneclient/tests/unit/test_hacking_checks.py | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/keystoneclient/tests/unit/test_hacking_checks.py b/keystoneclient/tests/unit/test_hacking_checks.py
index f1e81c9..3ab8983 100644
--- a/keystoneclient/tests/unit/test_hacking_checks.py
+++ b/keystoneclient/tests/unit/test_hacking_checks.py
@@ -12,8 +12,11 @@
 
 import textwrap
 
-import mock
-import pep8
+# work with both pep8 and pycodestyle
+try:
+    import pycodestyle
+except ImportError:
+    import pep8 as pycodestyle
 import testtools
 
 from keystoneclient.tests.hacking import checks
@@ -25,16 +28,13 @@ class TestCheckOsloNamespaceImports(testtools.TestCase):
         super(TestCheckOsloNamespaceImports, self).setUp()
         self.useFixture(client_fixtures.Deprecations())
 
-    # We are patching pep8 so that only the check under test is actually
-    # installed.
-    @mock.patch('pep8._checks',
-                {'physical_line': {}, 'logical_line': {}, 'tree': {}})
     def run_check(self, code):
-        pep8.register_check(checks.check_oslo_namespace_imports)
+        pycodestyle.register_check(checks.check_oslo_namespace_imports, ['K333'])
 
         lines = textwrap.dedent(code).strip().splitlines(True)
 
-        checker = pep8.Checker(lines=lines)
+        guide = pycodestyle.StyleGuide(select=['K333'])
+        checker = pycodestyle.Checker(lines=lines, options=guide.options)
         checker.check_all()
         checker.report._deferred_print.sort()
         return checker.report._deferred_print
-- 
2.11.0