forked from arkq/flake8-requirements
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_setup.py
67 lines (59 loc) · 1.99 KB
/
test_setup.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
import ast
import unittest
from pkg_resources import parse_requirements
from flake8_requirements.checker import SetupVisitor
class Flake8CheckerTestCase(unittest.TestCase):
def test_detect_setup(self):
code = "setup({})".format(",".join((
"name='A'",
"version='1'",
"author='A'",
"packages=['']",
"url='URL'",
)))
setup = SetupVisitor(ast.parse(code), "")
self.assertEqual(setup.redirected, True)
self.assertDictEqual(setup.keywords, {
'name': 'A',
'version': '1',
'packages': [''],
'author': 'A',
'url': 'URL',
})
code = "setup({})".format(",".join(
"{}='{}'".format(x, x)
for x in SetupVisitor.attributes
))
setup = SetupVisitor(ast.parse(code), "")
self.assertEqual(setup.redirected, True)
self.assertDictEqual(setup.keywords, {
x: x for x in SetupVisitor.attributes
})
code = "setup({})".format(",".join((
"name='A'",
"version='1'",
"package='ABC'",
"processing=True",
"verbose=True",
)))
setup = SetupVisitor(ast.parse(code), "")
self.assertEqual(setup.redirected, False)
def test_get_requirements(self):
setup = SetupVisitor(ast.parse("setup(**{})".format(str({
'name': 'A',
'version': '1',
'packages': [''],
'install_requires': ["ABC > 1.0.0", "bar.cat > 2, < 3"],
'extras_require': {
'extra': ["extra < 10"],
},
}))), "")
self.assertEqual(setup.redirected, True)
self.assertEqual(
sorted(setup.get_requirements(), key=lambda x: x.project_name),
sorted(parse_requirements([
"ABC > 1.0.0",
"bar.cat > 2, < 3",
"extra < 10",
]), key=lambda x: x.project_name),
)