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/pypi:parse_whl_name.bzl", "parse_whl_name") # buildifier: disable=bzl-visibility 19 20_tests = [] 21 22def _test_simple(env): 23 got = parse_whl_name("foo-1.2.3-py3-none-any.whl") 24 env.expect.that_str(got.distribution).equals("foo") 25 env.expect.that_str(got.version).equals("1.2.3") 26 env.expect.that_str(got.abi_tag).equals("none") 27 env.expect.that_str(got.platform_tag).equals("any") 28 env.expect.that_str(got.python_tag).equals("py3") 29 env.expect.that_str(got.build_tag).equals(None) 30 31_tests.append(_test_simple) 32 33def _test_with_build_tag(env): 34 got = parse_whl_name("foo-3.2.1-9999-py2.py3-none-any.whl") 35 env.expect.that_str(got.distribution).equals("foo") 36 env.expect.that_str(got.version).equals("3.2.1") 37 env.expect.that_str(got.abi_tag).equals("none") 38 env.expect.that_str(got.platform_tag).equals("any") 39 env.expect.that_str(got.python_tag).equals("py2.py3") 40 env.expect.that_str(got.build_tag).equals("9999") 41 42_tests.append(_test_with_build_tag) 43 44def _test_multiple_platforms(env): 45 got = parse_whl_name("bar-3.2.1-py3-abi3-manylinux1.manylinux2.whl") 46 env.expect.that_str(got.distribution).equals("bar") 47 env.expect.that_str(got.version).equals("3.2.1") 48 env.expect.that_str(got.abi_tag).equals("abi3") 49 env.expect.that_str(got.platform_tag).equals("manylinux1.manylinux2") 50 env.expect.that_str(got.python_tag).equals("py3") 51 env.expect.that_str(got.build_tag).equals(None) 52 53_tests.append(_test_multiple_platforms) 54 55def _test_real_numpy_wheel(env): 56 got = parse_whl_name("numpy-1.26.1-pp39-pypy39_pp73-macosx_10_9_x86_64.whl") 57 env.expect.that_str(got.distribution).equals("numpy") 58 env.expect.that_str(got.version).equals("1.26.1") 59 env.expect.that_str(got.abi_tag).equals("pypy39_pp73") 60 env.expect.that_str(got.platform_tag).equals("macosx_10_9_x86_64") 61 env.expect.that_str(got.python_tag).equals("pp39") 62 env.expect.that_str(got.build_tag).equals(None) 63 64_tests.append(_test_real_numpy_wheel) 65 66def parse_whl_name_test_suite(name): 67 """Create the test suite. 68 69 Args: 70 name: the name of the test suite 71 """ 72 test_suite(name = name, basic_tests = _tests) 73