Skip to content

Commit d182ecc

Browse files
committed
feat(ci): add github action unit_test
1 parent d36d1c1 commit d182ecc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+219
-125
lines changed

.github/workflows/unit_test.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
pull_request:
8+
branches:
9+
- 'main'
10+
11+
jobs:
12+
test:
13+
if: ${{ !(github.event_name == 'pull_request' && startsWith(github.event.pull_request.title, 'docs:')) }}
14+
15+
runs-on: ${{ matrix.os }}
16+
strategy:
17+
matrix:
18+
os: [ ubuntu-latest ]
19+
python-version: [ '3.8' ]
20+
21+
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Cache pip dependencies
32+
uses: actions/cache@v4
33+
with:
34+
path: ~/.cache/pip
35+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
36+
restore-keys: |
37+
${{ runner.os }}-pip-
38+
39+
- name: Update setuptools
40+
run: |
41+
pip install --upgrade pip
42+
pip install setuptools==78.1.1 wheel==0.45.1
43+
44+
- name: Set PYTHONPATH
45+
run: |
46+
echo "PYTHONPATH=$PYTHONPATH:${{ github.workspace }}/src" >> $GITHUB_ENV
47+
48+
- name: Install dependencies
49+
run: |
50+
export PIP_DEFAULT_TIMEOUT=300
51+
pip install -r requirements.txt
52+
pip install -r requirements-test.txt
53+
54+
- name: Show installed pip packages (versions)
55+
run: |
56+
python -m pip list --format=columns
57+
58+
- name: Run tests with coverage
59+
run: |
60+
coverage run -m pytest tests/unit
61+
62+
- name: Generate coverage report
63+
run: |
64+
coverage report -m

