|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 |
|
15 | | -"Unit tests for yaml.bzl" |
| 15 | +"Unit tests for relative_path computation" |
16 | 16 |
|
17 | | -load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") |
| 17 | +load("@rules_testing//lib:test_suite.bzl", "test_suite") |
18 | 18 | load("//python/private:py_executable_bazel.bzl", "relative_path") # buildifier: disable=bzl-visibility |
19 | 19 |
|
20 | | -def _relative_path_test_impl(ctx): |
21 | | - env = unittest.begin(ctx) |
| 20 | +_tests = [] |
22 | 21 |
|
| 22 | +def _relative_path_test(env): |
23 | 23 | # Basic test cases |
24 | 24 |
|
25 | | - asserts.equals( |
26 | | - env, |
27 | | - "../../c/d", |
| 25 | + env.expect.that_str( |
28 | 26 | relative_path( |
29 | 27 | from_ = "a/b", |
30 | 28 | to = "c/d", |
31 | 29 | ), |
32 | | - ) |
| 30 | + ).equals("../../c/d") |
33 | 31 |
|
34 | | - asserts.equals( |
35 | | - env, |
36 | | - "../../c/d", |
| 32 | + env.expect.that_str( |
37 | 33 | relative_path( |
38 | 34 | from_ = "../a/b", |
39 | 35 | to = "../c/d", |
40 | 36 | ), |
41 | | - ) |
| 37 | + ).equals("../../c/d") |
42 | 38 |
|
43 | | - asserts.equals( |
44 | | - env, |
45 | | - "../../../c/d", |
| 39 | + env.expect.that_str( |
46 | 40 | relative_path( |
47 | 41 | from_ = "../a/b", |
48 | 42 | to = "../../c/d", |
49 | 43 | ), |
50 | | - ) |
| 44 | + ).equals("../../../c/d") |
51 | 45 |
|
52 | | - asserts.equals( |
53 | | - env, |
54 | | - "../../d", |
| 46 | + env.expect.that_str( |
55 | 47 | relative_path( |
56 | 48 | from_ = "a/b/c", |
57 | 49 | to = "a/d", |
58 | 50 | ), |
59 | | - ) |
60 | | - |
61 | | - asserts.equals( |
62 | | - env, |
63 | | - "d/e", |
| 51 | + ).equals("../../d") |
| 52 | + env.expect.that_str( |
64 | 53 | relative_path( |
65 | 54 | from_ = "a/b/c", |
66 | 55 | to = "a/b/c/d/e", |
67 | 56 | ), |
68 | | - ) |
| 57 | + ).equals("d/e") |
69 | 58 |
|
70 | 59 | # Real examples |
71 | 60 |
|
72 | 61 | # 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( |
76 | 63 | 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", |
79 | 66 | ), |
| 67 | + ).equals( |
| 68 | + "../../../../../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3", |
80 | 69 | ) |
81 | 70 |
|
82 | 71 | # 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( |
86 | 73 | 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", |
89 | 76 | ), |
| 77 | + ).equals( |
| 78 | + "../../../../rules_python~~python~python_3_9_x86_64-unknown-linux-gnu/bin/python3", |
90 | 79 | ) |
91 | 80 |
|
92 | 81 | # 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 | + ) |
102 | 90 |
|
103 | 91 | # 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( |
107 | 93 | 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", |
110 | 96 | ), |
| 97 | + ).equals( |
| 98 | + "../../../python/python_3_9_x86_64-unknown-linux-gnu/bin/python3", |
111 | 99 | ) |
112 | 100 |
|
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) |
119 | 102 |
|
120 | 103 | def relative_path_test_suite(*, name): |
121 | | - unittest.suite(name, relative_path_test) |
| 104 | + test_suite(name = name, basic_tests = _tests) |
0 commit comments