• 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:generate_group_library_build_bazel.bzl", "generate_group_library_build_bazel")  # buildifier: disable=bzl-visibility
19
20_tests = []
21
22def _test_simple(env):
23    want = """\
24load("@rules_python//python:defs.bzl", "py_library")
25
26
27## Group vbap
28
29filegroup(
30    name = "vbap_whl",
31    srcs = [],
32    data = [
33        "@pypi_oletools//:_whl",
34        "@pypi_pcodedmp//:_whl",
35    ],
36    visibility = [
37        "@pypi_oletools//:__pkg__",
38        "@pypi_pcodedmp//:__pkg__",
39    ],
40)
41
42py_library(
43    name = "vbap_pkg",
44    srcs = [],
45    deps = [
46        "@pypi_oletools//:_pkg",
47        "@pypi_pcodedmp//:_pkg",
48    ],
49    visibility = [
50        "@pypi_oletools//:__pkg__",
51        "@pypi_pcodedmp//:__pkg__",
52    ],
53)
54"""
55    actual = generate_group_library_build_bazel(
56        repo_prefix = "pypi_",
57        groups = {"vbap": ["pcodedmp", "oletools"]},
58    )
59    env.expect.that_str(actual).equals(want)
60
61_tests.append(_test_simple)
62
63def _test_in_hub(env):
64    want = """\
65load("@rules_python//python:defs.bzl", "py_library")
66
67
68## Group vbap
69
70filegroup(
71    name = "vbap_whl",
72    srcs = [],
73    data = [
74        "//oletools:_whl",
75        "//pcodedmp:_whl",
76    ],
77    visibility = ["//:__subpackages__"],
78)
79
80py_library(
81    name = "vbap_pkg",
82    srcs = [],
83    deps = [
84        "//oletools:_pkg",
85        "//pcodedmp:_pkg",
86    ],
87    visibility = ["//:__subpackages__"],
88)
89"""
90    actual = generate_group_library_build_bazel(
91        repo_prefix = "",
92        groups = {"vbap": ["pcodedmp", "oletools"]},
93    )
94    env.expect.that_str(actual).equals(want)
95
96_tests.append(_test_in_hub)
97
98def generate_group_library_build_bazel_test_suite(name):
99    """Create the test suite.
100
101    Args:
102        name: the name of the test suite
103    """
104    test_suite(name = name, basic_tests = _tests)
105