commit 198af3f380d8c51dddc00e7b23fce1c70da9243f Author: Neel Chauhan neel@neelc.org Date: Thu Oct 27 09:49:48 2016 -0400
Finish modifying tests to reference pycodestyle as well as pep8 --- run_tests.py | 20 ++++++++++---------- test/util.py | 27 +++++++++++++++++++++------ 2 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/run_tests.py b/run_tests.py index 2fb93bf..0f98db7 100755 --- a/run_tests.py +++ b/run_tests.py @@ -80,7 +80,7 @@ PYFLAKES_TASK = Task( )
PEP8_TASK = Task( - 'running pep8', + 'running pycodestyle', stem.util.test_tools.stylistic_issues, args = (SRC_PATHS, True, True, True), is_required = False, @@ -140,14 +140,14 @@ def main():
sys.exit(1)
- pyflakes_task, pep8_task = None, None + pyflakes_task, pycodestyle_task = None, None
if not args.specific_test: if stem.util.test_tools.is_pyflakes_available(): pyflakes_task = PYFLAKES_TASK
- if stem.util.test_tools.is_pep8_available(): - pep8_task = PEP8_TASK + if stem.util.test_tools.is_pycodestyle_available(): + pycodestyle_task = PEP8_TASK
test.util.run_tasks( 'INITIALISING', @@ -156,11 +156,11 @@ def main(): Task('checking pycrypto version', test.util.check_pycrypto_version), Task('checking mock version', test.util.check_mock_version), Task('checking pyflakes version', test.util.check_pyflakes_version), - Task('checking pep8 version', test.util.check_pep8_version), + Task('checking pycodestyle version', test.util.check_pycodestyle_version), Task('checking for orphaned .pyc files', test.util.clean_orphaned_pyc, (SRC_PATHS,)), Task('checking for unused tests', test.util.check_for_unused_tests, ((os.path.join(STEM_BASE, 'test'),),)), pyflakes_task, - pep8_task, + pycodestyle_task, )
# buffer that we log messages into so they can be printed after a test has finished @@ -277,12 +277,12 @@ def main(): elif not stem.util.test_tools.is_pyflakes_available(): println('Static error checking requires pyflakes version 0.7.3 or later. Please install it from ...\n http://pypi.python.org/pypi/pyflakes%5Cn', ERROR)
- if pep8_task and pep8_task.is_successful: - for path, issues in pep8_task.result.items(): + if pycodestyle_task and pycodestyle_task.is_successful: + for path, issues in pycodestyle_task.result.items(): for issue in issues: static_check_issues.setdefault(path, []).append(issue) - elif not stem.util.test_tools.is_pep8_available(): - println('Style checks require pep8 version 1.4.2 or later. Please install it from...\n http://pypi.python.org/pypi/pep8%5Cn', ERROR) + elif not stem.util.test_tools.is_pycodestyle_available(): + println('Style checks require pycodestyle version 1.4.2 or later. Please install it from...\n http://pypi.python.org/pypi/pycodestyle%5Cn', ERROR)
_print_static_issues(static_check_issues)
diff --git a/test/util.py b/test/util.py index ef0e377..6812898 100644 --- a/test/util.py +++ b/test/util.py @@ -23,7 +23,7 @@ Tasks are... |- check_python_version - checks our version of python |- check_pycrypto_version - checks our version of pycrypto |- check_pyflakes_version - checks our version of pyflakes - |- check_pep8_version - checks our version of pep8 + |- check_pycodestyle_version - checks our version of pep8 |- clean_orphaned_pyc - removes any *.pyc without a corresponding *.py +- check_for_unused_tests - checks to see if any tests are missing from our settings """ @@ -84,6 +84,18 @@ STEM_BASE = os.path.sep.join(__file__.split(os.path.sep)[:-2])
NEW_CAPABILITIES = []
+def module_exists(module_name): + """ + Checks if a module exists + + :returns: **True** if module exists and **False** otherwise + """ + try: + mod = __import__(module_name) + except ImportError: + return False + else: + return True
def get_unit_tests(module_prefix = None): """ @@ -226,13 +238,16 @@ def check_pyflakes_version(): return 'missing'
-def check_pep8_version(): - try: - import pep8 - return pep8.__version__ - except ImportError: +def check_pycodestyle_version(): + if module_exists('pycodestyle'): + import pycodestyle + elif module_exists('pep8'): + import pep8 as pycodestyle + else: return 'missing'
+ return pycodestyle.__version__ +
def clean_orphaned_pyc(paths): """