• 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(r.Rlocation("rules_python_pip_parse_example/{}".format(env)))
36        self.assertTrue(entry_point.exists())
37
38        proc = subprocess.run(
39            [str(entry_point), "--version"],
40            check=True,
41            stdout=subprocess.PIPE,
42            stderr=subprocess.PIPE,
43        )
44        self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.26.3")
45
46    def test_data(self):
47        env = os.environ.get("WHEEL_DATA_CONTENTS")
48        self.assertIsNotNone(env)
49        self.assertListEqual(
50            env.split(" "),
51            [
52                "external/pypi_s3cmd/data/share/doc/packages/s3cmd/INSTALL.md",
53                "external/pypi_s3cmd/data/share/doc/packages/s3cmd/LICENSE",
54                "external/pypi_s3cmd/data/share/doc/packages/s3cmd/NEWS",
55                "external/pypi_s3cmd/data/share/doc/packages/s3cmd/README.md",
56                "external/pypi_s3cmd/data/share/man/man1/s3cmd.1",
57            ],
58        )
59
60    def test_dist_info(self):
61        env = os.environ.get("WHEEL_DIST_INFO_CONTENTS")
62        self.assertIsNotNone(env)
63        self.assertListEqual(
64            env.split(" "),
65            [
66                "external/pypi_requests/site-packages/requests-2.25.1.dist-info/INSTALLER",
67                "external/pypi_requests/site-packages/requests-2.25.1.dist-info/LICENSE",
68                "external/pypi_requests/site-packages/requests-2.25.1.dist-info/METADATA",
69                "external/pypi_requests/site-packages/requests-2.25.1.dist-info/RECORD",
70                "external/pypi_requests/site-packages/requests-2.25.1.dist-info/WHEEL",
71                "external/pypi_requests/site-packages/requests-2.25.1.dist-info/top_level.txt",
72            ],
73        )
74
75
76if __name__ == "__main__":
77    unittest.main()
78