.pre-commit-config.yaml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@ repos:
33
rev: v4.3.0
44
hooks:
55
- id: check-ast
6-
exclude: ^(tests|samples)/
6+
exclude: ^(tests/legacy|samples)/
77
- id: sort-simple-yaml
8-
exclude: ^(tests|samples)/
8+
exclude: ^(tests/legacy|samples)/
99
- id: check-yaml
1010
exclude: |
1111
(?x)^(
1212
meta.yaml
13-
| tests/
13+
| tests/legacy/
1414
| samples/
1515
)$
1616
- id: check-xml
17-
exclude: ^(tests|samples)/
17+
exclude: ^(tests/legacy|samples)/
1818
- id: check-toml
19-
exclude: ^(tests|samples)/
19+
exclude: ^(tests/legacy|samples)/
2020
- id: check-docstring-first
21-
exclude: ^(tests|samples)/
21+
exclude: ^(tests/legacy|samples)/
2222
- id: check-json
23-
exclude: ^(tests|samples)/
23+
exclude: ^(tests/legacy|samples)/
2424
- id: fix-encoding-pragma
25-
exclude: ^(tests|samples)/
25+
exclude: ^(tests/legacy|samples)/
2626
- id: detect-private-key
27-
exclude: ^(tests|samples)/
27+
exclude: ^(tests/legacy|samples)/
2828
- id: trailing-whitespace
29-
exclude: ^(tests|samples)/
29+
exclude: ^(tests/legacy|samples)/
3030
- repo: https://github.com/asottile/add-trailing-comma
3131
rev: v3.1.0
3232
hooks:
3333
- id: add-trailing-comma
34-
exclude: ^(tests|samples)/
34+
exclude: ^(tests/legacy|samples)/
3535
- repo: https://github.com/pre-commit/mirrors-mypy
3636
rev: v1.7.0
3737
hooks:
@@ -41,7 +41,7 @@ repos:
4141
pb2\.py$
4242
| grpc\.py$
4343
| ^docs
44-
| ^tests/
44+
| ^tests/legacy/
4545
| ^samples/
4646
| \.html$
4747
)
@@ -61,21 +61,21 @@ repos:
6161
hooks:
6262
- id: black
6363
args: [ --line-length=79 ]
64-
exclude: ^(tests|samples)/
64+
exclude: ^(tests/legacy|samples)/
6565
- repo: https://github.com/PyCQA/flake8
6666
rev: 6.1.0
6767
hooks:
6868
- id: flake8
6969
args: [ "--extend-ignore=E203"]
70-
exclude: ^(tests|samples)/
70+
exclude: ^(tests/legacy|samples)/
7171
- repo: https://github.com/pylint-dev/pylint
7272
rev: v3.0.2
7373
hooks:
7474
- id: pylint
7575
exclude:
7676
(?x)(
7777
^docs
78-
| ^tests/
78+
| ^tests/legacy/
7979
| ^samples/
8080
| pb2\.py$
8181
| grpc\.py$
@@ -122,19 +122,19 @@ repos:
122122
hooks:
123123
- id: eslint
124124
files: \.(js|jsx)$
125-
exclude: '(.*js_third_party.*|^tests/|^samples/)'
125+
exclude: '(.*js_third_party.*|^tests/legacy/|^samples/)'
126126
args: [ '--fix' ]
127127
- repo: https://github.com/thibaudcolas/pre-commit-stylelint
128128
rev: v14.4.0
129129
hooks:
130130
- id: stylelint
131131
files: \.(css)$
132-
exclude: '(.*css_third_party.*|^tests/|^samples/)'
132+
exclude: '(.*css_third_party.*|^tests/legacy/|^samples/)'
133133
args: [ '--fix' ]
134134
- repo: https://github.com/pre-commit/mirrors-prettier
135135
rev: 'v3.0.0'
136136
hooks:
137137
- id: prettier
138138
additional_dependencies: [ 'prettier@3.0.0' ]
139139
files: \.(tsx?)$
140-
exclude: ^(tests|samples)/
140+
exclude: ^(tests/legacy|samples)/
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
from http import HTTPStatus
66

77
from dashscope import Generation
8-
from tests.http_task_request import HttpRequest
9-
from tests.mock_request_base import MockServerBase
10-
from tests.mock_server import MockServer
8+
from tests.unit.http_task_request import HttpRequest
9+
from tests.unit.mock_request_base import MockServerBase
10+
from tests.unit.mock_server import MockServer
1111

1212
model = Generation.Models.qwen_turbo
1313

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
from dashscope import Application
1313
from dashscope.app.application_response import ApplicationResponse
14-
from tests.mock_request_base import MockServerBase
15-
from tests.mock_server import MockServer
14+
from tests.unit.mock_request_base import MockServerBase
15+
from tests.unit.mock_server import MockServer
1616

1717

1818
class TestCompletion(MockServerBase):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
import dashscope
1313
from dashscope.audio.asr import AsrPhraseManager
14-
from tests.constants import TEST_JOB_ID
15-
from tests.mock_request_base import MockRequestBase
14+
from tests.unit.constants import TEST_JOB_ID
15+
from tests.unit.mock_request_base import MockRequestBase
1616

1717
logger = logging.getLogger("dashscope")
1818
logger.setLevel(logging.DEBUG)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import uuid
66

77
from dashscope.assistants.files import Files
8-
from tests.mock_request_base import MockServerBase
9-
from tests.mock_server import MockServer
8+
from tests.unit.mock_request_base import MockServerBase
9+
from tests.unit.mock_server import MockServer
1010

1111

1212
class TestAssistantFiles(MockServerBase):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import uuid
66

77
from dashscope import Assistants
8-
from tests.mock_request_base import MockServerBase
9-
from tests.mock_server import MockServer
8+
from tests.unit.mock_request_base import MockServerBase
9+
from tests.unit.mock_server import MockServer
1010

1111

1212
class TestAssistants(MockServerBase):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from dashscope.api_entities.dashscope_response import DashScopeAPIResponse
88
from dashscope.client.base_api import BaseAsyncApi
99
from dashscope.common.constants import ApiProtocol, HTTPMethod, TaskStatus
10-
from tests.base_test import BaseTestEnvironment
10+
from tests.unit.base_test import BaseTestEnvironment
1111

1212

1313
class AsyncRequest(BaseAsyncApi):
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
AttachmentRoleMessageParam,
1010
UserRoleMessageParam,
1111
)
12-
from tests.mock_request_base import MockServerBase
13-
from tests.mock_server import MockServer
12+
from tests.unit.mock_request_base import MockServerBase
13+
from tests.unit.mock_server import MockServer
1414

1515
model = CodeGeneration.Models.tongyi_lingma_v1
1616

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
from dashscope.aigc.conversation import Conversation, History, HistoryItem
99
from dashscope.api_entities.dashscope_response import Choice, Message, Role
1010
from dashscope.common.message_manager import MessageManager
11-
from tests.mock_request_base import MockServerBase
12-
from tests.mock_server import MockServer
11+
from tests.unit.mock_request_base import MockServerBase
12+
from tests.unit.mock_server import MockServer
1313

1414

1515
def request_generator():

0 commit comments

Comments
 (0)