Skip to content

Commit 39e7e5a

Browse files
committed
update tests to use rules_tests; implement commented out case; update real examples to use runfiles-root relative paths
1 parent d09ad2c commit 39e7e5a

File tree

2 files changed

+40
-57
lines changed

2 files changed

+40
-57
lines changed

tests/bootstrap_impls/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,4 @@ sh_py_run_test(
8989
target_compatible_with = _SUPPORTS_BOOTSTRAP_SCRIPT,
9090
)
9191

92-
relative_path_test_suite(name = "relative_path_test")
92+
relative_path_test_suite(name = "relative_path_tests")

tests/bootstrap_impls/venv_relative_path_tests.bzl

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -12,110 +12,93 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
"Unit tests for yaml.bzl"
15+
"Unit tests for relative_path computation"
1616

17-
load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest")
17+
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1818
load("//python/private:py_executable_bazel.bzl", "relative_path") # buildifier: disable=bzl-visibility
1919

20-
def _relative_path_test_impl(ctx):
21-
env = unittest.begin(ctx)
20+
_tests = []
2221

22+
def _relative_path_test(env):
2323
# Basic test cases
2424

25-
asserts.equals(
26-
env,
27-
"../../c/d",
25+
env.expect.that_str(
2826
relative_path(
2927
from_ = "a/b",
3028
to = "c/d",
3129
),
32-
)
30+
).equals("../../c/d")
3331

34-
asserts.equals(
35-
env,
36-
"../../c/d",
32+
env.expect.that_str(
3733
relative_path(
3834
from_ = "../a/b",
3935
to = "../c/d",
4036
),
41-
)
37+
).equals("../../c/d")
4238

43-
asserts.equals(
44-
env,
45-
"../../../c/d",
39+
env.expect.that_str(
4640
relative_path(
4741
from_ = "../a/b",
4842
to = "../../c/d",
4943
),
50-
)
44+
).equals("../../../c/d")
5145

52-
asserts.equals(
53-
env,
54-
"../../d",
46+
env.expect.that_str(
5547
relative_path(
5648
from_ = "a/b/c",
5749
to = "a/d",
5850
),
59-
)
60-
61-
asserts.equals(
62-
env,
63-
"d/e",
51+
).equals("../../d")
52+
env.expect.that_str(
6453
relative_path(
6554
from_ = "a/b/c",
6655
to = "a/b/c/d/e",
6756
),
68-
)
57+
).equals("d/e")
6958

7059
# Real examples
7160

7261
# external py_binary uses external python runtime
73-
asserts.equals(
74-
env,
75-
"../../../../../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
62+
env.expect.that_str(
7663
relative_path(
77-
from_ = "../rules_python~/python/private/_py_console_script_gen_py.venv/bin",
78-
to = "../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
64+
from_ = "other_repo~/python/private/_py_console_script_gen_py.venv/bin",
65+
to = "rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
7966
),
67+
).equals(
68+
"../../../../../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
8069
)
8170

8271
# internal py_binary uses external python runtime
83-
asserts.equals(
84-
env,
85-
"../../../../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
72+
env.expect.that_str(
8673
relative_path(
87-
from_ = "test/version_default.venv/bin",
88-
to = "../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
74+
from_ = "_main/test/version_default.venv/bin",
75+
to = "rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
8976
),
77+
).equals(
78+
"../../../../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3",
9079
)
9180

9281
# external py_binary uses internal python runtime
93-
# asserts.equals(
94-
# env,
95-
# "???",
96-
# relative_path(
97-
# from_ = "../rules_python~/python/private/_py_console_script_gen_py.venv/bin",
98-
# to = "python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
99-
# ),
100-
#)
101-
# ^ TODO: Technically we can infer ".." to be the workspace name?
82+
env.expect.that_str(
83+
relative_path(
84+
from_ = "other_repo~/python/private/_py_console_script_gen_py.venv/bin",
85+
to = "_main/python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
86+
),
87+
).equals(
88+
"../../../../../_main/python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
89+
)
10290

10391
# internal py_binary uses internal python runtime
104-
asserts.equals(
105-
env,
106-
"../../../python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
92+
env.expect.that_str(
10793
relative_path(
108-
from_ = "scratch/main.venv/bin",
109-
to = "python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
94+
from_ = "_main/scratch/main.venv/bin",
95+
to = "_main/python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
11096
),
97+
).equals(
98+
"../../../python/python_3_9_x86_64-unknown-linux-gnu/bin/python3",
11199
)
112100

113-
return unittest.end(env)
114-
115-
relative_path_test = unittest.make(
116-
_relative_path_test_impl,
117-
attrs = {},
118-
)
101+
_tests.append(_relative_path_test)
119102

120103
def relative_path_test_suite(*, name):
121-
unittest.suite(name, relative_path_test)
104+
test_suite(name = name, basic_tests = _tests)

0 commit comments

Comments
 (0)