1import json 2import os 3import pathlib 4import sys 5import unittest 6 7from python.runfiles import runfiles 8 9 10class PythonToolchainTest(unittest.TestCase): 11 def test_expected_toolchain_matches(self): 12 expect_version = os.environ["EXPECT_PYTHON_VERSION"] 13 14 rf = runfiles.Create() 15 settings_path = rf.Rlocation( 16 "rules_python/tests/support/current_build_settings.json" 17 ) 18 settings = json.loads(pathlib.Path(settings_path).read_text()) 19 20 expected = "python_{}".format(expect_version.replace(".", "_")) 21 self.assertIn(expected, settings["toolchain_label"], str(settings)) 22 23 actual = "{v.major}.{v.minor}.{v.micro}".format(v=sys.version_info) 24 self.assertEqual(actual, expect_version) 25 26 27if __name__ == "__main__": 28 unittest.main() 29