File: test_codestyle.py

package info (click to toggle)
python-transitions 0.9.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,728 kB
  • sloc: python: 8,765; makefile: 10; sh: 7
file content (42 lines) | stat: -rw-r--r-- 1,666 bytes parent folder | download
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
import unittest
import subprocess
from os.path import exists

import pycodestyle

try:
    import mypy
except ImportError:
    mypy = None  # type: ignore


class TestCodeFormat(unittest.TestCase):
    def test_conformance(self):
        """Test that we conform to PEP-8."""
        style = pycodestyle.StyleGuide(quiet=False, ignore=['E501', 'W605', 'W503'])
        if exists('transitions'):  # when run from root directory (e.g. tox)
            style.input_dir('transitions')
            style.input_dir('tests')
        else:  # when run from test directory (e.g. pycharm)
            style.input_dir('../transitions')
            style.input_dir('.')
        result = style.check_files()
        self.assertEqual(result.total_errors, 0,
                         "Found code style errors (and warnings).")

    @unittest.skipIf(mypy is None, "mypy not found")
    def test_mypy_package(self):
        call = ['mypy', '--config-file', 'mypy.ini', '--strict', 'transitions', 'tests/test_imports.py']

        # when run from root directory (e.g. tox) else when run from test directory (e.g. pycharm)
        project_root = '.' if exists('transitions') else '..'
        subprocess.check_call(call, cwd=project_root)

    @unittest.skipIf(mypy is None, "mypy not found")
    def test_mypy_tests(self):
        call = ['mypy', 'tests',
                '--disable-error-code', 'attr-defined',
                '--disable-error-code', 'no-untyped-def']
        # when run from root directory (e.g. tox) else when run from test directory (e.g. pycharm)
        project_root = '.' if exists('transitions') else '..'
        subprocess.check_call(call, cwd=project_root)