Skip to content

test: add comprehensive C# and Python unit tests for the PyMCU SDK#4

Merged
begeistert merged 1 commit into
mainfrom
copilot/add-unit-tests-for-python-code
Apr 23, 2026
Merged

test: add comprehensive C# and Python unit tests for the PyMCU SDK#4
begeistert merged 1 commit into
mainfrom
copilot/add-unit-tests-for-python-code

Conversation

Copilot AI commented Apr 23, 2026

Copy link
Copy Markdown
Contributor

The SDK had no tests of its own despite containing non-trivial logic across the IR layer, backend analysis passes, serialization, license validation, and Python plugin abstractions. This brings a self-contained test suite ported and adapted from the upstream PyMCU monorepo, extended with edge-case coverage specific to this package.

C# — tests/csharp/ (138 xUnit tests)

  • IR/DataTypeTests.csSizeOf, IsSigned, StringToDataType (all type strings including const[T], ptr[T], PIORegister, null/unknown), GetPromotedType (same type, larger wins, mixed-signedness promotion at all widths)
  • IR/TackyTests.cs — Record equality/defaults for every Val and Instruction subtype; ProgramIR/Function defaults and mutation
  • Backend/Analysis/StackAllocatorTests.cs — Global allocation, local frame sequencing, param registration via call graph entry points, globals not re-allocated as locals, ISR function allocation, VariableSizes for all data widths, bit instructions, ArrayLoad/ArrayStore byte sizing
  • Backend/Analysis/DynamicStackAllocatorTests.cs — Downward-growing offsets, params-before-body-locals ordering, 16-byte alignment invariant, unique offsets, temporaries, custom word sizes
  • Backend/Serialization/IrSerializerTests.cs — Full JSON round-trip for every instruction and value type, including FlashData, MemoryAddress, FloatConstant, InlineAsm with operands
  • Backend/License/LicenseResultTests.cs — All factory methods (Free, Ok, NotFound, Expired, WrongFamily)
  • Backend/License/LicenseValidatorTests.csResolveKey resolution order (explicit > env > whitespace), JWT parsing for valid/expired/wrong-family/all-families tokens, case-insensitive family matching

Python — tests/python/ (56 pytest tests)

  • test_base_tool.py_default_platform_key arch normalisation (amd64→x86_64, aarch64→arm64), _is_non_interactive (CI env, PYMCU_NO_INTERACTIVE, tty), verify_sha256, _extract_archive for tar.gz/bz2/zip including zip-slip path traversal protection for both tar and zip formats, base dir env override, version cache helpers
  • test_backend_plugin.pyresolve_license_key full priority chain, BackendPlugin.supports (exact, prefix, case-insensitive, false-positive guard), validate_license default/override, LicenseStatus enum completeness
  • test_toolchain_plugin.pyToolchainPlugin.get_instance uses default_chip, get_ffi_toolchain default returns None, ExternalToolchain chip storage and assemble contract

Infrastructure

  • tests/csharp/PyMCU.Backend.SDK.Tests.csproj — references the SDK project; pulls xUnit 2.7 + FluentAssertions 6.12
  • PyMCU.SDK.slnx — test project added to the solution
  • pyproject.toml[tool.pytest.ini_options] block pointing at tests/python/

@begeistert begeistert marked this pull request as ready for review April 23, 2026 06:29
@begeistert begeistert merged commit f60c724 into main Apr 23, 2026
6 checks passed
@begeistert begeistert deleted the copilot/add-unit-tests-for-python-code branch April 23, 2026 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants