1# Copyright 2021 The Abseil Authors.
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"""Test that verifies the Python version used in bazel is expected."""
15
16import sys
17from absl import flags
18from absl.testing import absltest
19
20_EXPECTED_VERSION = flags.DEFINE_string(
21    'expected_version',
22    None,
23    'The expected Python SemVer version, '
24    'can be major.minor or major.minor.patch.',
25)
26
27
28class PythonVersionTest(absltest.TestCase):
29
30  def test_version(self):
31    version = _EXPECTED_VERSION.value
32    if not version:
33      self.skipTest(
34          'Skipping version test since --expected_version is not specified')
35    num_parts = len(version.split('.'))
36    self.assertEqual('.'.join(map(str, sys.version_info[:num_parts])), version)
37
38
39if __name__ == '__main__':
40  absltest.main()
41