From 2dccc95d195d4637322e55795f3ad1cd2c21ca01 Mon Sep 17 00:00:00 2001 From: Carson Gee Date: Wed, 5 Aug 2015 16:03:34 -0400 Subject: [PATCH] Switched from pyflakes to pylint Added tox support Resolved minor pylint issues Closes #36 Closes #35 --- .travis.yml | 5 ++-- docs/conf.py | 20 ++++++++++++++++ orcoursetrion/tests/base.py | 2 +- orcoursetrion/tests/test_action.py | 8 +++---- orcoursetrion/tests/test_github.py | 15 ++++++++---- pylintrc | 8 +++++++ pytest.ini | 5 ++++ setup.py | 37 ++++++++++++------------------ test_requirements.txt | 15 ++++++++---- tox.ini | 17 ++++++++++++++ 10 files changed, 93 insertions(+), 39 deletions(-) create mode 100644 pylintrc create mode 100644 pytest.ini create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index d7abb71..426df9c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,10 +2,9 @@ language: python python: - 2.7 install: - - pip install -e . + - pip install tox - pip install coveralls script: - - python setup.py test --coverage --pep8 --flakes - - coverage run --source=orcoursetrion setup.py test + - tox after_success: coveralls diff --git a/docs/conf.py b/docs/conf.py index 22f0f3f..ba18f0a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,6 +11,7 @@ # # All configuration values have a default; values that are commented out # serve to show the default. +# pylint: skip-file from orcoursetrion import VERSION import sphinx_bootstrap_theme @@ -127,3 +128,22 @@ epub_exclude_files = ['search.html'] autoclass_content = 'both' + +# -- Monkey-patch to hide 'non-local image warnings' ------------------- +# The following explanation is taken from the source... +# +# ...I found this necessary because I want the sphinx-build -W to emit +# "warnings as errors" as part of my test & build infrastructure, to ensure +# that there are no mistakes in the documentation -- I know very well that +# I'm using nonlocal image URI's and I'm OK with that, but I don't want to +# ignore the other warnings. +# +# source: http://stackoverflow.com/a/28778969/875546 +import sphinx.environment +from docutils.utils import get_source_line + +def _warn_node(self, msg, node): + if not msg.startswith('nonlocal image URI found:'): + self._warnfunc(msg, '%s:%s' % get_source_line(node)) + +sphinx.environment.BuildEnvironment.warn_node = _warn_node diff --git a/orcoursetrion/tests/base.py b/orcoursetrion/tests/base.py index eab5b09..6443f91 100644 --- a/orcoursetrion/tests/base.py +++ b/orcoursetrion/tests/base.py @@ -148,7 +148,7 @@ def callback_team_create( @staticmethod def callback_team_membership( - request, uri, headers, success=True, action_list=None + request, uri, headers, success=True, action_list=None ): """Manage both add and delete of team membership. diff --git a/orcoursetrion/tests/test_action.py b/orcoursetrion/tests/test_action.py index ebaec1d..e2ed046 100644 --- a/orcoursetrion/tests/test_action.py +++ b/orcoursetrion/tests/test_action.py @@ -55,7 +55,7 @@ def test_create_export_repo_success(self, config): # Mocking out add_repo_file due to it needing the repo to exist # but other items in this test need it to not exist with mock.patch( - 'orcoursetrion.actions.github.GitHub.add_repo_file' + 'orcoursetrion.actions.github.GitHub.add_repo_file' ) as mock_add_file: create_export_repo( self.TEST_COURSE, @@ -98,9 +98,9 @@ def test_rerun_studio_success(self, config): self.register_hook_delete() # Mocking out add_repo_file due to it needing the repo to exist - # but other items in this test need it to not exist + # but other items in this test need it to not exist. with mock.patch( - 'orcoursetrion.actions.github.GitHub.add_repo_file' + 'orcoursetrion.actions.github.GitHub.add_repo_file' ) as mock_add_file: rerun_studio( @@ -286,7 +286,7 @@ def test_rerun_xml_success(self, config): @mock.patch('orcoursetrion.actions.github.config') @httpretty.activate - def test_release_XML_success(self, config): + def test_release_xml_success(self, config): """Test the API call comes through as expected. """ config.ORC_GH_OAUTH2_TOKEN = self.OAUTH2_TOKEN diff --git a/orcoursetrion/tests/test_github.py b/orcoursetrion/tests/test_github.py index 947bbbd..67a81d1 100644 --- a/orcoursetrion/tests/test_github.py +++ b/orcoursetrion/tests/test_github.py @@ -27,7 +27,9 @@ class TestGithub(TestGithubBase): """Test Github actions and backing library.""" - + # All these fit under this test class, so the number of methods seems + # valid for now. + # pylint: disable=too-many-public-methods @httpretty.activate def test_create_repo_success(self): """Test the API call comes through as expected. @@ -338,10 +340,13 @@ def test_put_team_membership_fail(self): git_hub.put_team(self.ORG, self.TEST_TEAM, True, []) def test_copy_repo(self): - """Verify that we can do a single commit, single branch copy of a - repo.""" - # Even pylint thinks this test is too long, but it is needed - # pylint: disable=too-many-locals + """ + Verify that we can do a single commit, single branch copy of a + repo. + """ + # Even pylint thinks this test is too long, but it can't be + # easily broken up + # pylint: disable=too-many-locals,too-many-statements from orcoursetrion import config diff --git a/pylintrc b/pylintrc new file mode 100644 index 0000000..b6328f6 --- /dev/null +++ b/pylintrc @@ -0,0 +1,8 @@ +[BASIC] + +# Regular expression matching correct method names +method-rgx=[a-z_][a-z0-9_]{2,40}$ + +[DESIGN] + +max-args = 7 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..8835eb5 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,5 @@ +[pytest] +addopts = --cov orcoursetrion --cov-config .coveragerc --pep8 --pylint --cov-report term --cov-report html +pep8ignore = + docs/conf.py ALL +norecursedirs = .git .tox .* CVS _darcs {arch} *.egg diff --git a/setup.py b/setup.py index 0ada3d0..a12e62c 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ import sys from setuptools import setup, find_packages -from setuptools.command.test import test +from setuptools.command.test import test as testcommand VERSION = __import__('orcoursetrion').VERSION @@ -15,40 +15,35 @@ README = readme.read() with open('test_requirements.txt') as test_reqs: - tests_require = test_reqs.readlines(), + TESTS_REQUIRE = test_reqs.readlines(), -class PyTest(test): - """ - Test runner for package. - """ - user_options = test.user_options[:] +class PyTest(testcommand): + """PyTest class to enable running `python setup.py test`.""" + user_options = testcommand.user_options[:] user_options += [ ('coverage', 'C', 'Produce a coverage report for orcoursetrion'), ('pep8', 'P', 'Produce a pep8 report for orcoursetrion'), - ('flakes', 'F', 'Produce a flakes report for orcoursetrion'), - + ('pylint', 'l', 'Produce a pylint report for orcoursetrion'), ] coverage = None pep8 = None - flakes = None + lint = None test_suite = False test_args = [] def initialize_options(self): - test.initialize_options(self) + pass def finalize_options(self): - test.finalize_options(self) self.test_suite = True self.test_args = [] if self.coverage: - self.test_args.append('--cov') - self.test_args.append('orcoursetrion') + self.test_args.extend(['--cov', 'orcoursetrion']) if self.pep8: self.test_args.append('--pep8') - if self.flakes: - self.test_args.append('--flakes') + if self.lint: + self.test_args.append('--lint') def run_tests(self): # import here, cause outside the eggs aren't loaded @@ -57,11 +52,9 @@ def run_tests(self): # Alternate fix: import pytest_cache and pass to pytest.main import _pytest.config - pm = _pytest.config.get_plugin_manager() - pm.consider_setuptools_entrypoints() - pm.config.option.color = True - errno = pytest.main(self.test_args) - sys.exit(errno) + plugin_manager = _pytest.config.get_plugin_manager() + plugin_manager.consider_setuptools_entrypoints() + sys.exit(pytest.main(self.test_args)) setup( @@ -91,6 +84,6 @@ def run_tests(self): ]}, zip_safe=True, test_suite="orcoursetrion.tests", - tests_require=tests_require, + tests_require=TESTS_REQUIRE, cmdclass={"test": PyTest}, ) diff --git a/test_requirements.txt b/test_requirements.txt index 85dbc8e..927274b 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,7 +1,14 @@ -pytest-cov>=1.8.1 -pytest-pep8>=1.0.6 -pytest-flakes>=0.2 -pytest>=2.6.3 +# Test running requirements +pytest-cov +pytest-pep8 +pytest-pylint +pytest-watch +pytest-xdist +pytest +ipdb +ipython + +# Internal test requirements httpretty>=0.8.4 semantic_version>=2.3.1 mock>=1.0.1 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..2302500 --- /dev/null +++ b/tox.ini @@ -0,0 +1,17 @@ +[tox] +envlist = py27,docs + +[testenv] +deps = + -r{toxinidir}/requirements.txt + -r{toxinidir}/test_requirements.txt +commands = py.test {posargs} + +[testenv:docs] +basepython = python2.7 +changedir = docs + +deps= + -r{toxinidir}/doc_requirements.txt +commands= + sphinx-build -W -b html -d {envtmpdir}/doctrees . {toxinidir}/docs/_build