File: source_check.py

package info (click to toggle)
dh-cmake 0.6.3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 396 kB
  • sloc: python: 2,255; perl: 26; makefile: 6; ansic: 6; sh: 2
file content (30 lines) | stat: -rw-r--r-- 1,264 bytes parent folder | download | duplicates (3)
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
# This file is part of dh-cmake, and is distributed under the OSI-approved
# BSD 3-Clause license. See top-level LICENSE file or
# https://gitlab.kitware.com/debian/dh-cmake/blob/master/LICENSE for details.

import autopep8
import pyflakes.api
import os.path
from unittest import TestCase


class SourceCheckTestCase(TestCase):
    def foreach_py(self, func):
        test_dir = os.path.dirname(__file__)
        root_dir = os.path.dirname(os.path.dirname(test_dir))

        for dirpath, _, filenames in os.walk(root_dir):
            for filename in filter(lambda f: f.endswith(".py"), filenames):
                filename_abs = os.path.join(dirpath, filename)
                filename_rel = os.path.relpath(filename_abs, root_dir)
                with open(filename_abs) as f:
                    contents = f.read()
                func(filename_abs, filename_rel, contents)

    def test_autopep8(self):
        self.foreach_py(lambda a, r, c: self.assertEqual(autopep8.fix_code(c), c,
                                                         msg="File %s is incorrectly formatted" % r))

    def test_pyflakes(self):
        self.foreach_py(lambda a, r, c: self.assertEqual(
            0, pyflakes.api.check(c, r), msg="File %s failed pyflakes check" % r))