|
| 1 | +# Copyright 2024 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 | +"""Tests for get_release_info.""" |
| 16 | + |
| 17 | +load("@rules_testing//lib:test_suite.bzl", "test_suite") |
| 18 | +load("//python:versions.bzl", "get_release_info") # buildifier: disable=bzl-visibility |
| 19 | + |
| 20 | +_tests = [] |
| 21 | + |
| 22 | +def _test_file_url(env): |
| 23 | + """Tests that a file:/// url is handled correctly.""" |
| 24 | + tool_versions = { |
| 25 | + "3.11.5": { |
| 26 | + "sha256": { |
| 27 | + "x86_64-unknown-linux-gnu": "fbed6f7694b2faae5d7c401a856219c945397f772eea5ca50c6eb825cbc9d1e1", |
| 28 | + }, |
| 29 | + "strip_prefix": "python", |
| 30 | + "url": "file:///tmp/cpython-3.11.5.tar.gz", |
| 31 | + }, |
| 32 | + } |
| 33 | + |
| 34 | + expected_url = "file:///tmp/cpython-3.11.5.tar.gz" |
| 35 | + expected_filename = "file:///tmp/cpython-3.11.5.tar.gz" |
| 36 | + |
| 37 | + filename, urls, strip_prefix, patches, patch_strip = get_release_info( |
| 38 | + platform = "x86_64-unknown-linux-gnu", |
| 39 | + python_version = "3.11.5", |
| 40 | + tool_versions = tool_versions, |
| 41 | + ) |
| 42 | + |
| 43 | + env.expect.that_str(filename).equals(expected_filename) |
| 44 | + env.expect.that_collection(urls).contains_exactly([expected_url]) |
| 45 | + env.expect.that_str(strip_prefix).equals("python") |
| 46 | + env.expect.that_collection(patches).has_size(0) |
| 47 | + env.expect.that_bool(patch_strip == None).equals(True) |
| 48 | + |
| 49 | +_tests.append(_test_file_url) |
| 50 | + |
| 51 | +def get_release_info_test_suite(name): |
| 52 | + """Defines the test suite for get_release_info.""" |
| 53 | + test_suite( |
| 54 | + name = name, |
| 55 | + basic_tests = _tests, |
| 56 | + ) |
0 commit comments