-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsetup_python3.py
More file actions
77 lines (60 loc) · 1.8 KB
/
setup_python3.py
File metadata and controls
77 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
setup for the tests of the module string_to_python
"""
import general_utilities as gu
from string_to_code import to_python3
def get_python_interpreter():
"""returns the name of the python interpreter"""
return "python3"
def get_pylint():
"""returns the name of pylint"""
return "pylint"
def get_flake8():
"""returns the name of flake8"""
return "flake8"
def _get_source_code_file_extension():
return "py"
def run_python_code(in_code, tmp_folder):
"""
Runs the python code in_code.
Returns the output of the program.
"""
source_filename = gu.get_unique_filename(
tmp_folder, _get_source_code_file_extension()
)
gu.save_str_to_file(tmp_folder / source_filename, in_code)
gu.subprocess_run_with_check(
[
get_pylint(),
source_filename,
"--disable=missing-module-docstring,"
"missing-function-docstring,"
"too-many-lines",
],
cwd=str(tmp_folder),
capture_output=True,
text=True,
)
gu.subprocess_run_with_check(
[get_flake8(), source_filename, "--count"],
cwd=str(tmp_folder),
capture_output=True,
text=True,
)
res = gu.subprocess_run_with_check(
[get_python_interpreter(), source_filename],
cwd=str(tmp_folder),
capture_output=True,
text=True,
)
return res
def get_test_data():
"""returns test data for the module string_to_python"""
return gu.Language(
tool_names=[get_python_interpreter(), get_pylint(), get_flake8()],
string_to_code=to_python3.proc,
printer_program_to_code=to_python3.proc_printer_program,
run_code=run_python_code,
id="python3",
source_code_file_extension=_get_source_code_file_extension(),
)