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 15import os 16import pathlib 17import subprocess 18import unittest 19 20from python.runfiles import runfiles 21 22 23class ExampleTest(unittest.TestCase): 24 def __init__(self, *args, **kwargs): 25 self.maxDiff = None 26 27 super().__init__(*args, **kwargs) 28 29 def test_yamllint_entry_point(self): 30 rlocation_path = os.environ.get("ENTRY_POINT") 31 assert ( 32 rlocation_path is not None 33 ), "expected 'ENTRY_POINT' env variable to be set to rlocation of the tool" 34 35 entry_point = pathlib.Path(runfiles.Create().Rlocation(rlocation_path)) 36 self.assertTrue(entry_point.exists(), f"'{entry_point}' does not exist") 37 38 # Let's run the entrypoint and check the tool version. 39 # 40 # NOTE @aignas 2023-08-24: the Windows python launcher with Python 3.9 and bazel 6 is not happy if we start 41 # passing extra files via `subprocess.run` and it starts to fail with an error that the file which is the 42 # entry_point cannot be found. However, just calling `--version` seems to be fine. 43 proc = subprocess.run( 44 [str(entry_point), "--version"], 45 check=True, 46 stdout=subprocess.PIPE, 47 stderr=subprocess.PIPE, 48 ) 49 self.assertEqual(proc.stdout.decode("utf-8").strip(), "yamllint 1.28.0") 50 51 52if __name__ == "__main__": 53 unittest.main() 54