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 python.runfiles import runfiles 23 24 25class PipInstallTest(unittest.TestCase): 26 maxDiff = None 27 28 def _remove_leading_dirs(self, paths): 29 # Removes the first two directories (external/<reponame>) 30 # to normalize what workspace and bzlmod produce. 31 return ["/".join(v.split("/")[2:]) for v in paths] 32 33 def test_entry_point(self): 34 entry_point_path = os.environ.get("YAMLLINT_ENTRY_POINT") 35 self.assertIsNotNone(entry_point_path) 36 37 r = runfiles.Create() 38 39 entry_point = Path(r.Rlocation(entry_point_path)) 40 self.assertTrue(entry_point.exists()) 41 42 proc = subprocess.run( 43 [str(entry_point), "--version"], 44 check=True, 45 stdout=subprocess.PIPE, 46 stderr=subprocess.PIPE, 47 ) 48 self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.28.0") 49 50 def test_data(self): 51 actual = os.environ.get("WHEEL_DATA_CONTENTS") 52 self.assertIsNotNone(actual) 53 actual = self._remove_leading_dirs(actual.split(" ")) 54 55 self.assertListEqual( 56 actual, 57 [ 58 "data/share/doc/packages/s3cmd/INSTALL.md", 59 "data/share/doc/packages/s3cmd/LICENSE", 60 "data/share/doc/packages/s3cmd/NEWS", 61 "data/share/doc/packages/s3cmd/README.md", 62 "data/share/man/man1/s3cmd.1", 63 ], 64 ) 65 66 def test_dist_info(self): 67 actual = os.environ.get("WHEEL_DIST_INFO_CONTENTS") 68 self.assertIsNotNone(actual) 69 actual = self._remove_leading_dirs(actual.split(" ")) 70 self.assertListEqual( 71 actual, 72 [ 73 "site-packages/requests-2.25.1.dist-info/INSTALLER", 74 "site-packages/requests-2.25.1.dist-info/LICENSE", 75 "site-packages/requests-2.25.1.dist-info/METADATA", 76 "site-packages/requests-2.25.1.dist-info/RECORD", 77 "site-packages/requests-2.25.1.dist-info/WHEEL", 78 "site-packages/requests-2.25.1.dist-info/top_level.txt", 79 ], 80 ) 81 82 83if __name__ == "__main__": 84 unittest.main() 85