File: test_version_compare.py

package info (click to toggle)
python-libcst 1.4.0-1.2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,928 kB
  • sloc: python: 76,235; makefile: 10; sh: 2
file content (45 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download
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
        )