summaryrefslogtreecommitdiff
path: root/tests/test_mypy.py
blob: b13cdcc2a2e0efca8c315d6624485ccde0be53b4 (plain)
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
import pathlib
import sys
import unittest

import mypy.api

test_modules = ['rsa', 'tests']


class MypyRunnerTest(unittest.TestCase):
    def test_run_mypy(self):
        proj_root = pathlib.Path(__file__).parent.parent
        args = [
            '--incremental',
            '--ignore-missing-imports',
            f'--python-version={sys.version_info.major}.{sys.version_info.minor}'
        ] + [str(proj_root / dirname) for dirname in test_modules]

        result = mypy.api.run(args)

        stdout, stderr, status = result

        messages = []
        if stderr:
            messages.append(stderr)
        if stdout:
            messages.append(stdout)
        if status:
            messages.append('Mypy failed with status %d' % status)
        if messages and not all('Success' in message for message in messages):
            self.fail('\n'.join(['Mypy errors:'] + messages))