File tree Expand file tree Collapse file tree 4 files changed +36
-24
lines changed Expand file tree Collapse file tree 4 files changed +36
-24
lines changed Original file line number Diff line number Diff line change 22
22
strategy :
23
23
matrix :
24
24
os : [ubuntu-latest, macos-latest, windows-latest]
25
- python-version : ["3.8 ", "3.10 "]
25
+ python-version : ["3.10 ", "3.11 "]
26
26
steps :
27
27
- uses : actions/checkout@v4
28
28
- name : Set up Python ${{ matrix.python-version }}
36
36
- name : Lint with black
37
37
run : |
38
38
black codes/python
39
- - name : Build with py_compile
39
+ - name : Test python code
40
40
run : |
41
- python codes/python/build .py
41
+ python codes/python/test_all .py
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import os
2
+ import glob
3
+ import subprocess
4
+
5
+ env = os .environ .copy ()
6
+ env ["PYTHONIOENCODING" ] = "utf-8"
7
+
8
+ if __name__ == "__main__" :
9
+ # find source code files
10
+ src_paths = sorted (glob .glob ("codes/python/chapter_*/*.py" ))
11
+ errors = []
12
+
13
+ # run python code
14
+ for src_path in src_paths :
15
+ process = subprocess .Popen (
16
+ ["python" , src_path ],
17
+ stdout = subprocess .PIPE ,
18
+ stderr = subprocess .PIPE ,
19
+ text = True ,
20
+ env = env ,
21
+ )
22
+ # Wait for the process to complete, and get the output and error messages
23
+ stdout , stderr = process .communicate ()
24
+ # Check the exit status
25
+ exit_status = process .returncode
26
+ if exit_status != 0 :
27
+ errors .append (stderr )
28
+
29
+ print (f"Tested { len (src_paths )} files" )
30
+ print (f"Found exception in { len (errors )} files" )
31
+ if len (errors ) > 0 :
32
+ raise RuntimeError ("\n \n " .join (errors ))
Original file line number Diff line number Diff line change 17
17
18
18
### Python 环境
19
19
20
- 1 . 下载并安装 [ Miniconda3] ( https://docs.conda.io/en/latest/miniconda.html ) 。
20
+ 1 . 下载并安装 [ Miniconda3] ( https://docs.conda.io/en/latest/miniconda.html ) ,需要 Python 3.10 或更新版本 。
21
21
2 . 在 VSCode 的插件市场中搜索 ` python ` ,安装 Python Extension Pack 。
22
22
3 . (可选)在命令行输入 ` pip install black ` ,安装代码格式化工具。
23
23
You can’t perform that action at this time.
0 commit comments