File: test_static.py

package info (click to toggle)
click 0.5.2-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,372 kB
  • sloc: python: 7,135; ansic: 857; makefile: 441; sh: 236; perl: 26; xml: 11
file content (80 lines) | stat: -rw-r--r-- 2,722 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# Copyright (C) 2013 Canonical Ltd.
# Author: Colin Watson <cjwatson@ubuntu.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Test compliance with various static analysis tools."""

from __future__ import print_function

__metaclass__ = type
__all__ = [
    'TestStatic',
    ]


import os
import sys
from unittest import skipIf

from pkg_resources import resource_filename

try:
    import pep8
except ImportError:
    pep8 = None
try:
    import pyflakes
    import pyflakes.api
    import pyflakes.reporter
except ImportError:
    pyflakes = None


from click_package.tests.helpers import TestCase


class TestStatic(TestCase):
    def all_paths(self):
        paths = []
        start_dir = os.path.dirname(resource_filename('click_package', '__init__.py'))
        for dirpath, dirnames, filenames in os.walk(start_dir):
            for ignore in ('doc', ".git", "__pycache__"):
                if ignore in dirnames:
                    dirnames.remove(ignore)
            filenames = [
                n for n in filenames
                if not n.startswith(".") and not n.endswith("~")]
            if dirpath.split(os.sep)[-1] == "bin":
                for filename in filenames:
                    paths.append(os.path.join(dirpath, filename))
            else:
                for filename in filenames:
                    if filename.endswith(".py"):
                        paths.append(os.path.join(dirpath, filename))
        return paths

    @skipIf('SKIP_SLOW_TESTS' in os.environ, 'Skipping slow tests')
    @skipIf(pep8 is None, 'No pep8 package available')
    def test_pep8_clean(self):
        # https://github.com/jcrocholl/pep8/issues/103
        pep8_style = pep8.StyleGuide(ignore='E123')
        result = pep8_style.check_files(self.all_paths())
        self.assertEqual(result.total_errors, 0)

    @skipIf('SKIP_SLOW_TESTS' in os.environ, 'Skipping slow tests')
    @skipIf(pyflakes is None, 'No pyflakes package available')
    def test_pyflakes_clean(self):
        reporter = pyflakes.reporter.Reporter(sys.stdout, sys.stderr)
        warnings = pyflakes.api.checkRecursive(self.all_paths(), reporter)
        self.assertEqual(0, warnings)