Skip to content

Commit

Permalink
chore: Configure coverage.io and update ci.yaml (#20)
Browse files Browse the repository at this point in the history
- Added coverage.io configuration to the project
- Updated ci.yaml to include coverage reporting
- Added coverage badge to README for visual representation of test
coverage
  • Loading branch information
chyroc authored Sep 27, 2024
1 parent 97609d3 commit 8dcc15f
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
poetry run ruff format --check
poetry build
- name: Run tests
run: poetry run pytest
run: poetry run pytest --cov --cov-report=xml
env:
COZE_TOKEN: ${{ secrets.COZE_TOKEN }}
SPACE_ID_1: ${{ secrets.SPACE_ID_1 }}
Expand All @@ -47,6 +47,8 @@ jobs:
COZE_BOT_ID_TRANSLATE: ${{ secrets.COZE_BOT_ID_TRANSLATE }}
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}

test_success:
# this aggregates success state of all jobs listed in `needs`
Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ And then install dependencies:
poetry install
```

Run the code

## Pre Commit

```shell
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Coze Python API SDK

[![PyPI version](https://img.shields.io/pypi/v/cozepy.svg)](https://pypi.org/project/cozepy/)
[![codecov](https://codecov.io/github/coze-dev/coze-py/graph/badge.svg?token=U6OKGQXF0E)](https://codecov.io/github/coze-dev/coze-py)

## Requirements

Expand All @@ -14,6 +15,10 @@ pip install cozepy

## Usage

### Examples

TODO

### Auth

#### Personal Auth Token
Expand Down Expand Up @@ -60,7 +65,7 @@ chat = coze.chat.create(
)
start = int(time.time())
while chat.status == ChatStatus.in_progress:
if int(time.time()) > 120:
if int(time.time()) - start > 120:
# too long, cancel chat
coze.chat.cancel(conversation_id=chat.conversation_id, chat_id=chat.chat_id)
break
Expand All @@ -83,7 +88,7 @@ chat_iterator = coze.chat.stream(
)
for event in chat_iterator:
if event.event == ChatEventType.conversation_message_delta:
print('got message delta:', event.messages.content)
print('got message delta:', event.message.content)
```

### Bots
Expand Down
14 changes: 14 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
coverage:
status:
project: #add everything under here, more options at https://docs.codecov.com/docs/commit-status
default:
target: 70%
threshold: 70%
base: auto
comment: #this is a top-level key
layout: "diff, flags, files"
behavior: default
require_changes: true # if true: only post the comment if coverage changes
require_base: true # if true: must have a base report to post
require_head: true # if true: must have a head report to post
hide_project_coverage: false # [true :: only show coverage on the git diff aka patch coverage]]
1 change: 1 addition & 0 deletions cozepy/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class TokenAuth(Auth):
"""

def __init__(self, token: str):
# TODO: 其他 sdk 实现
assert isinstance(token, str)
assert len(token) > 0
self._token = token
Expand Down
10 changes: 5 additions & 5 deletions cozepy/chat/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from enum import Enum
from typing import Dict, List, Iterator, Union, TYPE_CHECKING, Optional

Expand Down Expand Up @@ -184,6 +183,9 @@ class Chat(CozeModel):
# Details of the information needed for execution.


# TODO: 枚举值是否需要大写


class ChatEventType(str, Enum):
# Event for creating a conversation, indicating the start of the conversation.
# 创建对话的事件,表示对话开始。
Expand Down Expand Up @@ -268,17 +270,15 @@ def __next__(self) -> ChatEvent:
ChatEventType.conversation_message_delta,
ChatEventType.conversation_message_completed,
]:
return ChatEvent(
event=event, message=Message.model_validate(json.loads(data))
)
return ChatEvent(event=event, message=Message.model_validate_json(data))
elif event in [
ChatEventType.conversation_chat_created,
ChatEventType.conversation_chat_in_progress,
ChatEventType.conversation_chat_completed,
ChatEventType.conversation_chat_failed,
ChatEventType.conversation_chat_requires_action,
]:
return ChatEvent(event=event, chat=Chat.model_validate(json.loads(data)))
return ChatEvent(event=event, chat=Chat.model_validate_json(data))
else:
raise ValueError(f"invalid chat.event: {event}, {data}")

Expand Down
95 changes: 94 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typing-extensions = "^4.3.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.0.0"
pytest-cov = "^4.0.0"
ruff = "^0.6.0"
pre-commit = "^2.9.0"

Expand Down

0 comments on commit 8dcc15f

Please sign in to comment.