/ dev / clint / tests / rules / test_subprocess_check_call.py
test_subprocess_check_call.py
 1  from pathlib import Path
 2  
 3  from clint.config import Config
 4  from clint.index import SymbolIndex
 5  from clint.linter import Position, Range, lint_file
 6  from clint.rules import SubprocessCheckCall
 7  
 8  
 9  def test_subprocess_check_call(index: SymbolIndex) -> None:
10      code = """
11  import subprocess
12  
13  # Bad
14  subprocess.run(["echo", "hello"], check=True)
15  
16  # Good - has other kwargs
17  subprocess.run(["echo", "hello"], check=True, text=True)
18  
19  # Good - check_call
20  subprocess.check_call(["echo", "hello"])
21  
22  # Good - no check
23  subprocess.run(["echo", "hello"])
24  """
25      config = Config(select={SubprocessCheckCall.name})
26      results = lint_file(Path("test.py"), code, config, index)
27      assert len(results) == 1
28      assert isinstance(results[0].rule, SubprocessCheckCall)
29      assert results[0].range == Range(Position(4, 0))