• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2023 The Bazel Authors. All rights reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16
17import os
18import subprocess
19import unittest
20from pathlib import Path
21
22from rules_python.python.runfiles import runfiles
23
24
25class PipInstallTest(unittest.TestCase):
26    maxDiff = None
27
28    def test_entry_point(self):
29        env = os.environ.get("YAMLLINT_ENTRY_POINT")
30        self.assertIsNotNone(env)
31
32        r = runfiles.Create()
33
34        # To find an external target, this must use `{workspace_name}/$(rootpath @external_repo//:target)`
35        entry_point = Path(
36            r.Rlocation("rules_python_pip_install_example/{}".format(env))
37        )
38        self.assertTrue(entry_point.exists())
39
40        proc = subprocess.run(
41            [str(entry_point), "--version"],
42            check=True,
43            stdout=subprocess.PIPE,
44            stderr=subprocess.PIPE,
45        )
46        self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.26.3")
47
48    def test_data(self):
49        env = os.environ.get("WHEEL_DATA_CONTENTS")
50        self.assertIsNotNone(env)
51        self.assertListEqual(
52            env.split(" "),
53            [
54                "external/pip_s3cmd/data/share/doc/packages/s3cmd/INSTALL.md",
55                "external/pip_s3cmd/data/share/doc/packages/s3cmd/LICENSE",
56                "external/pip_s3cmd/data/share/doc/packages/s3cmd/NEWS",
57                "external/pip_s3cmd/data/share/doc/packages/s3cmd/README.md",
58                "external/pip_s3cmd/data/share/man/man1/s3cmd.1",
59            ],
60        )
61
62    def test_dist_info(self):
63        env = os.environ.get("WHEEL_DIST_INFO_CONTENTS")
64        self.assertIsNotNone(env)
65        self.assertListEqual(
66            env.split(" "),
67            [
68                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/DESCRIPTION.rst",
69                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/INSTALLER",
70                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/METADATA",
71                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/RECORD",
72                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/WHEEL",
73                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/metadata.json",
74                "external/pip_boto3/site-packages/boto3-1.14.63.dist-info/top_level.txt",
75            ],
76        )
77
78
79if __name__ == "__main__":
80    unittest.main()
81