This repository has been archived by the owner on Apr 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_meta.py
79 lines (62 loc) · 2.25 KB
/
test_meta.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import doctest
import importlib
import os
from itertools import groupby
import mock
from serde import fields
from tests import REPO_DIR, py36
@py36
def test_readme():
failures, _ = doctest.testfile('../README.rst')
if failures:
raise Exception('doctests in README.rst failed')
@mock.patch('setuptools.setup')
@mock.patch('setuptools.find_packages')
def test_setup_requirements_sorted(find_packages, setup):
"""
Check that setup.py requirements are sorted.
"""
setup_mod = importlib.import_module('setup')
assert setup_mod.install_requires == sorted(setup_mod.install_requires)
assert setup_mod.ext_requires == sorted(setup_mod.ext_requires)
def test_dev_requirements_sorted():
"""
Check that dev-requirements.in is sorted (within sections).
"""
with open(os.path.join(REPO_DIR, 'dev-requirements.in'), 'r') as f:
lines = f.readlines()
def is_comment_or_empty(l):
return not l.strip() or l.lstrip().startswith('#')
for _, group in groupby(lines, key=is_comment_or_empty):
grouped = list(group)
assert grouped == sorted(grouped)
def test_module___all__s():
"""
Check that there is nothing bad in any module __all__ by importing *.
"""
def module_from_path(p):
p = p[: -len('/__init__')] if p.endswith('__init__') else p
return p.replace('/', '.')
src_dir = os.path.join(REPO_DIR, 'src')
filenames = [
os.path.splitext(os.path.relpath(os.path.join(dirpath, filename), src_dir))[0]
for dirpath, dirnames, filenames in os.walk(src_dir)
for filename in filenames
if filename.endswith('.py')
]
for module in [module_from_path(f) for f in filenames]:
exec ('from {} import *'.format(module), {}, {}) # noqa: E211
def test_field_class_map():
"""
Check that all Instance type fields are in the FIELD_CLASS_MAP.
"""
for name in fields.__all__:
field_cls = getattr(fields, name)
if fields.is_subclass(field_cls, fields.Instance):
try:
ty = field_cls().ty
except TypeError:
pass
else:
msg = '{!r} not in FIELD_CLASS_MAP'.format(ty.__name__)
assert ty in fields.FIELD_CLASS_MAP, msg