-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Now with proper test suite :-) (both Tox and Travis CI)
- Loading branch information
Showing
9 changed files
with
143 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |