|
1 | | -"""Unit tests for repo_utils.bzl.""" |
2 | | - |
3 | | -load("@rules_testing//lib:test_suite.bzl", "test_suite") |
4 | | -load("//python/private:repo_utils.bzl", "repo_utils") # buildifier: disable=bzl-visibility |
5 | | -load("//tests/support:mocks.bzl", "mocks") |
6 | | - |
7 | | -_tests = [] |
8 | | - |
9 | | -def _test_get_platforms_os_name(env): |
10 | | - mock_mrctx = mocks.rctx(os_name = "Mac OS X") |
11 | | - got = repo_utils.get_platforms_os_name(mock_mrctx) |
12 | | - env.expect.that_str(got).equals("osx") |
13 | | - |
14 | | -_tests.append(_test_get_platforms_os_name) |
15 | | - |
16 | | -def _test_relative_to(env): |
17 | | - mock_mrctx_linux = mocks.rctx(os_name = "linux") |
18 | | - mock_mrctx_win = mocks.rctx(os_name = "windows") |
19 | | - |
20 | | - # Case-sensitive matching (Linux) |
21 | | - got = repo_utils.relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar") |
22 | | - env.expect.that_str(got).equals("baz") |
23 | | - |
24 | | - # Case-insensitive matching (Windows) |
25 | | - got = repo_utils.relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar") |
26 | | - env.expect.that_str(got).equals("Baz") |
27 | | - |
28 | | - # Failure case |
29 | | - failures = [] |
30 | | - def _mock_fail(msg): |
31 | | - failures.append(msg) |
32 | | - |
33 | | - repo_utils.relative_to(mock_mrctx_linux, "foo/bar/baz", "qux", fail = _mock_fail) |
34 | | - env.expect.that_collection(failures).contains_exactly(["foo/bar/baz is not relative to qux"]) |
35 | | - |
36 | | -_tests.append(_test_relative_to) |
37 | | - |
38 | | -def _test_is_relative_to(env): |
39 | | - mock_mrctx_linux = mocks.rctx(os_name = "linux") |
40 | | - mock_mrctx_win = mocks.rctx(os_name = "windows") |
41 | | - |
42 | | - # Case-sensitive matching (Linux) |
43 | | - env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar")).equals(True) |
44 | | - env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "qux")).equals(False) |
45 | | - |
46 | | - # Case-insensitive matching (Windows) |
47 | | - env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar")).equals(True) |
48 | | - env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "D:/Foo")).equals(False) |
49 | | - |
50 | | -_tests.append(_test_is_relative_to) |
51 | | - |
52 | | -def repo_utils_test_suite(name): |
| 1 | +"""Unit tests for repo_utils.bzl.""" |
| 2 | + |
| 3 | +load("@rules_testing//lib:test_suite.bzl", "test_suite") |
| 4 | +load("//python/private:repo_utils.bzl", "repo_utils") # buildifier: disable=bzl-visibility |
| 5 | +load("//tests/support:mocks.bzl", "mocks") |
| 6 | + |
| 7 | +_tests = [] |
| 8 | + |
| 9 | +def _test_get_platforms_os_name(env): |
| 10 | + mock_mrctx = mocks.rctx(os_name = "Mac OS X") |
| 11 | + got = repo_utils.get_platforms_os_name(mock_mrctx) |
| 12 | + env.expect.that_str(got).equals("osx") |
| 13 | + |
| 14 | +_tests.append(_test_get_platforms_os_name) |
| 15 | + |
| 16 | +def _test_relative_to(env): |
| 17 | + mock_mrctx_linux = mocks.rctx(os_name = "linux") |
| 18 | + mock_mrctx_win = mocks.rctx(os_name = "windows") |
| 19 | + |
| 20 | + # Case-sensitive matching (Linux) |
| 21 | + got = repo_utils.relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar") |
| 22 | + env.expect.that_str(got).equals("baz") |
| 23 | + |
| 24 | + # Case-insensitive matching (Windows) |
| 25 | + got = repo_utils.relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar") |
| 26 | + env.expect.that_str(got).equals("Baz") |
| 27 | + |
| 28 | + # Failure case |
| 29 | + failures = [] |
| 30 | + |
| 31 | + def _mock_fail(msg): |
| 32 | + failures.append(msg) |
| 33 | + |
| 34 | + repo_utils.relative_to(mock_mrctx_linux, "foo/bar/baz", "qux", fail = _mock_fail) |
| 35 | + env.expect.that_collection(failures).contains_exactly(["foo/bar/baz is not relative to qux"]) |
| 36 | + |
| 37 | +_tests.append(_test_relative_to) |
| 38 | + |
| 39 | +def _test_is_relative_to(env): |
| 40 | + mock_mrctx_linux = mocks.rctx(os_name = "linux") |
| 41 | + mock_mrctx_win = mocks.rctx(os_name = "windows") |
| 42 | + |
| 43 | + # Case-sensitive matching (Linux) |
| 44 | + env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "foo/bar")).equals(True) |
| 45 | + env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_linux, "foo/bar/baz", "qux")).equals(False) |
| 46 | + |
| 47 | + # Case-insensitive matching (Windows) |
| 48 | + env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "c:/foo/bar")).equals(True) |
| 49 | + env.expect.that_bool(repo_utils.is_relative_to(mock_mrctx_win, "C:/Foo/Bar/Baz", "D:/Foo")).equals(False) |
| 50 | + |
| 51 | +_tests.append(_test_is_relative_to) |
| 52 | + |
| 53 | +def repo_utils_test_suite(name): |
53 | 54 | """Create the test suite. |
54 | 55 |
|
55 | 56 | Args: |
56 | 57 | name: the name of the test suite |
57 | | - """ |
58 | | - test_suite(name = name, basic_tests = _tests) |
| 58 | + """ |
| 59 | + test_suite(name = name, basic_tests = _tests) |
0 commit comments