• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:index_sources.bzl", "index_sources")  # buildifier: disable=bzl-visibility
19
20_tests = []
21
22def _test_no_simple_api_sources(env):
23    inputs = [
24        "foo==0.0.1",
25        "foo==0.0.1 @ https://someurl.org",
26        "foo==0.0.1 @ https://someurl.org --hash=sha256:deadbeef",
27        "foo==0.0.1 @ https://someurl.org; python_version < 2.7 --hash=sha256:deadbeef",
28    ]
29    for input in inputs:
30        got = index_sources(input)
31        env.expect.that_collection(got.shas).contains_exactly([])
32        env.expect.that_str(got.version).equals("0.0.1")
33
34_tests.append(_test_no_simple_api_sources)
35
36def _test_simple_api_sources(env):
37    tests = {
38        "foo==0.0.2 --hash=sha256:deafbeef    --hash=sha256:deadbeef": [
39            "deadbeef",
40            "deafbeef",
41        ],
42        "foo[extra]==0.0.2; (python_version < 2.7 or something_else == \"@\") --hash=sha256:deafbeef    --hash=sha256:deadbeef": [
43            "deadbeef",
44            "deafbeef",
45        ],
46    }
47    for input, want_shas in tests.items():
48        got = index_sources(input)
49        env.expect.that_collection(got.shas).contains_exactly(want_shas)
50        env.expect.that_str(got.version).equals("0.0.2")
51
52_tests.append(_test_simple_api_sources)
53
54def index_sources_test_suite(name):
55    """Create the test suite.
56
57    Args:
58        name: the name of the test suite
59    """
60    test_suite(name = name, basic_tests = _tests)
61