Skip to content
Open
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,6 @@ venv.bak/
.mypy_cache/

.vscode

# Claude Code settings
.claude/*
697 changes: 697 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[tool.poetry]
name = "kendryte210"
version = "1.3.0"
description = "Kendryte K210 is an AI capable RISCV64 dual core SoC."
authors = ["Sipeed <[email protected]>"]
license = "Apache-2.0"
homepage = "https://kendryte.com/"
repository = "https://github.com/sipeed/platform-kendryte210.git"
readme = "README.md"
keywords = ["dev-platform", "Kendryte", "SoC", "RISC-V", "64bit", "AI", "platformio"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Software Development :: Embedded Systems",
]
packages = [
{ include = "platform.py" },
{ include = "builder" },
]
include = [
"boards/*.json",
"examples/**/*",
]

[tool.poetry.dependencies]
python = "^3.8"
platformio = "^6.0"

[tool.poetry.group.dev.dependencies]
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
pytest-mock = "^3.11.0"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
minversion = "6.0"
addopts = [
"-ra",
"--strict-markers",
"--strict-config",
"--cov=.",
"--cov-report=term-missing:skip-covered",
"--cov-report=html:htmlcov",
"--cov-report=xml:coverage.xml",
"--cov-fail-under=80"
]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
markers = [
"unit: marks tests as unit tests (deselect with '-m \"not unit\"')",
"integration: marks tests as integration tests (deselect with '-m \"not integration\"')",
"slow: marks tests as slow (deselect with '-m \"not slow\"')",
]

[tool.coverage.run]
source = ["."]
omit = [
"tests/*",
"examples/*",
".venv/*",
"venv/*",
"*/__pycache__/*",
"*/site-packages/*",
".pytest_cache/*",
"htmlcov/*",
"build/*",
"dist/*",
]

[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"if self.debug:",
"if settings.DEBUG",
"raise AssertionError",
"raise NotImplementedError",
"if 0:",
"if __name__ == .__main__.:",
"class .*\\bProtocol\\):",
"@(abc\\.)?abstractmethod",
]
show_missing = true
skip_covered = true
precision = 2

[tool.coverage.html]
directory = "htmlcov"

[tool.coverage.xml]
output = "coverage.xml"
Empty file added tests/__init__.py
Empty file.
163 changes: 163 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
"""
Shared pytest fixtures for the kendryte210 platform tests.
"""

import json
import tempfile
from pathlib import Path
from unittest.mock import MagicMock
from typing import Dict, Any

import pytest


@pytest.fixture
def temp_dir():
"""Create a temporary directory for test files."""
with tempfile.TemporaryDirectory() as temp_path:
yield Path(temp_path)


@pytest.fixture
def mock_platform_config() -> Dict[str, Any]:
"""Mock platform configuration data."""
return {
"name": "kendryte210",
"title": "Kendryte K210",
"version": "1.3.0",
"description": "Kendryte K210 is an AI capable RISCV64 dual core SoC.",
"homepage": "https://kendryte.com/",
"keywords": ["dev-platform", "Kendryte", "SoC", "RISC-V", "64bit", "AI"],
"license": "Apache-2.0",
"engines": {"platformio": "^6"},
"repository": {
"type": "git",
"url": "https://github.com/sipeed/platform-kendryte210.git"
},
"frameworks": {
"kendryte-standalone-sdk": {
"package": "framework-kendryte-standalone-sdk",
"script": "builder/frameworks/kendryte-standalone-sdk.py",
"description": "Kendryte Standalone SDK without OS support"
}
}
}


@pytest.fixture
def mock_board_config() -> Dict[str, Any]:
"""Mock board configuration data."""
return {
"build": {
"core": "kendryte210",
"cpu": "k210",
"f_cpu": "26000000L",
"mcu": "k210"
},
"debug": {
"tools": {
"jlink": {
"server": {
"package": "tool-openocd-kendryte",
"executable": "bin/openocd",
"arguments": ["-f", "interface/jlink.cfg"]
}
}
}
},
"upload": {
"maximum_ram_size": 8388608,
"maximum_size": 16777216,
"protocol": "kflash",
"protocols": ["kflash"]
},
"url": "https://kendryte.com/",
"vendor": "Sipeed"
}


@pytest.fixture
def mock_platformio_env():
"""Mock PlatformIO environment."""
env = MagicMock()
env.BoardConfig.return_value.get.return_value = None
env.PioPlatform.return_value.get_package_dir.return_value = "/mock/package/dir"
env.subst.return_value = "kflash"
return env


@pytest.fixture
def sample_platform_json(temp_dir: Path) -> Path:
"""Create a sample platform.json file."""
platform_data = {
"name": "kendryte210",
"title": "Kendryte K210",
"version": "1.3.0",
"description": "Test platform configuration",
"frameworks": {
"kendryte-standalone-sdk": {
"package": "framework-kendryte-standalone-sdk",
"script": "builder/frameworks/kendryte-standalone-sdk.py"
}
}
}

platform_json_path = temp_dir / "platform.json"
with platform_json_path.open("w") as f:
json.dump(platform_data, f, indent=2)

return platform_json_path


@pytest.fixture
def sample_board_json(temp_dir: Path) -> Path:
"""Create a sample board JSON file."""
board_data = {
"build": {
"core": "kendryte210",
"cpu": "k210",
"f_cpu": "26000000L",
"mcu": "k210"
},
"debug": {
"tools": {}
},
"frameworks": ["kendryte-standalone-sdk", "arduino"],
"name": "Sipeed MAiX BiT",
"upload": {
"maximum_ram_size": 8388608,
"maximum_size": 16777216,
"protocol": "kflash"
},
"url": "https://maixpy.sipeed.com/en/hardware/board/bit.html",
"vendor": "Sipeed"
}

board_json_path = temp_dir / "board.json"
with board_json_path.open("w") as f:
json.dump(board_data, f, indent=2)

return board_json_path


@pytest.fixture
def mock_scons_env():
"""Mock SCons environment for builder tests."""
from unittest.mock import MagicMock

env = MagicMock()
env.BoardConfig.return_value = MagicMock()
env.PioPlatform.return_value = MagicMock()
env.get.return_value = None
env.subst.return_value = ""
env.VerboseAction = MagicMock(return_value="mock_action")
env.AutodetectUploadPort = "mock_port_detect"

return env


@pytest.fixture(autouse=True)
def reset_mocks():
"""Reset all mocks after each test."""
yield
# Add any cleanup if needed
Empty file added tests/integration/__init__.py
Empty file.
Loading