-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathtest_code_quality.py
62 lines (52 loc) · 2.04 KB
/
test_code_quality.py
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
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
import pathlib
import subprocess
import sys
import unittest
import re
import azure.functions as func
ROOT_PATH = pathlib.Path(__file__).parent.parent
class TestCodeQuality(unittest.TestCase):
def test_mypy(self):
try:
import mypy # NoQA
except ImportError:
raise unittest.SkipTest('mypy module is missing')
try:
subprocess.run(
[sys.executable, '-m', 'mypy', '-p', 'azure.functions'],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=str(ROOT_PATH))
except subprocess.CalledProcessError as ex:
output = ex.output.decode()
raise AssertionError(
f'mypy validation failed:\n{output}') from None
def test_flake8(self):
try:
import flake8 # NoQA
except ImportError:
raise unittest.SkipTest('flake8 module is missing')
config_path = ROOT_PATH / '.flake8'
if not config_path.exists():
raise unittest.SkipTest('could not locate the .flake8 file')
try:
subprocess.run(
[sys.executable, '-m', 'flake8', '--config', str(config_path)],
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
cwd=str(ROOT_PATH))
except subprocess.CalledProcessError as ex:
output = ex.output.decode()
raise AssertionError(
f'flake8 validation failed:\n{output}') from None
def test_library_version(self):
# PEP 440 Parsing version strings with regular expressions
is_valid = re.match(
r'^([1-9][0-9]*!)?(0|[1-9][0-9]*)(\.(0|[1-9][0-9]*))'
r'*((a|b|rc)(0|[1-9][0-9]*))?(\.post(0|[1-9][0-9]*))'
r'?(\.dev(0|[1-9][0-9]*))?$', func.__version__) is not None
self.assertTrue(is_valid, '__version__ field must be canonical')