• 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/config_settings/private:py_args.bzl", "py_args")  # buildifier: disable=bzl-visibility
19
20_tests = []
21
22def _test_py_args_default(env):
23    actual = py_args("foo", {})
24
25    want = {
26        "args": None,
27        "data": None,
28        "deps": None,
29        "env": None,
30        "main": "foo.py",
31        "srcs": None,
32    }
33    env.expect.that_dict(actual).contains_exactly(want)
34
35_tests.append(_test_py_args_default)
36
37def _test_kwargs_get_consumed(env):
38    kwargs = {
39        "args": ["some", "args"],
40        "data": ["data"],
41        "deps": ["deps"],
42        "env": {"key": "value"},
43        "main": "__main__.py",
44        "srcs": ["__main__.py"],
45        "visibility": ["//visibility:public"],
46    }
47    actual = py_args("bar_bin", kwargs)
48
49    want = {
50        "args": ["some", "args"],
51        "data": ["data"],
52        "deps": ["deps"],
53        "env": {"key": "value"},
54        "main": "__main__.py",
55        "srcs": ["__main__.py"],
56    }
57    env.expect.that_dict(actual).contains_exactly(want)
58    env.expect.that_dict(kwargs).keys().contains_exactly(["visibility"])
59
60_tests.append(_test_kwargs_get_consumed)
61
62def py_args_test_suite(name):
63    """Create the test suite.
64
65    Args:
66        name: the name of the test suite
67    """
68    test_suite(name = name, basic_tests = _tests)
69