Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9import subprocess 

10import sys 

11import unittest 

12 

13from pathlib import Path 

14import pytest 

15 

16import tsfpga 

17from tsfpga.git_utils import find_git_files 

18from tsfpga.system_utils import create_file 

19 

20 

21THIS_DIR = Path(__file__).parent 

22 

23 

24def _files_to_check(): 

25 # Exclude doc folder, since conf.py used by sphinx does not conform 

26 return [ 

27 str(path) 

28 for path in find_git_files( 

29 directory=tsfpga.REPO_ROOT, 

30 exclude_directories=[tsfpga.TSFPGA_DOC], 

31 file_endings_include="py", 

32 ) 

33 ] 

34 

35 

36def run_pylint(files): 

37 config = THIS_DIR / "pylintrc" 

38 command = [sys.executable, "-m", "pylint", f"--rcfile={config}"] + files 

39 

40 subprocess.check_call(command) 

41 

42 

43def test_pylint(): 

44 run_pylint(_files_to_check()) 

45 

46 

47def run_black(files): 

48 command = [sys.executable, "-m", "black", "--check"] + files 

49 subprocess.check_call(command, cwd=tsfpga.REPO_ROOT) 

50 

51 

52def test_black_formatting(): 

53 run_black(_files_to_check()) 

54 

55 

56def run_flake8_lint(files): 

57 command = [sys.executable, "-m", "flake8"] + files 

58 subprocess.check_call(command, cwd=tsfpga.REPO_ROOT) 

59 

60 

61def test_flake8_lint(): 

62 run_flake8_lint(_files_to_check()) 

63 

64 

65@pytest.mark.usefixtures("fixture_tmp_path") 

66class TestPythonLintFunctions(unittest.TestCase): 

67 tmp_path = None 

68 

69 def setUp(self): 

70 ugly_code = "aa =\ndef bb:\ncc = 3" 

71 self.file = str(create_file(self.tmp_path / "dummy_python_file.py", ugly_code)) 

72 

73 def test_pylint_should_raise_exception_if_there_are_ugly_files(self): 

74 with pytest.raises(subprocess.CalledProcessError): 

75 run_pylint([self.file]) 

76 

77 def test_flake8_lint_should_raise_exception_if_there_are_ugly_files(self): 

78 with pytest.raises(subprocess.CalledProcessError): 

79 run_flake8_lint([self.file]) 

80 

81 def test_black_formatting_should_raise_exception_if_there_are_ugly_files(self): 

82 with pytest.raises(subprocess.CalledProcessError): 

83 run_black([self.file])