/ dev / clint / tests / rules / test_version_major_check.py
test_version_major_check.py
 1  from pathlib import Path
 2  
 3  from clint.config import Config
 4  from clint.index import SymbolIndex
 5  from clint.linter import lint_file
 6  from clint.rules.version_major_check import MajorVersionCheck
 7  
 8  
 9  def test_version_major_check(index: SymbolIndex) -> None:
10      code = """
11  from packaging.version import Version
12  
13  Version("0.9.0") >= Version("1.0.0")
14  Version("1.2.3").major >= 1
15  Version("1.0.0") >= Version("0.83.0")
16  Version("1.5.0") >= Version("2.0.0")
17  Version("1.5.0") == Version("3.0.0")
18  Version("1.5.0") != Version("4.0.0")
19  """
20      config = Config(select={MajorVersionCheck.name})
21      violations = lint_file(Path("test.py"), code, config, index)
22      assert len(violations) == 4
23      assert all(isinstance(v.rule, MajorVersionCheck) for v in violations)
24      assert violations[0].range.start.line == 3
25      assert violations[1].range.start.line == 6
26      assert violations[2].range.start.line == 7
27      assert violations[3].range.start.line == 8
28  
29  
30  def test_version_major_check_no_violations(index: SymbolIndex) -> None:
31      code = """
32  from packaging.version import Version
33  
34  Version("1.2.3").major >= 1
35  Version("1.0.0") >= Version("0.83.0")
36  Version("1.5.0") >= Version("1.0.1")
37  Version("1.5.0") >= Version("1.0.0.dev0")
38  5 >= 3
39  """
40      config = Config(select={MajorVersionCheck.name})
41      violations = lint_file(Path("test.py"), code, config, index)
42      assert len(violations) == 0