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 76 77
|
#!/usr/bin/env python
#
# Copyright (c), 2018-2020, SISSA (International School for Advanced Studies).
# All rights reserved.
# This file is distributed under the terms of the MIT License.
# See the file 'LICENSE' in the root directory of the present
# distribution, or http://opensource.org/licenses/MIT.
#
# @author Davide Brunato <brunato@sissa.it>
#
"""Tests about static typing of xmlschema objects."""
import unittest
import importlib
from pathlib import Path
try:
from mypy import api as mypy_api
except ImportError:
mypy_api = None
try:
lxml_stubs_module = importlib.import_module('lxml-stubs')
except ImportError:
lxml_stubs_module = None
import elementpath
@unittest.skipIf(mypy_api is None, "mypy is not installed")
@unittest.skipIf(lxml_stubs_module is None, "lxml-stubs is not installed")
class TestTyping(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.cases_dir = Path(__file__).parent.joinpath('test_cases/mypy')
cls.config_file = Path(__file__).parent.parent.joinpath('pyproject.toml')
def test_schema_source(self):
result = mypy_api.run([
'--strict',
'--no-warn-unused-ignores',
'--config-file', str(self.config_file),
str(self.cases_dir.joinpath('schema_source.py'))
])
self.assertEqual(result[2], 0, msg=result[1] or result[0])
def test_simple_types(self):
result = mypy_api.run([
'--strict',
'--no-warn-unused-ignores',
'--config-file', str(self.config_file),
str(self.cases_dir.joinpath('simple_types.py'))
])
self.assertEqual(result[2], 0, msg=result[1] or result[0])
@unittest.skipIf(elementpath.__version__ == '4.5.0', "ep450 needs a patch for protocols")
def test_protocols(self):
result = mypy_api.run([
'--strict',
'--no-warn-unused-ignores',
'--config-file', str(self.config_file),
str(self.cases_dir.joinpath('protocols.py'))
])
self.assertEqual(result[2], 0, msg=result[1] or result[0])
def test_extra_validator__issue_291(self):
result = mypy_api.run([
'--strict',
'--config-file', str(self.config_file),
str(self.cases_dir.joinpath('extra_validator.py'))
])
self.assertEqual(result[2], 0, msg=result[1] or result[0])
if __name__ == '__main__':
unittest.main()
|