11"""Various checks you may want to run during submission tests"""
2+
23import os
34import subprocess
45from pathlib import Path
1213_ENV_VAL_TRUE = "1"
1314_ENV_VAL_FALSE = "0"
1415
16+
1517def contains_flag (flag : str , python_script : Path , silent : bool = False ) -> bool :
1618 """
1719 Run submitted file and match whether it contains the flag value.
@@ -32,15 +34,18 @@ def run_pylint(python_files: List[Path]) -> bool:
3234 """
3335 Run pylint with custom config on user code (only interesting if submission contains .py files)
3436 """
35- if not python_files or os .environ .get (_NO_LINT_ENV_VAR , '' ) == _ENV_VAL_TRUE :
37+ if not python_files or os .environ .get (_NO_LINT_ENV_VAR , "" ) == _ENV_VAL_TRUE :
3638 return SUCCESS
37- result = run (["pylint" , "--exit-zero" , "--rcfile" , str (get_config ().pylint_config_path )] +
38- [str (f .resolve ()) for f in python_files ],
39- stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
39+ result = run (
40+ ["pylint" , "--exit-zero" , "--rcfile" , str (get_config ().pylint_config_path )]
41+ + [str (f .resolve ()) for f in python_files ],
42+ stdout = subprocess .PIPE ,
43+ stderr = subprocess .STDOUT ,
44+ )
4045 lint_output = result .stdout .decode () if result .stdout else ""
4146 if lint_output != "" :
4247 print_warn ("[!] pylint's syntax and coding style checks failed:" )
43- print_warn (' ' + ' \n ' .join (lint_output .split (' \n ' )))
48+ print_warn (" " + " \n " .join (lint_output .split (" \n " )))
4449 return FAILURE
4550 print_ok ("[+] pylint's syntax and coding style checks passed" )
4651 return SUCCESS
@@ -50,15 +55,15 @@ def run_mypy(python_files: List[Path]) -> bool:
5055 """
5156 Run mypy with custom config on user code (only interesting if submission contains typed .py files)
5257 """
53- if not python_files or os .environ .get (_NO_LINT_ENV_VAR , '' ) == _ENV_VAL_TRUE :
58+ if not python_files or os .environ .get (_NO_LINT_ENV_VAR , "" ) == _ENV_VAL_TRUE :
5459 return SUCCESS
5560 cmd = ["mypy" , "--config-file" , str (get_config ().mypy_config_path )]
5661 cmd += [str (f .resolve ()) for f in python_files ]
5762 result = run (cmd , stdout = subprocess .PIPE , stderr = subprocess .STDOUT )
5863 lint_output = result .stdout .decode () if result .stdout else ""
5964 if lint_output != "" :
6065 print_warn ("[!] mypy's type checks failed:" )
61- print_warn (' ' + ' \n ' .join (lint_output .split (' \n ' )))
66+ print_warn (" " + " \n " .join (lint_output .split (" \n " )))
6267 return FAILURE
6368 print_ok ("[+] mypy's type checks passed" )
6469 return SUCCESS
@@ -70,9 +75,9 @@ def check_all_python_files() -> bool:
7075 """
7176 tests_passed = True
7277 python_files = [f for f in get_config ().user_home_path .glob ("**/*.py" ) if not f .name .startswith ("." )]
73- if not python_files or os .environ .get (_NO_LINT_ENV_VAR , '' ) == _ENV_VAL_TRUE :
78+ if not python_files or os .environ .get (_NO_LINT_ENV_VAR , "" ) == _ENV_VAL_TRUE :
7479 return tests_passed
75- print_ok (f' [+] Testing { len (python_files )} Python source code files' )
80+ print_ok (f" [+] Testing { len (python_files )} Python source code files" )
7681 tests_passed &= run_pylint (python_files )
7782 tests_passed &= run_mypy (python_files )
7883 return tests_passed
0 commit comments