Skip to content

Commit

Permalink
Merge 2dccc95 into 3ab516b
Browse files Browse the repository at this point in the history
  • Loading branch information
carsongee committed Aug 10, 2015
2 parents 3ab516b + 2dccc95 commit 4ea5400
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 39 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Expand Up @@ -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
20 changes: 20 additions & 0 deletions docs/conf.py
Expand Up @@ -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

Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion orcoursetrion/tests/base.py
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions orcoursetrion/tests/test_action.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions orcoursetrion/tests/test_github.py
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions 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
5 changes: 5 additions & 0 deletions 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
37 changes: 15 additions & 22 deletions setup.py
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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},
)
15 changes: 11 additions & 4 deletions 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
17 changes: 17 additions & 0 deletions 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

0 comments on commit 4ea5400

Please sign in to comment.