Skip to content

Commit 184c57c

Browse files
authored
Feat/unit test (#438)
* refactor structure
1 parent 14c6567 commit 184c57c

File tree

11 files changed

+80
-234
lines changed

11 files changed

+80
-234
lines changed

.gitignore

Lines changed: 7 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -7,175 +7,17 @@ vue/components.d.ts
77
vue/auto-imports.d.ts
88
swanlog/
99
swanlog.bak/
10-
logs/
1110
.eslintrc-auto-import.json
12-
13-
# Byte-compiled / optimized / DLL files
14-
__pycache__/
15-
*.py[cod]
16-
*$py.class
17-
.swanlab/
18-
test/*
19-
!test/db/
20-
!test/_server.py
21-
!test/load.yaml
22-
!test/config.json
23-
24-
# C extensions
25-
*.so
26-
27-
# Distribution / packaging
28-
.Python
29-
wandb
30-
build/
31-
develop-eggs/
3211
dist/
33-
downloads/
34-
eggs/
35-
.eggs/
36-
lib/
37-
lib64/
38-
parts/
39-
sdist/
40-
var/
41-
wheels/
42-
share/python-wheels/
43-
*.egg-info/
44-
.installed.cfg
45-
*.egg
46-
MANIFEST
47-
48-
# PyInstaller
49-
# Usually these files are written by a python script from a template
50-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
51-
*.manifest
52-
*.spec
53-
54-
# Installer logs
55-
pip-log.txt
56-
pip-delete-this-directory.txt
57-
58-
# Unit test / coverage reports
59-
htmlcov/
60-
.tox/
61-
.nox/
62-
.coverage
63-
.coverage.*
64-
.cache
65-
nosetests.xml
66-
coverage.xml
67-
*.cover
68-
*.py,cover
69-
.hypothesis/
70-
.pytest_cache/
71-
cover/
72-
!unit
73-
unit/temp
74-
75-
# Translations
76-
*.mo
77-
*.pot
78-
79-
# Django stuff:
80-
*.log
81-
local_settings.py
82-
db.sqlite3
83-
db.sqlite3-journal
84-
85-
# Flask stuff:
86-
instance/
87-
.webassets-cache
88-
89-
# Scrapy stuff:
90-
.scrapy
91-
92-
# Sphinx documentation
93-
docs/_build/
94-
95-
# PyBuilder
96-
.pybuilder/
97-
target/
98-
99-
# Jupyter Notebook
100-
.ipynb_checkpoints
101-
102-
# IPython
103-
profile_default/
104-
ipython_config.py
10512

106-
# pyenv
107-
# For a library or package, you might want to ignore these files since the code is
108-
# intended to run in multiple environments; otherwise, check them in:
109-
# .python-version
13+
# playground
14+
playground/
11015

111-
# pipenv
112-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
113-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
114-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
115-
# install all needed dependencies.
116-
#Pipfile.lock
11716

118-
# poetry
119-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
120-
# This is especially recommended for binary packages to ensure reproducibility, and is more
121-
# commonly ignored for libraries.
122-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
123-
#poetry.lock
124-
125-
# pdm
126-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
127-
#pdm.lock
128-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
129-
# in version control.
130-
# https://pdm.fming.dev/#use-with-ide
131-
.pdm.toml
132-
133-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
134-
__pypackages__/
135-
136-
# Celery stuff
137-
celerybeat-schedule
138-
celerybeat.pid
139-
140-
# SageMath parsed files
141-
*.sage.py
142-
143-
# Environments
144-
.venv
145-
env/
146-
venv/
147-
ENV/
148-
env.bak/
149-
venv.bak/
150-
151-
# Spyder project settings
152-
.spyderproject
153-
.spyproject
154-
155-
# Rope project settings
156-
.ropeproject
157-
158-
# mkdocs documentation
159-
/site
160-
161-
# mypy
162-
.mypy_cache/
163-
.dmypy.json
164-
dmypy.json
165-
166-
# Pyre type checker
167-
.pyre/
168-
169-
# pytype static type analyzer
170-
.pytype/
171-
172-
# Cython debug symbols
173-
cython_debug/
174-
175-
# PyCharm
176-
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
177-
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
178-
# and can be added to the global gitignore or merged into this file. For a more nuclear
179-
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
17+
# Jetbrains
18018
.idea/
18119
.DS_Store
20+
21+
# python
22+
__pycache__
23+
.pytest_cache/

.vscode/launch.json

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,52 +25,45 @@
2525
//sys.path 会加入顶层目录,影响模块导入查询路径
2626
"env": { "PYTHONPATH": "${workspaceFolder}" }
2727
},
28-
// 开发调试
28+
// 模拟实验开启
2929
{
30-
"name": "开发调试",
30+
"name": "开启一个实验",
3131
"type": "debugpy",
3232
"request": "launch",
33-
"program": "${workspaceFolder}/test/test_create_experiment.py",
33+
"program": "${workspaceFolder}/test/create_experiment.py",
3434
"console": "integratedTerminal",
3535
"justMyCode": true,
3636
"cwd": "${workspaceFolder}",
3737
//sys.path 会加入顶层目录,影响模块导入查询路径
3838
"env": { "PYTHONPATH": "${workspaceFolder}" }
3939
},
40-
// 模拟实验开启
40+
// python运行当前文件
4141
{
42-
"name": "开启一个实验",
42+
"name": "运行当前文件",
4343
"type": "debugpy",
4444
"request": "launch",
45-
"program": "${workspaceFolder}/test/create_experiment.py",
45+
"program": "${file}",
4646
"console": "integratedTerminal",
4747
"justMyCode": true,
4848
"cwd": "${workspaceFolder}",
4949
//sys.path 会加入顶层目录,影响模块导入查询路径
5050
"env": { "PYTHONPATH": "${workspaceFolder}" }
5151
},
5252
{
53-
"name": "模拟命令行watch",
53+
"name": "测试当前文件",
5454
"type": "debugpy",
5555
"request": "launch",
56-
"program": "${workspaceFolder}/test/cli_test.py",
57-
"console": "integratedTerminal",
58-
"justMyCode": true,
59-
"cwd": "${workspaceFolder}",
60-
//sys.path 会加入顶层目录,影响模块导入查询路径
61-
"env": { "PYTHONPATH": "${workspaceFolder}" }
56+
"module": "pytest",
57+
"args": ["${file}"],
58+
"console": "integratedTerminal"
6259
},
63-
// python运行当前文件
6460
{
65-
"name": "Python运行当前文件",
61+
"name": "进行所有单元测试",
6662
"type": "debugpy",
6763
"request": "launch",
68-
"program": "${file}",
69-
"console": "integratedTerminal",
70-
"justMyCode": true,
71-
"cwd": "${workspaceFolder}",
72-
//sys.path 会加入顶层目录,影响模块导入查询路径
73-
"env": { "PYTHONPATH": "${workspaceFolder}" }
64+
"module": "pytest",
65+
"args": ["test/unit"],
66+
"console": "integratedTerminal"
7467
},
7568
// 打包命令
7669
{

.vscode/settings.json

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,6 @@
8989

9090
/** tailwind */
9191
"css.customData": [".vscode/tailwind.json"],
92-
/** 不显示__pycache__文件夹 */
93-
"files.exclude": {
94-
"**/.git": true,
95-
"**/.svn": true,
96-
"**/.hg": true,
97-
"**/CVS": true,
98-
"**/.DS_Store": true,
99-
"**/Thumbs.db": true,
100-
"**/__pycache__": true
101-
},
10292
/** python代码注释 */
10393
"autoDocstring.docstringFormat": "numpy",
10494

@@ -109,8 +99,18 @@
10999
// 允许首行不是level1标题
110100
"MD041": false
111101
},
112-
"vue-i18n.i18nPaths": "vue/src/i18n"
113102

