Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
{
"name": "Default Linux Universal",
"image": "mcr.microsoft.com/devcontainers/universal:2-linux",
"name": "Ubuntu",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers-contrib/features/poetry:2": {}
"ghcr.io/jsburckhardt/devcontainer-features/uv:1": {},
"ghcr.io/meaningful-ooo/devcontainer-features/fish:2": {}
},
"postCreateCommand": "poetry config virtualenvs.in-project true && poetry install && poetry run pre-commit install",
"postCreateCommand": "uv sync && uv run pre-commit install",
"customizations": {
"vscode": {
"settings": {
"python.analysis.diagnosticMode": "workspace",
"ruff.organizeImports": false,
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports": "explicit"
}
},
Expand Down Expand Up @@ -43,7 +44,6 @@
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff",
"ms-python.isort",
"EditorConfig.EditorConfig",
"esbenp.prettier-vscode"
]
Expand Down
11 changes: 3 additions & 8 deletions .github/actions/setup-python/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ inputs:
python-version:
description: Python version
required: false
default: "3.10"
default: "3.12"

runs:
using: "composite"
steps:
- name: Install poetry
run: pipx install poetry
shell: bash

- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v7
with:
python-version: ${{ inputs.python-version }}
cache: "poetry"

- run: poetry install
- run: uv sync --locked
shell: bash
18 changes: 15 additions & 3 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@ name: Code Coverage

on:
push:
branches:
- master
pull_request:

jobs:
test:
name: Test Coverage
runs-on: ubuntu-latest
name: Run Pytest and Upload Coverage
strategy:
fail-fast: false
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
env:
PYTHON_VERSION: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6

- name: Setup Python environment
uses: ./.github/actions/setup-python
with:
python-version: ${{ matrix.python-version }}

- name: Run Pytest
run: poetry run pytest --cov-report xml
run: uv run --no-sync pytest --cov-report xml

- name: Upload coverage report
uses: codecov/codecov-action@v5
with:
env_vars: PYTHON_VERSION
files: ./coverage.xml
flags: unittests
fail_ci_if_error: true
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,28 @@ jobs:
id-token: write
contents: write
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6

- name: Setup Python environment
uses: ./.github/actions/setup-python

- name: Get Version
id: version
run: |
echo "VERSION=$(poetry version -s)" >> $GITHUB_OUTPUT
echo "VERSION=$(uv version --short)" >> $GITHUB_OUTPUT
echo "TAG_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT
echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT

- name: Check Version
if: steps.version.outputs.VERSION != steps.version.outputs.TAG_VERSION
run: exit 1

- name: Build Package
run: poetry build

- name: Publish Package to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
- name: Build and Publish Package
run: |
uv build
uv publish

