File: test_code.py

package info (click to toggle)
python-dbusmock 0.36.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 812 kB
  • sloc: python: 7,324; sh: 73; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 2,718 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
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation; either version 3 of the License, or (at your option) any
# later version.  See http://www.gnu.org/copyleft/lgpl.html for the full text
# of the license.

__author__ = "Martin Pitt"
__copyright__ = """
(c) 2012 Canonical Ltd.
(c) 2017 - 2022 Martin Pitt <martin@piware.de>
"""

import glob
import importlib.util
import os
import subprocess
import sys
import unittest


@unittest.skipIf(
    os.getenv("SKIP_STATIC_CHECKS", "0") == "1", "$SKIP_STATIC_CHECKS set, not running static code checks"
)
class StaticCodeTests(unittest.TestCase):
    @unittest.skipUnless(importlib.util.find_spec("pylint"), "pylint not available, skipping")
    def test_pylint(self):
        subprocess.check_call([sys.executable, "-m", "pylint", *glob.glob("dbusmock/*.py")])
        # signatures/arguments are not determined by us, docstrings are a bit pointless, and code repetition
        # is impractical to avoid (e.g. bluez4 and bluez5)
        subprocess.check_call(
            [
                sys.executable,
                "-m",
                "pylint",
                "--score=n",
                "--disable=missing-function-docstring,R0801",
                "--disable=too-many-arguments,too-many-instance-attributes",
                "--disable=too-few-public-methods",
                "dbusmock/templates/",
            ]
        )
        subprocess.check_call(
            [
                sys.executable,
                "-m",
                "pylint",
                "--score=n",
                "--disable=missing-module-docstring,missing-class-docstring",
                "--disable=missing-function-docstring",
                "--disable=too-many-public-methods,too-many-lines,too-many-statements,R0801",
                "--disable=fixme",
                "tests/",
            ]
        )

    @unittest.skipUnless(importlib.util.find_spec("mypy"), "mypy not available, skipping")
    def test_types(self):
        subprocess.check_call([sys.executable, "-m", "mypy", "dbusmock/", "tests/"])

    def test_ruff(self):
        try:
            subprocess.check_call(["ruff", "check", "--no-cache", "."])
        except FileNotFoundError:
            self.skipTest("ruff not available, skipping")

    def test_black(self):
        try:
            subprocess.check_call(["black", "--check", "--diff", "."])
        except FileNotFoundError:
            self.skipTest("black not available, skipping")


if __name__ == "__main__":
    # avoid writing to stderr
    unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout))