xref: /aosp_15_r20/external/bazelbuild-rules_python/tests/version_label/version_label_test.bzl (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1# Copyright 2023 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#     http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15""
16
17load("@rules_testing//lib:test_suite.bzl", "test_suite")
18load("//python/private:version_label.bzl", "version_label")  # buildifier: disable=bzl-visibility
19
20_tests = []
21
22def _test_version_label_from_major_minor_version(env):
23    actual = version_label("3.9")
24    env.expect.that_str(actual).equals("39")
25
26_tests.append(_test_version_label_from_major_minor_version)
27
28def _test_version_label_from_major_minor_patch_version(env):
29    actual = version_label("3.9.3")
30    env.expect.that_str(actual).equals("39")
31
32_tests.append(_test_version_label_from_major_minor_patch_version)
33
34def _test_version_label_from_major_minor_version_custom_sep(env):
35    actual = version_label("3.9", sep = "_")
36    env.expect.that_str(actual).equals("3_9")
37
38_tests.append(_test_version_label_from_major_minor_version_custom_sep)
39
40def _test_version_label_from_complex_version(env):
41    actual = version_label("3.9.3-rc.0")
42    env.expect.that_str(actual).equals("39")
43
44_tests.append(_test_version_label_from_complex_version)
45
46def version_label_test_suite(name):
47    """Create the test suite.
48
49    Args:
50        name: the name of the test suite
51    """
52    test_suite(name = name, basic_tests = _tests)
53