File: test_pyflakes.py

package info (click to toggle)
python-apt 1.4.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,980 kB
  • sloc: cpp: 10,003; python: 7,108; makefile: 107; sh: 27
file content (43 lines) | stat: -rw-r--r-- 1,243 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
#!/usr/bin/python3
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-

import os
import subprocess
import unittest

import testcommon


class TestPyflakesClean(testcommon.TestCase):

    EXCLUDES = ["build", "tests/old"]
    TOPLEVEL = os.path.normpath(
        os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))

    def is_excluded_path(self, path):
        for exclude in self.EXCLUDES:
            if path.startswith(os.path.join(self.TOPLEVEL, exclude)):
                return True
        return False

    def get_py_files(self, toplevel):
        files = []
        for path, dirnames, filenames in os.walk(self.TOPLEVEL):
            if self.is_excluded_path(path):
                continue
            for filename in filenames:
                if os.path.splitext(filename)[1] == ".py":
                    files.append(os.path.join(path, filename))
        return files

    def test_pyflakes_clean(self):
        cmd = ["pyflakes"] + self.get_py_files(self.TOPLEVEL)
        res = subprocess.call(cmd)
        if res != 0:
            self.fail("pyflakes failed with: %s" % res)


if __name__ == "__main__":
    import logging
    logging.basicConfig(level=logging.DEBUG)
    unittest.main()