1# Copyright 2025 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://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, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14 15from pathlib import Path 16import unittest 17 18import pw_build.test_runfile 19import pw_build.another_test_runfile 20import pw_build_external_runfile_resource.black 21from python.runfiles import runfiles # type: ignore 22 23 24class TestRunfiles(unittest.TestCase): 25 """Tests for pw_py_importable_runfile.""" 26 27 def setUp(self): 28 self.r = runfiles.Create() 29 30 def test_expected_runfiles(self): 31 runfile = Path(self.r.Rlocation(*pw_build.test_runfile.RLOCATION)) 32 self.assertTrue(runfile.is_file()) 33 self.assertEqual(runfile.read_text(), "OK\n") 34 35 def test_compare_runfiles(self): 36 runfile = Path(self.r.Rlocation(*pw_build.test_runfile.RLOCATION)) 37 rules_python_runfile = Path( 38 self.r.Rlocation( 39 "pigweed/pw_build/test_data/test_runfile.txt", 40 self.r.CurrentRepository(), 41 ) 42 ) 43 self.assertTrue(rules_python_runfile.is_file()) 44 self.assertEqual( 45 runfile.read_text(), 46 rules_python_runfile.read_text(), 47 ) 48 49 def test_expected_remapped_runfiles(self): 50 runfile = Path( 51 self.r.Rlocation(*pw_build.another_test_runfile.RLOCATION) 52 ) 53 self.assertTrue(runfile.is_file()) 54 self.assertEqual(runfile.read_text(), "OK\n") 55 56 def test_compare_remapped_runfiles(self): 57 runfile = Path( 58 self.r.Rlocation(*pw_build.another_test_runfile.RLOCATION) 59 ) 60 rules_python_runfile = Path( 61 self.r.Rlocation( 62 "pigweed/pw_build/test_data/test_runfile.txt", 63 self.r.CurrentRepository(), 64 ) 65 ) 66 self.assertTrue(rules_python_runfile.is_file()) 67 self.assertEqual( 68 runfile.read_text(), 69 rules_python_runfile.read_text(), 70 ) 71 72 def test_external_py_resource(self): 73 runfile = Path( 74 self.r.Rlocation( 75 *pw_build_external_runfile_resource.black.RLOCATION 76 ) 77 ) 78 self.assertTrue(runfile.is_file()) 79 80 81if __name__ == '__main__': 82 unittest.main() 83