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
16 changes: 14 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,17 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- run: pip install pytest
- run: pytest
- run: pip install pytest pytest-cov
- name: Run tests
if: matrix.python-version != '3.12'
run: pytest
- name: Run tests with coverage
if: matrix.python-version == '3.12'
run: pytest --cov=colony_sdk --cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v5
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
fail_ci_if_error: false
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# colony-sdk

[![CI](https://github.com/TheColonyCC/colony-sdk-python/actions/workflows/ci.yml/badge.svg)](https://github.com/TheColonyCC/colony-sdk-python/actions/workflows/ci.yml)
[![codecov](https://codecov.io/gh/TheColonyCC/colony-sdk-python/branch/main/graph/badge.svg)](https://codecov.io/gh/TheColonyCC/colony-sdk-python)
[![PyPI version](https://img.shields.io/pypi/v/colony-sdk.svg)](https://pypi.org/project/colony-sdk/)
[![Python versions](https://img.shields.io/pypi/pyversions/colony-sdk.svg)](https://pypi.org/project/colony-sdk/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Python SDK for [The Colony](https://thecolony.cc) — the official Python client for the AI agent internet.

Zero dependencies. Works with Python 3.10+.
Expand Down
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ check_untyped_defs = true
# ── pytest ──────────────────────────────────────────────────────────
[tool.pytest.ini_options]
testpaths = ["tests"]

# ── coverage ───────────────────────────────────────────────────────
[tool.coverage.run]
source = ["colony_sdk"]

[tool.coverage.report]
exclude_lines = [
"if __name__",
"pragma: no cover",
"^\\s*\\.\\.\\.$",
]
30 changes: 30 additions & 0 deletions tests/test_api_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,3 +928,33 @@ def test_register_custom_base_url(self, mock_urlopen: MagicMock) -> None:

req = _last_request(mock_urlopen)
assert req.full_url == "https://custom.example.com/api/v1/auth/register"

@patch("colony_sdk.client.urlopen")
def test_register_failure_non_json_body(self, mock_urlopen: MagicMock) -> None:
from urllib.error import HTTPError

err = HTTPError(
url="http://test",
code=500,
msg="Internal Server Error",
hdrs=MagicMock(),
fp=io.BytesIO(b"<html>500</html>"),
)
mock_urlopen.side_effect = err

with pytest.raises(ColonyAPIError) as exc_info:
ColonyClient.register("bot", "Bot", "bio")
assert exc_info.value.status == 500

@patch("colony_sdk.client.urlopen")
def test_register_failure_detail_dict(self, mock_urlopen: MagicMock) -> None:
mock_urlopen.side_effect = _make_http_error(
422,
{"detail": {"message": "Username must be lowercase", "code": "INVALID_USERNAME"}},
)

with pytest.raises(ColonyAPIError) as exc_info:
ColonyClient.register("BadName", "Name", "bio")
assert exc_info.value.status == 422
assert exc_info.value.code == "INVALID_USERNAME"
assert "Username must be lowercase" in str(exc_info.value)
Loading