114-
// /** SQLite */
115-
// "sqlite.databaseExtensions": ["db", "db3", "sdb", "s3db", "sqlite", "sqlite3", "swanlab"]
103+
/** 不显示文件夹 */
104+
"files.exclude": {
105+
"**/.git": true,
106+
"**/.svn": true,
107+
"**/.hg": true,
108+
"**/CVS": true,
109+
"**/.DS_Store": true,
110+
"**/Thumbs.db": true,
111+
"**/__pycache__": true,
112+
".idea": true
113+
},
114+
"python.testing.unittestEnabled": false,
115+
"python.testing.pytestEnabled": true
116116
}

pytest.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
python_files = pytest_*

test/_server.py

Lines changed: 0 additions & 12 deletions
This file was deleted.

test/cli_test.py

Lines changed: 0 additions & 20 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

test/create_experiment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
swanlab.init(
2121
description="这是一个测试实验",
2222
log_level="debug",
23-
config="test/config.json",
24-
load="test/load.yaml",
23+
config="test/config/config.json",
24+
load="test/config/load.yaml",
2525
# cloud=True,
2626
)
2727
swanlab.config.epoches = epochs

test/start_server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,15 @@
1010
增加了实际开发中不会用到的热启动功能
1111
"""
1212
import uvicorn
13+
from swanlab.db import connect
14+
from swanlab.server.app import app
15+
16+
connect()
17+
18+
19+
def main():
20+
return app
1321

1422

1523
if __name__ == "__main__":
16-
uvicorn.run("_server:main", host="0.0.0.0", port=6092, reload=True, log_level="critical")
24+
uvicorn.run("start_server:main", host="0.0.0.0", port=6092, reload=True, log_level="critical")

0 commit comments

Comments
 (0)