Skip to content

Commit 27d2d97

Browse files
authored
feat(ci): add github action unit_test (#99)
1 parent d36d1c1 commit 27d2d97

Some content is hidden

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

54 files changed

+230
-128
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==68.2.2 wheel==0.41.2
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)/

dashscope/api_entities/encryption.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
3+
# mypy: disable-error-code="annotation-unchecked"
34
import base64
45
import json
56
import os

dashscope/audio/asr/recognition.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
3+
# mypy: disable-error-code="annotation-unchecked"
34

45
import json
56
import os

dashscope/audio/tts_v2/speech_synthesizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
3+
# mypy: disable-error-code="annotation-unchecked"
34

45
import json
56
import platform

dashscope/multimodal/multimodal_request_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# -*- coding: utf-8 -*-
2+
# mypy: disable-error-code="annotation-unchecked"
23
from dataclasses import dataclass, field
34
import uuid
45

dashscope/tokenizers/qwen_tokenizer.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: utf-8 -*-
22
# Copyright (c) Alibaba, Inc. and its affiliates.
3+
# mypy: disable-error-code="annotation-unchecked"
34

45
import base64
56
import unicodedata

requirements-test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ pytest>=7
55
pytest-aiohttp
66
pytest-asyncio
77
yapf==0.30.0 # use fix version to ensure consistent auto-styling
8+
coverage
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):

0 commit comments

Comments
 (0)