Affected files: .obsidian/workspace 03. Programming/COM/20210726 - COM Interface.md 03. Programming/DB/MySQL.md 03. Programming/DB/sqlite.md 03. Programming/Design Pattern.md 03. Programming/FFMPEG/00. Introduction.md 03. Programming/FFMPEG/01. Setup.md 03. Programming/FFMPEG/FFMpeg.md 03. Programming/Flask.md 03. Programming/Media Foundation/20210604 - Windows media foundation.md 03. Programming/OpenCV.md 03. Programming/OpenGL.md 03. Programming/Python/argparse.ArgumentParser.md 03. Programming/Python/decorator.md 03. Programming/Python/logging.md 03. Programming/Python/opencv.md 03. Programming/Python/subprocess.md 03. Programming/Python/threading.md 03. Programming/Python/tkinter.md 03. Programming/Python/檢測工具.md 03. Programming/QT/Dropdown button.md 03. Programming/QT/QVariant.md 03. Programming/QT/Qt.md 03. Programming/UML.md 03. Programming/演算法.md 04. 資料收集/99. templates/blogHeader.md 04. 資料收集/99. templates/date.md 04. 資料收集/99. templates/front matter.md 04. 資料收集/99. templates/note.md 04. 資料收集/99. templates/table.md 04. 資料收集/99. templates/thisWeek.md 04. 資料收集/99. templates/日記.md 04. 資料收集/99. templates/讀書筆記.md 04. 資料收集/Linux/CLI/cut.md 04. 資料收集/Linux/CLI/scp.md 04. 資料收集/Linux/CLI/timedatectl.md 04. 資料收集/Linux/Programming.md 04. 資料收集/Linux/Ubuntu.md 04. 資料收集/Tool Setup/Hardware/RaspberryPi.md 04. 資料收集/Tool Setup/Software/Chrome.md 04. 資料收集/Tool Setup/Software/Obisidian.md 04. 資料收集/Tool Setup/Software/SublimeText.md 04. 資料收集/Tool Setup/Software/VirtualBox.md 04. 資料收集/Tool Setup/Software/Visual Studio Code.md 04. 資料收集/Tool Setup/Software/Windows Setup.md 04. 資料收集/Tool Setup/Software/Windows Terminal.md 04. 資料收集/Tool Setup/Software/freefilesync.md 04. 資料收集/Tool Setup/Software/vim.md 04. 資料收集/名言佳句.md 04. 資料收集/架站/Gitea.md 04. 資料收集/架站/HTTP Server/Apache.md 04. 資料收集/架站/HTTP Server/Nginx/Reverse Proxy(Layer4).md 04. 資料收集/架站/Pelican blog.md 04. 資料收集/架站/Proxmox VE.md 04. 資料收集/架站/SWAG Reverse proxy.md 04. 資料收集/架站/Storj.md 04. 資料收集/架站/Trojan.md 04. 資料收集/每週外食.md 04. 資料收集/科技/802.11.md 04. 資料收集/科技/HDR Sensor.md 04. 資料收集/科技/量子電腦.md 04. 資料收集/科技/鋰電池.md 04. 資料收集/興趣嗜好/RC/Traxxas Sledge.md 04. 資料收集/興趣嗜好/RC/好盈電變調整中立點.md 04. 資料收集/興趣嗜好/RC/差速器調教教學.md 04. 資料收集/興趣嗜好/模型/舊化作例.md 04. 資料收集/興趣嗜好/軍武/虎式.md 04. 資料收集/讀書筆記/20201201 - 學習如何學習.md 04. 資料收集/讀書筆記/20201218 - Kotlin權威2.0.md 04. 資料收集/讀書筆記/20201224 - 寫作是最好的自我投資.md 04. 資料收集/讀書筆記/20210119 - 中產悲歌.md 04. 資料收集/讀書筆記/20210220 - 最高學習法.md 04. 資料收集/讀書筆記/20210320 - 最高學以致用法.md 04. 資料收集/讀書筆記/20210406 - 精準購買.md 04. 資料收集/讀書筆記/20210723 - 高手學習.md 04. 資料收集/讀書筆記/20220526 - 深入淺出設計模式.md 04. 資料收集/讀書筆記/20220619 - 精確的力量.md 04. 資料收集/軟體工具/IPFS.md 04. 資料收集/軟體工具/MkDocs.md 04. 資料收集/軟體工具/Obsidian.md 04. 資料收集/軟體工具/docker.md 04. 資料收集/軟體工具/git/apply.md 04. 資料收集/軟體工具/git/submodule.md 04. 資料收集/軟體工具/youtube-dl.md 04. 資料收集/面試準備/技术面试最后反问面试官的话.md
96 lines
3.1 KiB
Markdown
96 lines
3.1 KiB
Markdown
## 單元測試
|
||
### [pytest](https://docs.pytest.org/en/7.1.x/)
|
||
Pytest 不僅可以幫助我們運行測試,還可以幫助我們配置如何運行它們、運行哪些文件等等……Pytest 有一個配置文件 `pytest.ini`,您可以在其中描述它的配置,例如哪個版本應該是 Pytest 或者哪些是測試文件,例如下列。
|
||
```ini
|
||
# pytet.ini
|
||
[pytest]
|
||
minversion = 6.0
|
||
addopts = -ra -q — cov=src — cov-report=html
|
||
python_files = test_*.py
|
||
```
|
||
|
||
### [tox](https://tox.wiki/en/latest/)
|
||
Tox 是一個通用的virtualenv管理和測試命令行工具。
|
||
使用不同的 Python 版本和解釋器檢查您的包是否正確安裝
|
||
在每個環境中運行您的測試,配置您選擇的測試工具
|
||
作為持續集成服務器的前端,大大減少樣板文件並合併 CI 和基於 shell 的測試。
|
||
Tox 也有它的配置文件。
|
||
```ini
|
||
[tox]
|
||
isolated_build = True
|
||
envlist = py{38}
|
||
|
||
[testenv]
|
||
usedevelop = true
|
||
deps = -r src/requirements_dev.txt
|
||
```
|
||
|
||
|
||
## 程式檢查工具
|
||
用來檢查程式是否符合coding style、PEP8之類的規範
|
||
### [pylint](https://github.com/PyCQA/pylint)
|
||
Pylint config: create `.pylintrc` file
|
||
```
|
||
[MESSAGES CONTROL]
|
||
disable=
|
||
missing-docstring,
|
||
too-few-public-methods[REPORTS]
|
||
output-format=colorized
|
||
files-output=no
|
||
reports=no
|
||
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
|
||
```
|
||
|
||
### [flake8](https://github.com/pycqa/flake8)
|
||
Flake8 config: create `.flake8` file
|
||
```
|
||
[flake8]
|
||
ignore = E203, E266, E501, W503, F403, F401, E402
|
||
max-line-length = 120
|
||
max-complexity = 18
|
||
select = B,C,E,F,W,T4,B9
|
||
exclude =
|
||
.git,
|
||
tests
|
||
```
|
||
|
||
### [mypy](http://www.mypy-lang.org/)
|
||
|
||
## Git hook
|
||
### pre-commit
|
||
Pre-commit 是一個創建 git hook的framework,以確保您的代碼編寫與您定義的代碼樣式相對應。
|
||
它會掃描您的原始碼並運行您將在預提交配置文件中定義的所有檢查器:`.pre-commit-config.yaml`
|
||
```
|
||
repos:
|
||
- repo: 'https://gitlab.com/pycqa/flake8'
|
||
rev: 3.8.2
|
||
hooks:
|
||
- id: flake8
|
||
name: Style Guide Enforcement (flake8)
|
||
args:
|
||
- '--max-line-length=120'
|
||
- repo: 'https://github.com/pre-commit/mirrors-mypy'
|
||
rev: v0.720
|
||
hooks:
|
||
- id: mypy
|
||
name: Optional Static Typing for Python (mypy)
|
||
```
|
||
|
||
## 漏洞檢查
|
||
### [SonarQube](https://www.sonarqube.org/)
|
||
有很多用於漏洞掃描的工具,但我們將看看[Sonarqube](https://www.sonarqube.org/)。Sonarqube 是用於代碼質量和安全掃描的開源強大工具,是該行業的領先工具之一。
|
||
更多在[官方文檔](https://docs.sonarqube.org/latest/)中。
|
||
您可以使用 Docker 映像設置本地 Sonarqube 服務器並定義`sonar-project.properties`
|
||
```
|
||
# must be unique in a given SonarQube instance
|
||
sonar.projectKey=python_app_blueprint
|
||
# --- optional properties ---
|
||
# defaults to project key
|
||
#sonar.projectName=My project
|
||
# defaults to 'not provided'
|
||
#sonar.projectVersion=1.0
|
||
# Path is relative to the sonar-project.properties file. Defaults to .
|
||
#sonar.sources=.
|
||
# Encoding of the source code. Default is default system encoding
|
||
#sonar.sourceEncoding=UTF-8
|
||
``` |