forked from pantsbuild/pants
/
test_build_local_python_distributions.py
127 lines (107 loc) · 3.84 KB
/
test_build_local_python_distributions.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
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
# coding=utf-8
# Copyright 2017 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).
from __future__ import absolute_import, division, print_function, unicode_literals
import re
import pex.resolver
from twitter.common.collections import OrderedDict
from pants.backend.python.python_requirement import PythonRequirement
from pants.backend.python.targets.python_distribution import PythonDistribution
from pants.backend.python.targets.python_library import PythonLibrary
from pants.backend.python.targets.python_requirement_library import PythonRequirementLibrary
from pants_test.backend.python.tasks.util.build_local_dists_test_base import \
BuildLocalPythonDistributionsTestBase
class TestBuildLocalDistsNativeSources(BuildLocalPythonDistributionsTestBase):
dist_specs = OrderedDict([
('src/python/dist:universal_dist', {
'key': 'universal',
'target_type': PythonDistribution,
'sources': ['__init__.py', 'setup.py'],
'filemap': {
'__init__.py': '',
'setup.py': """\
from setuptools import find_packages, setup
setup(
name='universal_dist',
version='0.0.0',
packages=find_packages()
)
""",
},
}),
('3rdparty/python:pycountry', {
'key': 'pycountry',
'target_type': PythonRequirementLibrary,
'requirements': [
PythonRequirement('pycountry==18.5.20'),
],
}),
('src/python/setup_requires:setup_requires', {
'key': 'setup_requires',
'target_type': PythonDistribution,
'setup_requires': [
'3rdparty/python:pycountry',
],
'sources': ['__init__.py', 'setup.py'],
'filemap': {
'__init__.py': '',
'setup.py': """\
from setuptools import find_packages, setup
import pycountry
us_country_string = pycountry.countries.get(alpha_2='US').name.replace(' ', '_').lower()
setup(
name='setup_requires_dist_{}'.format(us_country_string),
version='0.0.0',
packages=find_packages(),
)
""",
},
}),
('src/python/install_requires:install_requires', {
'key': 'install_requires',
'target_type': PythonDistribution,
'sources': ['__init__.py', 'setup.py'],
'filemap': {
'__init__.py': '',
'setup.py': """\
from setuptools import setup
setup(
name='install_requires_dist',
version='0.0.0',
install_requires=['pycountry==17.1.2'],
)
""",
},
}),
('src/python/install_requires:conflict', {
'key': 'install_requires_conflict',
'target_type': PythonLibrary,
'dependencies': [
'3rdparty/python:pycountry',
'src/python/install_requires:install_requires',
],
}),
])
def test_create_distribution(self):
universal_dist = self.target_dict['universal']
self._assert_dist_and_wheel_identity('universal_dist', '0.0.0', 'any', universal_dist)
def test_python_dist_setup_requires(self):
setup_requires_dist = self.target_dict['setup_requires']
self._assert_dist_and_wheel_identity(
'setup_requires_dist_united_states', '0.0.0', 'any',
setup_requires_dist, extra_targets=[self.target_dict['pycountry']])
def test_install_requires(self):
install_requires_dist = self.target_dict['install_requires']
self._assert_dist_and_wheel_identity(
'install_requires_dist', '0.0.0', 'any',
install_requires_dist)
def test_install_requires_conflict(self):
install_requires_dist = self.target_dict['install_requires']
pycountry_req_lib = self.target_dict['pycountry']
conflicting_lib = self.target_dict['install_requires_conflict']
with self.assertRaisesRegexp(
pex.resolver.Unsatisfiable,
re.escape('Could not satisfy all requirements for pycountry==18.5.20:')):
self._create_distribution_synthetic_target(
install_requires_dist,
extra_targets=[pycountry_req_lib, conflicting_lib])