diff --git a/.gitignore b/.gitignore index 1046518b7..d987f272c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.egg-info *.pyc +.tox /build /dist /docs/_site diff --git a/fig/cli/main.py b/fig/cli/main.py index b815f9087..3459e211f 100644 --- a/fig/cli/main.py +++ b/fig/cli/main.py @@ -24,16 +24,7 @@ log = logging.getLogger(__name__) def main(): - console_handler = logging.StreamHandler(stream=sys.stderr) - console_handler.setFormatter(logging.Formatter()) - console_handler.setLevel(logging.INFO) - root_logger = logging.getLogger() - root_logger.addHandler(console_handler) - root_logger.setLevel(logging.DEBUG) - - # Disable requests logging - logging.getLogger("requests").propagate = False - + setup_logging() try: command = TopLevelCommand() command.sys_dispatch() @@ -56,6 +47,18 @@ def main(): sys.exit(1) +def setup_logging(): + console_handler = logging.StreamHandler(sys.stderr) + console_handler.setFormatter(logging.Formatter()) + console_handler.setLevel(logging.INFO) + root_logger = logging.getLogger() + root_logger.addHandler(console_handler) + root_logger.setLevel(logging.DEBUG) + + # Disable requests logging + logging.getLogger("requests").propagate = False + + # stolen from docopt master def parse_doc_section(name, source): pattern = re.compile('^([^\n]*' + name + '[^\n]*\n?(?:[ \t].*?(?:\n|$))*)', diff --git a/tests/unit/cli_test.py b/tests/unit/cli_test.py index 911b14ad8..c69235793 100644 --- a/tests/unit/cli_test.py +++ b/tests/unit/cli_test.py @@ -1,9 +1,13 @@ from __future__ import unicode_literals from __future__ import absolute_import +import logging +import os from .. import unittest + +from fig.cli import main from fig.cli.main import TopLevelCommand from fig.packages.six import StringIO -import os + class CLITestCase(unittest.TestCase): def test_default_project_name(self): @@ -35,3 +39,8 @@ class CLITestCase(unittest.TestCase): command = TopLevelCommand() with self.assertRaises(SystemExit): command.dispatch(['-h'], None) + + def test_setup_logging(self): + main.setup_logging() + self.assertEqual(logging.getLogger().level, logging.DEBUG) + self.assertEqual(logging.getLogger('requests').propagate, False) diff --git a/tox.ini b/tox.ini index a4a195d66..a99ce210f 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,8 @@ envlist = py26,py27,py32,py33,pypy [testenv] +deps = + -rrequirements.txt + -rrequirements-dev.txt commands = - pip install -e {toxinidir} - pip install -e {toxinidir}[test] - python setup.py test + nosetests {posargs}