forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_order_setup.py
More file actions
executable file
·133 lines (112 loc) · 5.3 KB
/
Copy pathtest_order_setup.py
File metadata and controls
executable file
·133 lines (112 loc) · 5.3 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
"""
Test for an order of dependencies in setup.py
"""
import os
import re
import unittest
class TestOrderSetup(unittest.TestCase):
def setUp(self):
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
self.setup_file = open('{parent_dir}/setup.py'.format(parent_dir=parent_dir))
self.setup_context = self.setup_file.read()
def tearDown(self):
self.setup_file.close()
def test_main_dependent_group(self):
"""
Test for an order of dependencies groups between mark
'# Start dependencies group' and '# End dependencies group' in setup.py
"""
pattern_main_dependent_group = re.compile(
'# Start dependencies group\n(.*)# End dependencies group', re.DOTALL)
main_dependent_group = pattern_main_dependent_group.findall(self.setup_context)[0]
pattern_sub_dependent = re.compile(' = \\[.*?\\]\n', re.DOTALL)
main_dependent = pattern_sub_dependent.sub(',', main_dependent_group)
src = main_dependent.strip(',').split(',')
alphabetical = sorted(src)
self.assertListEqual(alphabetical, src)
def test_sub_dependent_group(self):
"""
Test for an order of each dependencies groups declare like
`^dependent_group_name = [.*?]\n` in setup.py
"""
pattern_dependent_group_name = re.compile('^(\\w+) = \\[', re.MULTILINE)
dependent_group_names = pattern_dependent_group_name.findall(self.setup_context)
pattern_dependent_version = re.compile('[~|>|<|=|;].*')
for group_name in dependent_group_names:
pattern_sub_dependent = re.compile(
'{group_name} = \\[(.*?)\\]'.format(group_name=group_name), re.DOTALL)
sub_dependent = pattern_sub_dependent.findall(self.setup_context)[0]
pattern_dependent = re.compile('\'(.*?)\'')
dependent = pattern_dependent.findall(sub_dependent)
src = [pattern_dependent_version.sub('', p) for p in dependent]
alphabetical = sorted(src)
self.assertListEqual(alphabetical, src)
def test_alias_dependent_group(self):
"""
Test for an order of each dependencies groups declare like
`alias_dependent_group = dependent_group_1 + ... + dependent_group_n` in setup.py
"""
pattern = re.compile('^\\w+ = (\\w+ \\+.*)', re.MULTILINE)
dependents = pattern.findall(self.setup_context)
for dependent in dependents:
src = dependent.split(' + ')
alphabetical = sorted(src)
self.assertListEqual(alphabetical, src)
def test_devel_all(self):
"""
Test for an order of dependencies groups
devel_all = (dependent_group_1 + ... + dependent_group_n) in setup.py
"""
pattern = re.compile('devel_all = \\((.*?)\\)', re.DOTALL)
dependent = pattern.findall(self.setup_context)[0]
pattern_new_line = re.compile('\\n *')
src = pattern_new_line.sub(' ', dependent).split(' + ')
alphabetical = sorted(src)
self.assertListEqual(alphabetical, src)
def test_install_and_setup_requires(self):
"""
Test for an order of dependencies in function do_setup section
install_requires and setup_requires in setup.py
"""
pattern_install_and_setup_requires = re.compile(
'(install_requires|setup_requires)=\\[(.*?)\\]', re.DOTALL)
install_and_setup_requires = pattern_install_and_setup_requires.findall(self.setup_context)
for dependent_requires in install_and_setup_requires:
pattern_dependent = re.compile('\'(.*?)\'')
dependent = pattern_dependent.findall(dependent_requires[1])
pattern_dependent_version = re.compile('[~|>|<|=|;].*')
src = [pattern_dependent_version.sub('', p) for p in dependent]
alphabetical = sorted(src)
self.assertListEqual(alphabetical, src)
def test_extras_require(self):
"""
Test for an order of dependencies in function do_setup section
extras_require in setup.py
"""
pattern_extras_requires = re.compile('extras_require=\\{(.*?)\\}', re.DOTALL)
extras_requires = pattern_extras_requires.findall(self.setup_context)[0]
pattern_dependent = re.compile('\'(.*?)\'')
src = pattern_dependent.findall(extras_requires)
alphabetical = sorted(src)
self.assertListEqual(alphabetical, src)
if __name__ == '__main__':
unittest.main(verbosity=2)