File: conftest.py

package info (click to toggle)
flake8-cognitive-complexity 0.1.0-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 116 kB
  • sloc: python: 116; makefile: 7; sh: 5
file content (24 lines) | stat: -rw-r--r-- 705 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import ast
import os

from flake8_cognitive_complexity.checker import CognitiveComplexityChecker


def run_validator_for_test_file(
    filename: str,
    max_cognitive_complexity: int = None,
    ignore_django_orm_queries: bool = True,
):
    test_file_path = os.path.join(
        os.path.dirname(os.path.abspath(__file__)),
        'test_files',
        filename,
    )
    with open(test_file_path, 'r') as file_handler:
        raw_content = file_handler.read()
    tree = ast.parse(raw_content)
    checker = CognitiveComplexityChecker(tree=tree, filename=filename)
    if max_cognitive_complexity:
        checker.max_cognitive_complexity = max_cognitive_complexity

    return list(checker.run())