Skip to content

test: add comprehensive unit tests for core utilities#990

Merged
qin-ctx merged 1 commit intovolcengine:mainfrom
xingzihai:add-comprehensive-unit-tests
Mar 26, 2026
Merged

test: add comprehensive unit tests for core utilities#990
qin-ctx merged 1 commit intovolcengine:mainfrom
xingzihai:add-comprehensive-unit-tests

Conversation

@xingzihai
Copy link
Contributor

Summary

This PR adds comprehensive unit tests for core OpenViking utility modules to improve test coverage and code reliability.

Changes

New Test Files

  1. tests/unit/test_circuit_breaker.py (93 tests)

    • TestClassifyApiError: Tests for API error classification (permanent vs transient)
    • TestCircuitBreaker: Tests for circuit breaker state transitions (CLOSED, OPEN, HALF_OPEN)
    • TestCircuitBreakerEdgeCases: Edge cases including thread safety
  2. tests/unit/test_process_lock.py (36 tests)

    • TestReadPidFile: Tests for PID file reading
    • TestIsPidAlive: Tests for process liveness detection
    • TestAcquireDataDirLock: Tests for data directory lock acquisition
    • TestAcquireDataDirLockEdgeCases: Edge cases for lock handling
  3. tests/unit/test_time_utils_comprehensive.py (41 tests)

    • TestParseIsoDatetime: Tests for ISO datetime parsing
    • TestFormatIso8601: Tests for ISO 8601 formatting
    • TestFormatSimplified: Tests for simplified time formatting
    • TestGetCurrentTimestamp: Tests for timestamp generation
    • TestTimeUtilsRoundTrip: Round-trip conversion tests
  4. tests/unit/test_context.py (66 tests)

    • TestResourceContentType, TestContextType, TestContextLevel: Enum tests
    • TestContextInit: Initialization tests
    • TestContextDeriveContextType, TestContextDeriveCategory: Derivation tests
    • TestContextMethods: Method tests
    • TestContextToDict, TestContextFromDict: Serialization tests
    • TestContextWithUser: User-related tests
  5. tests/unit/test_message.py (56 tests)

    • TestTextPart, TestContextPart, TestToolPart: Part class tests
    • TestPartFromDict: Part deserialization tests
    • TestMessageInit, TestMessageContent: Message initialization tests
    • TestMessageToDict, TestMessageFromDict: Serialization tests
    • TestMessageFactoryMethods: Factory method tests
    • TestMessageMethods: Method tests
    • TestMessageEdgeCases: Edge case handling

Test Coverage

  • 212 total test cases added
  • Tests cover:
    • Normal functionality
    • Edge cases (empty inputs, invalid data, boundary conditions)
    • Error handling
    • Unicode and special character handling
    • Thread safety (circuit breaker)
    • Round-trip serialization/deserialization

Test Results

All 212 tests pass:

======================= 212 passed, 5 warnings in 7.23s ========================

Code Quality

  • All tests follow the project coding style (verified with ruff check)
  • All tests formatted with ruff format
  • Tests follow existing patterns in the project test suite

Related Issues

Improves test coverage for core utility modules that are used throughout the OpenViking SDK.

Add comprehensive unit tests for the following modules:
- openviking/utils/circuit_breaker.py: Test CircuitBreaker class and classify_api_error function
- openviking/utils/process_lock.py: Test acquire_data_dir_lock and related functions
- openviking/utils/time_utils.py: Test parse_iso_datetime, format_iso8601, format_simplified, get_current_timestamp
- openviking/core/context.py: Test Context class and related enums
- openviking/message: Test Message, TextPart, ContextPart, ToolPart classes

Test coverage includes:
- Normal functionality tests
- Edge case handling
- Error handling
- Unicode and special character handling
- Thread safety (for circuit breaker)
- Round-trip serialization/deserialization

Total: 212 test cases added
@github-actions
Copy link

Failed to generate code suggestions for PR

@qin-ctx qin-ctx merged commit 3258acd into volcengine:main Mar 26, 2026
2 checks passed
@github-project-automation github-project-automation bot moved this from Backlog to Done in OpenViking project Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants