forked from pantsbuild/pants
/
test_subproject_integration.py
112 lines (95 loc) · 3.02 KB
/
test_subproject_integration.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
# 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
from contextlib import contextmanager
from textwrap import dedent
from pants.util.dirutil import safe_file_dump, safe_rmtree
from pants_test.pants_run_integration_test import PantsRunIntegrationTest
SUBPROJ_SPEC = 'testprojects/src/python/subproject_test/'
SUBPROJ_ROOT = 'testprojects/src/python/subproject_test/subproject'
BUILD_FILES = {
'testprojects/src/python/subproject_test/BUILD':
"""
python_library(
dependencies = ['//testprojects/src/python/subproject_test/subproject/src/python:helpers'],
)
""",
'testprojects/src/python/subproject_test/subproject/BUILD':
"""
target(
name = 'local',
dependencies = [
':relative',
'//:absolute',
],
)
target(
name = 'relative',
)
target(
name = 'absolute',
)
""",
'testprojects/src/python/subproject_test/subproject/src/python/BUILD':
"""
python_library(
name = 'helpers',
dependencies = ['//src/python/helpershelpers'],
)
""",
'testprojects/src/python/subproject_test/subproject/src/python/helpershelpers/BUILD':
"""
python_library(
name = 'helpershelpers',
)
"""
}
"""
Test layout
-----------
testprojects/
src/
python/
subproject_test/
BUILD
subproject/
src/
python/
BUILD/
helpershelpers/
BUILD/
"""
@contextmanager
def harness():
try:
for name, content in BUILD_FILES.items():
safe_file_dump(name, dedent(content), binary_mode=False)
yield
finally:
safe_rmtree(SUBPROJ_SPEC)
class SubprojectIntegrationTest(PantsRunIntegrationTest):
def test_subproject_without_flag(self):
"""
Assert that when getting the dependencies of a project which relies
on a subproject which relies on its own internal library, a failure
occurs without the --subproject-roots option
"""
with harness():
pants_args = ['dependencies', SUBPROJ_SPEC]
self.assert_failure(self.run_pants(pants_args))
def test_subproject_with_flag(self):
"""
Assert that when getting the dependencies of a project which relies on
a subproject which relies on its own internal library, all things
go well when that subproject is declared as a subproject
"""
with harness():
# Has dependencies below the subproject.
pants_args = ['--subproject-roots={}'.format(SUBPROJ_ROOT),
'dependencies', SUBPROJ_SPEC]
self.assert_success(self.run_pants(pants_args))
# A relative path at the root of the subproject.
pants_args = ['--subproject-roots={}'.format(SUBPROJ_ROOT),
'dependencies', '{}:local'.format(SUBPROJ_ROOT)]
self.assert_success(self.run_pants(pants_args))