Skip to content

Commit

Permalink
Now with proper test suite :-) (both Tox and Travis CI)
Browse files Browse the repository at this point in the history
  • Loading branch information
xolox committed Jun 22, 2016
1 parent 374028f commit 02cc91a
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# .coveragerc: Configuration file for coverage.py.
# http://nedbatchelder.com/code/coverage/

[run]
source = verboselogs
omit = verboselogs/tests.py

# vim: ft=dosini
21 changes: 21 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
language: python
python:
- "2.6"
- "2.7"
- "3.4"
- "3.5"
- "pypy"
install:
- pip install pip-accel
- pip-accel install coveralls
- pip-accel install --requirement=requirements-checks.txt
- pip-accel install --requirement=requirements-tests.txt
- LC_ALL=C pip-accel install .
script:
- make check
- py.test --cov --cov-fail-under=90 --verbose
after_success:
- coveralls
branches:
except:
- /^[0-9]/
18 changes: 13 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ install:
@test -d "$(VIRTUAL_ENV)" || mkdir -p "$(VIRTUAL_ENV)"
@test -x "$(VIRTUAL_ENV)/bin/python" || virtualenv --quiet "$(VIRTUAL_ENV)"
@test -x "$(VIRTUAL_ENV)/bin/pip" || easy_install pip
@test -x "$(VIRTUAL_ENV)/bin/pip-accel" || pip install --quiet pip-accel
@test -x "$(VIRTUAL_ENV)/bin/pip-accel" || (pip install --quiet pip-accel && pip-accel install --quiet 'urllib3[secure]')
@echo "Updating installation of verboselogs .." >&2
@pip uninstall --yes verboselogs &>/dev/null || true
@pip install --quiet --editable .

Expand All @@ -38,12 +39,19 @@ reset:
$(MAKE) install

check: install
pip-accel install --upgrade --quiet flake8 flake8-docstrings
flake8
@echo "Updating installation of flake8 .." >&2
@pip-accel install --upgrade --quiet --requirement=requirements-checks.txt
@flake8

test: install
@pip-accel install --quiet detox pytest pytest-cov
@py.test --cov
@coverage html
@detox

docs: install
pip-accel install --quiet sphinx
cd docs && sphinx-build -nb html -d build/doctrees . build/html
@pip-accel install --quiet sphinx
@cd docs && sphinx-build -nb html -d build/doctrees . build/html

publish: install
git push origin && git push --tags origin
Expand Down
12 changes: 7 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ verboselogs: Verbose logging level for Python's logging module
The ``verboselogs.VerboseLogger`` class extends `logging.Logger`_ to add the
log levels ``VERBOSE`` and ``SPAM``. The ``VERBOSE`` level sits between the
predefined ``INFO`` and ``DEBUG`` levels and ``SPAM`` sits between ``DEBUG``
and ``NOTSET``. The code to do this is simple and short, but I still don't want
to copy/paste it to every project I'm working on, hence this package. The table
below shows the names, `numeric values`_ and descriptions_ of the predefined
log levels and the ``VERBOSE`` and ``SPAM`` levels defined by this module.
I've added some notes to the other levels, these are marked in bold:
and ``NOTSET``. The code to do this is simple and short, but I still don't
want to copy/paste it to every project I'm working on, hence this package. It's
currently tested on Python 2.6, 2.7, 3.4, 3.5 and PyPy.

The table below shows the names, `numeric values`_ and descriptions_ of the
predefined log levels and the ``VERBOSE`` and ``SPAM`` levels defined by this
module. I've added some notes to the other levels, these are marked in bold:

======== ============= =====================================================
Level Numeric value Description
Expand Down
4 changes: 4 additions & 0 deletions requirements-checks.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Python packages required to run `make check'.
flake8 >= 2.6.0
flake8-docstrings >= 0.2.8
pyflakes >= 1.2.3
11 changes: 11 additions & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
coloredlogs >= 5.0
mock >= 1.0.1
pytest >= 2.6.1
pytest-cov >= 2.2.1

# The following entries provide a pylint installation that's compatible with
# Python 2.6. The version pinning here was based on the following resources:
# - https://github.com/certbot/certbot/issues/97#issuecomment-65632583
# - https://bitbucket.org/logilab/pylint/commits/066bfa24a14f59288379638e1d64a9aa856769fd
pylint < 1.4
astroid <= 1.3.2
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ def get_absolute_path(*args):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[tox]
envlist = py26, py27, py34, py35, pypy

[testenv]
deps = -rrequirements-tests.txt
commands = py.test {posargs}

[pytest]
addopts = --verbose
python_files = verboselogs/tests.py

[flake8]
exclude = .tox
ignore = D211
Expand Down
65 changes: 65 additions & 0 deletions verboselogs/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Verbose and spam log levels for Python's logging module.
#
# Author: Peter Odding <peter@peterodding.com>
# Last Change: June 23, 2016
# URL: https://verboselogs.readthedocs.io

"""Test suite for the `verboselogs` package."""

# Standard library modules.
import logging
import random
import string
import sys
import unittest

# Modules included in our package.
import verboselogs

# Test dependencies.
import coloredlogs
import mock


class VerboseLogsTestCase(unittest.TestCase):

"""Container for the `verboselogs` tests."""

def setUp(self):
"""Enable logging to the terminal."""
coloredlogs.install(level='DEBUG')

def test_install(self):
"""Test the :func:`verboselogs.install()` function."""
default_logger = logging.getLogger(random_string())
assert isinstance(default_logger, logging.Logger)
verboselogs.install()
custom_logger = logging.getLogger(random_string())
assert isinstance(custom_logger, verboselogs.VerboseLogger)

def test_custom_methods(self):
"""Test :func:`~verboselogs.VerboseLogger.verbose()` and :func:`~verboselogs.VerboseLogger.spam()`."""
for name in 'verbose', 'spam':
logger = verboselogs.VerboseLogger(random_string())
logger.log = mock.MagicMock()
level = getattr(verboselogs, name.upper())
method = getattr(logger, name.lower())
message = "Any random message"
method(message)
logger.log.assert_called_with(level, message)

def test_pylint_plugin(self):
"""Test the :mod:`verboselogs.pylint` module."""
saved_args = sys.argv
try:
sys.argv = ['pylint', '--load-plugins', 'verboselogs.pylint', '--errors-only', 'verboselogs']
__import__('pylint').run_pylint()
except SystemExit:
pass
finally:
sys.argv = saved_args


def random_string(length=25):
"""Generate a random string."""
return ''.join(random.choice(string.ascii_letters) for i in range(length))

0 comments on commit 02cc91a

Please sign in to comment.