1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from libcst._parser.grammar import _should_include
from libcst._parser.parso.utils import PythonVersionInfo
from libcst.testing.utils import data_provider, UnitTest
class VersionCompareTest(UnitTest):
@data_provider(
(
# Simple equality
("==3.6", PythonVersionInfo(3, 6), True),
("!=3.6", PythonVersionInfo(3, 6), False),
# Equal or GT/LT
(">=3.6", PythonVersionInfo(3, 5), False),
(">=3.6", PythonVersionInfo(3, 6), True),
(">=3.6", PythonVersionInfo(3, 7), True),
("<=3.6", PythonVersionInfo(3, 5), True),
("<=3.6", PythonVersionInfo(3, 6), True),
("<=3.6", PythonVersionInfo(3, 7), False),
# GT/LT
(">3.6", PythonVersionInfo(3, 5), False),
(">3.6", PythonVersionInfo(3, 6), False),
(">3.6", PythonVersionInfo(3, 7), True),
("<3.6", PythonVersionInfo(3, 5), True),
("<3.6", PythonVersionInfo(3, 6), False),
("<3.6", PythonVersionInfo(3, 7), False),
# Multiple checks
(">3.6,<3.8", PythonVersionInfo(3, 6), False),
(">3.6,<3.8", PythonVersionInfo(3, 7), True),
(">3.6,<3.8", PythonVersionInfo(3, 8), False),
)
)
def test_tokenize(
self,
requested_version: str,
actual_version: PythonVersionInfo,
expected_result: bool,
) -> None:
self.assertEqual(
_should_include(requested_version, actual_version), expected_result
)
|