Skip to content

Add sync/async symmetry validation and attributes mapping tests - #497

Merged
martin-majlis merged 1 commit into
masterfrom
add-script-and-tests-for-checking-symetry
Mar 18, 2026
Merged

martin-majlis merged 1 commit into
masterfrom
add-script-and-tests-for-checking-symetry

Conversation

@martin-majlis

Copy link
Copy Markdown
Owner

Add sync/async symmetry validation and attributes mapping tests

Summary

This PR introduces comprehensive tooling to validate and maintain the critical sync/async symmetry requirement between WikipediaPage and AsyncWikipediaPage classes. The changes ensure that both APIs remain perfectly aligned as required by the project's architecture guidelines.

Key Changes

🆕 New Validation Script (validate_attributes_mapping.py)

  • 775 lines of comprehensive validation logic
  • Systematically tests property access patterns and API call tracking
  • Validates internal attribute population against documented ATTRIBUTES_MAPPING
  • Implements HTTP-level caching to prevent duplicate network requests
  • Provides detailed JSON reports and console summaries
  • Exit codes: 0 (success) or 1 (validation failures)

🆕 New Test Suite (tests/test_sync_async_symmetry.py)

  • 452 lines of unit tests for sync/async property symmetry
  • Tests all construction-time properties (title, ns, language, variant)
  • Tests all awaitable properties that require API calls
  • Ensures identical behavior between sync and async implementations
  • Uses mock data for consistent, reliable testing

🆕 GitHub Actions Workflow (.github/workflows/validate-attributes-mapping.yml)

  • Automated validation on push/PR to master branch
  • Daily scheduled runs (06:00 UTC) for continuous monitoring
  • Runs on Python 3.11 with uv package manager
  • Outputs validation results for CI/CD integration

📝 Documentation Updates

  • AGENTS.md: Comprehensive 149-line addition with sync/async symmetry guidelines
  • Updated API.rst and README.rst with new tooling information
  • Enhanced example_async.py with better patterns

🔧 Core Improvements

  • wikipediaapi/_base_wikipedia_page.py: 17 lines of improvements
  • wikipediaapi/async_wikipedia_page.py: 19 lines of improvements
  • Updated .gitignore for better file management

Impact

Before

  • Manual verification of sync/async symmetry
  • Risk of unnoticed API divergence
  • No systematic validation of attribute mapping

After

  • Automated validation of all property behaviors
  • Continuous monitoring via GitHub Actions
  • Comprehensive test coverage for sync/async symmetry
  • Detailed reporting for debugging and maintenance

Validation Coverage

The new tooling validates:

  • Property Discovery: All accessible properties via dir()
  • API Call Tracking: Internal calls (info, extracts, langlinks, etc.)
  • Attribute Population: Internal _attributes dictionary behavior
  • Mapping Validation: Against documented ATTRIBUTES_MAPPING
  • HTTP Caching: Request efficiency and duplicate prevention

Testing

# Run validation script
uv run python validate_attributes_mapping.py

# Run symmetry tests
make run-tests

# Run pre-commit checks
make run-pre-commit

Files Changed

  • 12 files modified
  • 1,482 insertions, 55 deletions
  • New files: 3 (validation script, test suite, workflow)
  • Updated files: 9 (documentation, core modules, examples)

This change strengthens the project's commitment to maintaining perfect sync/async API symmetry and provides robust tooling for ongoing validation and maintenance.

@martin-majlis
martin-majlis merged commit a1ceb5a into master Mar 18, 2026
39 of 40 checks passed
@martin-majlis
martin-majlis deleted the add-script-and-tests-for-checking-symetry branch March 18, 2026 00:12
@codecov

codecov Bot commented Mar 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.16%. Comparing base (f1ff681) to head (5dff9a7).
⚠️ Report is 123 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #497   +/-   ##
=======================================
  Coverage   97.15%   97.16%           
=======================================
  Files          14       14           
  Lines        1197     1201    +4     
=======================================
+ Hits         1163     1167    +4     
  Misses         34       34           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant