From a93397c5395e0a340dce44e613d4a1db535183c7 Mon Sep 17 00:00:00 2001 From: Gregory Armer Date: Mon, 13 Jul 2015 10:56:16 -0400 Subject: [PATCH 1/4] Get coveralls.io hooked up, and switch to py.test --- .coveralls.yml | 0 .travis.yml | 6 +++++- flake8diff/test_main.py | 10 ++++++++++ flake8diff/test_utils.py | 17 +++++++++++++++++ requirements.txt | 3 +++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .coveralls.yml create mode 100644 flake8diff/test_main.py create mode 100644 flake8diff/test_utils.py diff --git a/.coveralls.yml b/.coveralls.yml new file mode 100644 index 0000000..e69de29 diff --git a/.travis.yml b/.travis.yml index 2e9c3fe..a7dc5d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,9 @@ python: - "3.3" - "3.4" - "pypy" +sudo: false install: pip install -r requirements.txt -script: nosetests +script: + - py.test -v --cov flake8diff --cov-report term-missing +after_success: + - coveralls diff --git a/flake8diff/test_main.py b/flake8diff/test_main.py new file mode 100644 index 0000000..d859804 --- /dev/null +++ b/flake8diff/test_main.py @@ -0,0 +1,10 @@ +"""This test is primarily to trigger the argparse code in main.py +""" +from unittest import TestCase + +from flake8diff import main # noqa + + +class MainTestCase(TestCase): + def test_main(self): + self.assertIsNotNone(main.LOGGING_FORMAT) diff --git a/flake8diff/test_utils.py b/flake8diff/test_utils.py new file mode 100644 index 0000000..6078714 --- /dev/null +++ b/flake8diff/test_utils.py @@ -0,0 +1,17 @@ +from unittest import TestCase +import six + +from flake8diff import utils +from subprocess import CalledProcessError + + +class UtilsTestCase(TestCase): + def test_execute_success(self): + pwd = utils._execute("pwd", strict=True) + self.assertIsNotNone(pwd) + self.assertIsInstance(pwd, six.text_type) + + def test_execute_failure(self): + with self.assertRaises(CalledProcessError): + error = utils._execute("doesnotexist", strict=True) + self.assertEquals(error, "") diff --git a/requirements.txt b/requirements.txt index 8e43d4b..557b283 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,9 @@ Jinja2==2.7.1 MarkupSafe==0.18 Pygments==1.6 Sphinx==1.2.2 +coveralls==0.5 docutils==0.11 six==1.9.0 sphinx-rtd-theme==0.1.6 +pytest==2.7.2 +pytest-cov==1.8.1 From e7a51900c7247fcbd1df1155e34ccbf1290bf463 Mon Sep 17 00:00:00 2001 From: Gregory Armer Date: Mon, 13 Jul 2015 12:08:00 -0400 Subject: [PATCH 2/4] Drop Python 2.6.x for now --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a7dc5d2..1318515 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.6" - "2.7" - "3.2" - "3.3" From 93f5d3e49db13c1edca17492d1df57081309ca9a Mon Sep 17 00:00:00 2001 From: Gregory Armer Date: Mon, 13 Jul 2015 12:08:22 -0400 Subject: [PATCH 3/4] Flesh out a few more tests --- flake8diff/exceptions.py | 2 +- flake8diff/flake8.py | 4 +-- flake8diff/test_exceptions.py | 53 +++++++++++++++++++++++++++++++++++ flake8diff/test_flake8.py | 8 ++++++ flake8diff/test_utils.py | 3 +- requirements.txt | 2 ++ 6 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 flake8diff/test_exceptions.py create mode 100644 flake8diff/test_flake8.py diff --git a/flake8diff/exceptions.py b/flake8diff/exceptions.py index 743f1b7..d98ad36 100644 --- a/flake8diff/exceptions.py +++ b/flake8diff/exceptions.py @@ -30,7 +30,7 @@ class UnsupportedVCSError(BaseError): """ def __init__(self, vcs=None): - msg = '{0} VCS is not unsupported' + msg = '{0} VCS is not supported' self.message = msg.format(vcs) super(UnsupportedVCSError, self).__init__() diff --git a/flake8diff/flake8.py b/flake8diff/flake8.py index a80451e..c24c777 100644 --- a/flake8diff/flake8.py +++ b/flake8diff/flake8.py @@ -232,8 +232,6 @@ def process(self): )) for line in violations: - print(SIMPLE_OUTPUT.format( - **self.get_color_kwargs(line) - )) + print(SIMPLE_OUTPUT.format(**self.get_color_kwargs(line))) return overall_violations == 0 diff --git a/flake8diff/test_exceptions.py b/flake8diff/test_exceptions.py new file mode 100644 index 0000000..0a4c23b --- /dev/null +++ b/flake8diff/test_exceptions.py @@ -0,0 +1,53 @@ +from __future__ import unicode_literals + +from unittest import TestCase + +from flake8diff.exceptions import ( + Flake8NotInstalledError, + NotLocatableVCSError, + UnsupportedVCSError, + VCSNotInstalledError, + WrongVCSSpecified +) + + +class ExceptionsTestCase(TestCase): + def test_flake8_not_installed(self): + expected = "flake8 installation could not be found. Is it on $PATH?" + + try: + raise Flake8NotInstalledError + except Flake8NotInstalledError as e: + self.assertEquals(str(e), expected) + + def test_not_locatable_vcs(self): + expected = "VCS could not be determined automatically" + + try: + raise NotLocatableVCSError + except NotLocatableVCSError as e: + self.assertEquals(str(e), expected) + + def test_unsupported_vcs(self): + expected = "foo VCS is not supported" + + try: + raise UnsupportedVCSError(vcs="foo") + except UnsupportedVCSError as e: + self.assertEquals(str(e), expected) + + def test_vcs_not_installed(self): + expected = 'VCS "bar" installation could not be found. Is it on $PATH?' + + try: + raise VCSNotInstalledError(vcs="bar") + except VCSNotInstalledError as e: + self.assertEquals(str(e), expected) + + def test_wrong_vcs_specified(self): + expected = 'This is not a "baz" repository' + + try: + raise WrongVCSSpecified(vcs="baz") + except WrongVCSSpecified as e: + self.assertEquals(str(e), expected) diff --git a/flake8diff/test_flake8.py b/flake8diff/test_flake8.py new file mode 100644 index 0000000..f7f2bf3 --- /dev/null +++ b/flake8diff/test_flake8.py @@ -0,0 +1,8 @@ +from unittest import TestCase + +from flake8diff import flake8 + + +class Flake8DiffTestCase(TestCase): + def test_flake8diff(self): + f8d = flake8.Flake8Diff("", {}) diff --git a/flake8diff/test_utils.py b/flake8diff/test_utils.py index 6078714..af1010c 100644 --- a/flake8diff/test_utils.py +++ b/flake8diff/test_utils.py @@ -13,5 +13,4 @@ def test_execute_success(self): def test_execute_failure(self): with self.assertRaises(CalledProcessError): - error = utils._execute("doesnotexist", strict=True) - self.assertEquals(error, "") + utils._execute("doesnotexist", strict=True) diff --git a/requirements.txt b/requirements.txt index 557b283..59f96d6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,8 +2,10 @@ Jinja2==2.7.1 MarkupSafe==0.18 Pygments==1.6 Sphinx==1.2.2 +blessings==1.6 coveralls==0.5 docutils==0.11 +flake8==2.4.1 six==1.9.0 sphinx-rtd-theme==0.1.6 pytest==2.7.2 From ef552005fd33f04063e78a2e238682682576e814 Mon Sep 17 00:00:00 2001 From: Gregory Armer Date: Mon, 13 Jul 2015 15:20:52 -0400 Subject: [PATCH 4/4] Bring back Python 2.6 support --- .travis.yml | 1 + flake8diff/flake8.py | 4 ++-- flake8diff/main.py | 4 ++-- flake8diff/test_main.py | 3 ++- flake8diff/test_utils.py | 15 +++++++++------ tox.ini | 5 +++++ 6 files changed, 21 insertions(+), 11 deletions(-) create mode 100644 tox.ini diff --git a/.travis.yml b/.travis.yml index 1318515..a7dc5d2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,6 @@ language: python python: + - "2.6" - "2.7" - "3.2" - "3.3" diff --git a/flake8diff/flake8.py b/flake8diff/flake8.py index c24c777..be436b2 100644 --- a/flake8diff/flake8.py +++ b/flake8diff/flake8.py @@ -104,7 +104,7 @@ def __init__(self, commits, options=None): self._should_include_violation = getattr( self, - '_should_include_violation_{}' + '_should_include_violation_{0}' ''.format(self.options.get('strict_mode', 'only_lines')) ) @@ -129,7 +129,7 @@ def get_vcs(self): try: vcs = vcs(self.commits, self.options) except VCSNotInstalledError: - logger.error('Seems like {} is not installed'.format(vcs.name)) + logger.error('Seems like {0} is not installed'.format(vcs.name)) else: if vcs.is_used() and vcs.check(): return vcs diff --git a/flake8diff/main.py b/flake8diff/main.py index 8ecf300..e6e37c8 100644 --- a/flake8diff/main.py +++ b/flake8diff/main.py @@ -13,7 +13,8 @@ $ flake8-diff """ -from __future__ import unicode_literals, print_function +from __future__ import print_function, unicode_literals + import argparse import logging import operator @@ -24,7 +25,6 @@ from .flake8 import COLORS, STRICT_MODES, Flake8Diff from .vcs import SUPPORTED_VCS - LOGGING_FORMAT = '%(asctime)-15s %(name)s %(levelname)s %(message)s' ENVIRON_PREFIX = 'FLAKE8DIFF_{0}' VERBOSITY_MAPPING = { diff --git a/flake8diff/test_main.py b/flake8diff/test_main.py index d859804..1d5341b 100644 --- a/flake8diff/test_main.py +++ b/flake8diff/test_main.py @@ -7,4 +7,5 @@ class MainTestCase(TestCase): def test_main(self): - self.assertIsNotNone(main.LOGGING_FORMAT) + # using assertTrue() instead of assertIsNotNone() for py2.6 compat + self.assertTrue(main.LOGGING_FORMAT is not None) diff --git a/flake8diff/test_utils.py b/flake8diff/test_utils.py index af1010c..17e27d0 100644 --- a/flake8diff/test_utils.py +++ b/flake8diff/test_utils.py @@ -1,16 +1,19 @@ -from unittest import TestCase -import six +import sys +import unittest +from subprocess import CalledProcessError +import pytest +import six from flake8diff import utils -from subprocess import CalledProcessError -class UtilsTestCase(TestCase): +class UtilsTestCase(unittest.TestCase): def test_execute_success(self): pwd = utils._execute("pwd", strict=True) - self.assertIsNotNone(pwd) - self.assertIsInstance(pwd, six.text_type) + self.assertTrue(pwd is not "") + self.assertTrue(isinstance(pwd, six.string_types)) + @pytest.mark.skipif(sys.version_info < (2, 7), reason="Python >=2.7 needed") def test_execute_failure(self): with self.assertRaises(CalledProcessError): utils._execute("doesnotexist", strict=True) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..2214b0a --- /dev/null +++ b/tox.ini @@ -0,0 +1,5 @@ +[tox] +envlist = py26,py27,py34 +[testenv] +deps = -rrequirements.txt +commands = py.test -v