- name: Publish Package to GitHub
run: |
gh release upload --clobber ${{ steps.version.outputs.TAG_NAME }} dist/*.tar.gz dist/*.whl
run: gh release upload --clobber ${{ steps.version.outputs.TAG_NAME }} dist/*.tar.gz dist/*.whl
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
name: Ruff Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v6

- name: Run Ruff Lint
uses: chartboost/ruff-action@v1
uses: astral-sh/ruff-action@v3
8 changes: 1 addition & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@ repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.7
hooks:
- id: ruff
- id: ruff-check
args: [--fix, --exit-non-zero-on-fix]
stages: [pre-commit]
- id: ruff-format
stages: [pre-commit]

- repo: https://github.com/pycqa/isort
rev: 7.0.0
hooks:
- id: isort
stages: [pre-commit]

- repo: https://github.com/nonebot/nonemoji
rev: v0.1.4
hooks:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ _✨ NoneBot2 测试框架 ✨_

本工具为 [pytest](https://docs.pytest.org/en/stable/) 插件,需要配合 pytest 异步插件使用。

```bash
uv add nonebug pytest-asyncio --group test
# 或者使用 anyio
uv add nonebug anyio --group test
```

```bash
poetry add nonebug pytest-asyncio -G test
# 或者使用 anyio
Expand Down
2 changes: 1 addition & 1 deletion nonebug/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .mixin import DriverMixin, CallApiMixin, ProcessMixin, DependentMixin
from .mixin import CallApiMixin, DependentMixin, DriverMixin, ProcessMixin


class App(DependentMixin, ProcessMixin, CallApiMixin, DriverMixin): ...
2 changes: 1 addition & 1 deletion nonebug/fixture.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from contextlib import asynccontextmanager

import pytest
from async_asgi_testclient import TestClient
import pytest

from nonebug.app import App
from nonebug.mixin.driver import set_global_client
Expand Down
4 changes: 2 additions & 2 deletions nonebug/mixin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from .driver import DriverMixin as DriverMixin
from .process import ProcessMixin as ProcessMixin
from .call_api import CallApiMixin as CallApiMixin
from .dependent import DependentMixin as DependentMixin
from .driver import DriverMixin as DriverMixin
from .process import ProcessMixin as ProcessMixin
8 changes: 4 additions & 4 deletions nonebug/mixin/call_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import contextlib
from queue import Queue
from typing import TYPE_CHECKING, Any, Union, TypeVar, Optional, overload
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union, overload

import pytest

from nonebug.base import BaseApp, Context

from .model import Api, Send, Model
from .fake import make_fake_bot, make_fake_adapter
from .fake import make_fake_adapter, make_fake_bot
from .model import Api, Model, Send

if TYPE_CHECKING:
from nonebot.adapters import Bot, Event, Adapter, Message, MessageSegment
from nonebot.adapters import Adapter, Bot, Event, Message, MessageSegment

A = TypeVar("A", bound="Adapter")
B = TypeVar("B", bound="Bot")
Expand Down
4 changes: 2 additions & 2 deletions nonebug/mixin/call_api/fake.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from typing import TYPE_CHECKING, Any, Optional, TypeVar, Union, overload
from typing_extensions import override
from typing import TYPE_CHECKING, Any, Union, TypeVar, Optional, overload

if TYPE_CHECKING:
from nonebot.adapters import Bot, Event, Adapter, Message, MessageSegment
from nonebot.adapters import Adapter, Bot, Event, Message, MessageSegment

from . import ApiContext

Expand Down
4 changes: 2 additions & 2 deletions nonebug/mixin/call_api/model.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Union, Optional
from typing import TYPE_CHECKING, Any, Optional, Union

if TYPE_CHECKING:
from nonebot.adapters import Bot, Event, Adapter, Message, MessageSegment
from nonebot.adapters import Adapter, Bot, Event, Message, MessageSegment


@dataclass
Expand Down
6 changes: 3 additions & 3 deletions nonebug/mixin/dependent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing_extensions import final
from collections.abc import Iterable
from contextlib import AsyncExitStack
from typing import TYPE_CHECKING, Any, Union, Callable, Optional
from typing import TYPE_CHECKING, Any, Callable, Optional, Union
from typing_extensions import final

import pytest

Expand All @@ -10,7 +10,7 @@
from .call_api import ApiContext

if TYPE_CHECKING:
from nonebot.dependencies import Param, Dependent
from nonebot.dependencies import Dependent, Param


UNSET = object()
Expand Down
26 changes: 13 additions & 13 deletions nonebug/mixin/process/__init__.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
from contextvars import ContextVar
from collections import defaultdict
from typing_extensions import final
from contextlib import contextmanager
from typing import TYPE_CHECKING, Union, Literal, Optional, TypedDict
from contextvars import ContextVar
from typing import TYPE_CHECKING, Literal, Optional, TypedDict, Union
from typing_extensions import final

import pytest
from _pytest.outcomes import Skipped
import pytest

from nonebug.base import BaseApp
from nonebug.mixin.call_api import ApiContext

from .fake import PATCHES, make_fake_default_state
from .model import (
Check,
Action,
Paused,
Check,
Finished,
Rejected,
RulePass,
IgnoreRule,
RuleNotPass,
ReceiveEvent,
PermissionPass,
IgnorePermission,
IgnoreRule,
Paused,
PermissionNotPass,
PermissionPass,
ReceiveEvent,
Rejected,
RuleNotPass,
RulePass,
)

if TYPE_CHECKING:
from nonebot.matcher import Matcher
from nonebot.adapters import Bot, Event
from nonebot.matcher import Matcher

event_test_context: ContextVar[tuple[ReceiveEvent, "EventTest"]] = ContextVar(
"event_test_context"
Expand Down
4 changes: 2 additions & 2 deletions nonebug/mixin/process/fake.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections.abc import Awaitable
from typing_extensions import ParamSpec
from typing import TYPE_CHECKING, Callable
from typing_extensions import ParamSpec

from _pytest.outcomes import OutcomeException

Expand Down Expand Up @@ -53,8 +53,8 @@ def make_fake_simple_run(

async def fake_simple_run(self: "Matcher", *args, **kwargs) -> None:
from nonebot.exception import (
PausedException,
FinishedException,
PausedException,
RejectedException,
)

Expand Down
4 changes: 2 additions & 2 deletions nonebug/mixin/process/model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from dataclasses import dataclass
from typing import TYPE_CHECKING, Union, ClassVar, Optional
from typing import TYPE_CHECKING, ClassVar, Optional, Union

from _pytest.outcomes import OutcomeException

if TYPE_CHECKING:
from nonebot.matcher import Matcher
from nonebot.adapters import Bot, Event
from nonebot.matcher import Matcher


@dataclass
Expand Down
12 changes: 6 additions & 6 deletions nonebug/provider.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from copy import deepcopy
from collections import defaultdict
from contextlib import contextmanager
from typing import Union, TypeVar, Optional, overload
from collections.abc import (
Mapping,
ItemsView,
Iterator,
KeysView,
ItemsView,
ValuesView,
Mapping,
MutableMapping,
ValuesView,
)
from contextlib import contextmanager
from copy import deepcopy
from typing import Optional, TypeVar, Union, overload

from nonebot.matcher import Matcher, MatcherProvider

Expand Down
Loading