[tor-commits] [stem/master] Suppress pyflakes issues by prefix or suffix

atagar at torproject.org atagar at torproject.org
Sun Nov 6 19:48:56 UTC 2016


commit 058fb76c9ba57676df3c209dfed6996ffb565257
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Nov 6 11:47:14 2016 -0800

    Suppress pyflakes issues by prefix or suffix
    
    On #17306 neel's test output has quite a few pyflakes issues I don't get...
    
      https://trac.torproject.org/projects/tor/attachment/ticket/17306/integ_test.txt
    
    These would be a hassle to suppress one by one so allowing our config to
    suppress by prefix or suffix.
---
 docs/change_log.rst     |  1 +
 run_tests.py            |  2 +-
 stem/util/test_tools.py | 21 ++++++++++++++++++---
 test/settings.cfg       |  5 +++++
 4 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/docs/change_log.rst b/docs/change_log.rst
index 0d8dcf2..ba496a7 100644
--- a/docs/change_log.rst
+++ b/docs/change_log.rst
@@ -91,6 +91,7 @@ The following are only available within Stem's `git repository
   * The 'ss' connection resolver didn't work on Gentoo (:trac:`18079`)
   * Recognize IPv4-mapped IPv6 addresses in our utils (:trac:`18079`)
   * Allow :func:`stem.util.conf.Config.set` to remove values when provided with a **None** value
+  * Support prefix and suffix issue strings in :func:`~stem.util.test_tools.pyflakes_issues`
   * Additional information when :func:`~stem.util.system.call` fails through a :class:`~stem.util.system.CallError`
   * Added **stem.util.system.SYSTEM_CALL_TIME** with the total time spent on system calls
   * Added an **is_ipv6** value to :class:`~stem.util.connection.Connection` instances
diff --git a/run_tests.py b/run_tests.py
index abe77e4..db34e5b 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -125,7 +125,7 @@ def main():
   if not stem.prereq.is_mock_available():
     try:
       try:
-        import unittest.mock
+        import unittest.mock as mock
       except ImportError:
         import mock
 
diff --git a/stem/util/test_tools.py b/stem/util/test_tools.py
index a09f735..406ebd7 100644
--- a/stem/util/test_tools.py
+++ b/stem/util/test_tools.py
@@ -273,7 +273,8 @@ def pyflakes_issues(paths):
     pyflakes.ignore stem/util/test_tools.py => 'pycodestyle' imported but unused
 
   If a 'exclude_paths' was set in our test config then we exclude any absolute
-  paths matching those regexes.
+  paths matching those regexes. Issue strings can start or end with an asterisk
+  to match just against the prefix or suffix.
 
   .. versionchanged:: 1.3.0
      Renamed from get_pyflakes_issues() to pyflakes_issues(). The old name
@@ -283,6 +284,9 @@ def pyflakes_issues(paths):
      Changing tuples in return value to be namedtuple instances, and adding the
      line that had the issue.
 
+  .. versionchanged:: 1.5.0
+     Support matching against prefix or suffix issue strings.
+
   :param list paths: paths to search for problems
 
   :returns: dict of paths list of :class:`stem.util.test_tools.Issue` instances
@@ -316,8 +320,19 @@ def pyflakes_issues(paths):
         # path ends with any of them.
 
         for ignored_path, ignored_issues in self._ignored_issues.items():
-          if path.endswith(ignored_path) and issue in ignored_issues:
-            return True
+          if path.endswith(ignored_path):
+            is_match = issue in ignored_issues
+
+            for prefix in [i[:1] for i in ignored_issues if i.endswith('*')]:
+              if issue.startswith(prefix):
+                is_match = True
+
+            for suffix in [i[1:] for i in ignored_issues if i.startswith('*')]:
+              if issue.endswith(suffix):
+                is_match = True
+
+            if is_match:
+              return True
 
         return False
 
diff --git a/test/settings.cfg b/test/settings.cfg
index 9504da3..4913202 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -144,9 +144,13 @@ pyflakes.ignore stem/__init__.py => undefined name 'long'
 pyflakes.ignore stem/__init__.py => undefined name 'unicode'
 pyflakes.ignore stem/control.py => undefined name 'controller'
 pyflakes.ignore stem/manual.py => undefined name 'unichr'
+pyflakes.ignore stem/prereq.py => 'Crypto.PublicKey.RSA' imported but unused
+pyflakes.ignore stem/prereq.py => 'Crypto.Util.asn1' imported but unused
+pyflakes.ignore stem/prereq.py => 'Crypto.Util.number.long_to_bytes' imported but unused
 pyflakes.ignore stem/prereq.py => 'RSA' imported but unused
 pyflakes.ignore stem/prereq.py => 'asn1' imported but unused
 pyflakes.ignore stem/prereq.py => 'unittest' imported but unused
+pyflakes.ignore stem/prereq.py => 'unittest.mock' imported but unused
 pyflakes.ignore stem/prereq.py => 'long_to_bytes' imported but unused
 pyflakes.ignore stem/interpreter/__init__.py => undefined name 'raw_input'
 pyflakes.ignore stem/util/conf.py => undefined name 'unicode'
@@ -154,6 +158,7 @@ pyflakes.ignore stem/util/test_tools.py => 'pyflakes' imported but unused
 pyflakes.ignore stem/util/test_tools.py => 'pycodestyle' imported but unused
 pyflakes.ignore test/mocking.py => undefined name 'test'
 pyflakes.ignore test/unit/response/events.py => 'from stem import *' used; unable to detect undefined names
+pyflakes.ignore test/unit/response/events.py => *may be undefined, or defined from star imports: stem
 
 # Test modules we want to run. Modules are roughly ordered by the dependencies
 # so the lowest level tests come first. This is because a problem in say,



More information about the tor-commits mailing list