Skip to content

Commit 89bec57

Browse files
authored
test: basic analysis tests for py_wheel (bazel-contrib#1279)
This adds some basic analysis tests of py_wheel to cover the functionality it's recently introduced.
1 parent 2fb9a2a commit 89bec57

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

tests/py_wheel/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
"""Tests for py_wheel."""
15+
16+
load(":py_wheel_tests.bzl", "py_wheel_test_suite")
17+
18+
py_wheel_test_suite(name = "py_wheel_tests")

tests/py_wheel/py_wheel_tests.bzl

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
"""Test for py_wheel."""
15+
16+
load("@rules_testing//lib:analysis_test.bzl", "analysis_test", "test_suite")
17+
load("@rules_testing//lib:util.bzl", rt_util = "util")
18+
load("//python:packaging.bzl", "py_wheel")
19+
20+
_tests = []
21+
22+
def _test_metadata(name):
23+
rt_util.helper_target(
24+
py_wheel,
25+
name = name + "_subject",
26+
distribution = "mydist_" + name,
27+
version = "0.0.0",
28+
)
29+
analysis_test(
30+
name = name,
31+
impl = _test_metadata_impl,
32+
target = name + "_subject",
33+
)
34+
35+
def _test_metadata_impl(env, target):
36+
action = env.expect.that_target(target).action_generating(
37+
"{package}/{name}.metadata.txt",
38+
)
39+
action.content().split("\n").contains_exactly([
40+
env.expect.meta.format_str("Name: mydist_{test_name}"),
41+
"Metadata-Version: 2.1",
42+
"",
43+
])
44+
45+
_tests.append(_test_metadata)
46+
47+
def _test_content_type_from_attr(name):
48+
rt_util.helper_target(
49+
py_wheel,
50+
name = name + "_subject",
51+
distribution = "mydist_" + name,
52+
version = "0.0.0",
53+
description_content_type = "text/x-rst",
54+
)
55+
analysis_test(
56+
name = name,
57+
impl = _test_content_type_from_attr_impl,
58+
target = name + "_subject",
59+
)
60+
61+
def _test_content_type_from_attr_impl(env, target):
62+
action = env.expect.that_target(target).action_generating(
63+
"{package}/{name}.metadata.txt",
64+
)
65+
action.content().split("\n").contains(
66+
"Description-Content-Type: text/x-rst",
67+
)
68+
69+
_tests.append(_test_content_type_from_attr)
70+
71+
def _test_content_type_from_description(name):
72+
rt_util.helper_target(
73+
py_wheel,
74+
name = name + "_subject",
75+
distribution = "mydist_" + name,
76+
version = "0.0.0",
77+
description_file = "desc.md",
78+
)
79+
analysis_test(
80+
name = name,
81+
impl = _test_content_type_from_description_impl,
82+
target = name + "_subject",
83+
)
84+
85+
def _test_content_type_from_description_impl(env, target):
86+
action = env.expect.that_target(target).action_generating(
87+
"{package}/{name}.metadata.txt",
88+
)
89+
action.content().split("\n").contains(
90+
"Description-Content-Type: text/markdown",
91+
)
92+
93+
_tests.append(_test_content_type_from_description)
94+
95+
def py_wheel_test_suite(name):
96+
test_suite(
97+
name = name,
98+
tests = _tests,
99+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy