diff --git a/.github/workflows/presubmits.yml b/.github/workflows/presubmits.yml index 80d1b54..9732469 100644 --- a/.github/workflows/presubmits.yml +++ b/.github/workflows/presubmits.yml @@ -13,17 +13,14 @@ jobs: validate-signals: runs-on: ubuntu-latest steps: - # Step 1: Check out the current repository - uses: actions/checkout@v4 - # Step 2: Check out the central schema repository - name: Checkout schemas repo uses: actions/checkout@v4 with: repository: OBDb/.schemas path: .schemas - # Step 3: Validate with schema from the central repository - name: Validate signalsets id: json-yaml-validate-v3 uses: GrantBirki/json-yaml-validate@v2.7.1 diff --git a/.github/workflows/response_tests.yml b/.github/workflows/response_tests.yml index ac8e45f..5aea0ea 100644 --- a/.github/workflows/response_tests.yml +++ b/.github/workflows/response_tests.yml @@ -8,39 +8,58 @@ on: permissions: contents: read + pull-requests: write jobs: test: runs-on: ubuntu-latest steps: - - name: Checkout main repository + - name: Checkout repository uses: actions/checkout@v4 - - name: Checkout schemas repo - uses: actions/checkout@v4 + - name: Run tests in devcontainer + id: test + uses: devcontainers/ci@v0.3 with: - repository: OBDb/.schemas - path: tests/schemas + imageName: ghcr.io/obdb/devcontainer + push: never + env: | + GITHUB_SERVER_URL=${{ github.server_url }} + GITHUB_REPOSITORY=${{ github.repository }} + GITHUB_SHA=${{ github.sha }} + GITHUB_RUN_ID=${{ github.run_id }} + runCmd: | + pytest tests/ --ignore=tests/schemas -xvs -n auto > ./test-output.txt 2>&1 + TEST_EXIT=$? + cat ./test-output.txt - - name: Set up Python - uses: actions/setup-python@v4 - with: - python-version: '3.13' - cache: 'pip' + # Format results for PR comment with all required arguments + /usr/local/bin/format-test-results.sh \ + test-output.txt \ + $TEST_EXIT \ + "$GITHUB_SERVER_URL" \ + "$GITHUB_REPOSITORY" \ + "$GITHUB_SHA" \ + "$GITHUB_RUN_ID" \ + > ./test-results.md || true - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install -r tests/schemas/requirements.txt + # Exit with the actual test result + exit $TEST_EXIT - - name: Run tests - id: run_tests + - name: Set test results output + if: always() && github.event_name == 'pull_request' run: | - pytest tests/ --ignore=tests/schemas -xvs -n auto - continue-on-error: true + if [ -f test-results.md ]; then + { + echo 'TEST_RESULTS<> $GITHUB_ENV + fi - - name: Print fix instructions - if: steps.run_tests.outcome == 'failure' - run: | - echo "::notice title=How to fix failed tests::To fix the failed tests, run: python3 tests/update_yaml_tests.py --verbose" - exit 1 + - name: Comment test results on PR + if: always() && github.event_name == 'pull_request' + uses: thollander/actions-comment-pull-request@v2 + with: + message: ${{ env.TEST_RESULTS }} + comment_tag: response-tests diff --git a/.gitignore b/.gitignore index dde0473..edfa601 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ tests/schemas/ __pycache__ -build/ -.meta/ -workspace/ - +.claude/skills +.claude/settings.local.json +tests/*.py diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index da11add..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "python.testing.pytestArgs": [ - "tests", - "-xvs", - "-n", - "auto" - ], - "python.testing.unittestEnabled": false, - "python.testing.pytestEnabled": true, - "files.trimTrailingWhitespace": true -} diff --git a/.vscode/tasks.json b/.vscode/tasks.json deleted file mode 100644 index 3bbe224..0000000 --- a/.vscode/tasks.json +++ /dev/null @@ -1,39 +0,0 @@ -{ - "version": "2.0.0", - "tasks": [ - { - "label": "Format Signals", - "type": "shell", - "command": "find signalsets/v3 -type f -exec python3 tests/schemas/cli.py '{}' --output '{}' \\;", - "problemMatcher": [], - "group": "test" - }, - { - "label": "Update YAML Tests", - "type": "shell", - "command": "python3 ${workspaceFolder}/tests/update_yaml_tests.py ${input:testUpdateOptions}", - "problemMatcher": [], - "presentation": { - "reveal": "always", - "panel": "new" - }, - "group": "test" - } - ], - "inputs": [ - { - "id": "testUpdateOptions", - "type": "pickString", - "description": "Choose test update options", - "options": [ - "--dry-run --verbose", - "--verbose", - "--year 2022 --verbose", - "--year 2023 --verbose", - "--year 2024 --verbose", - "--year 2025 --verbose" - ], - "default": "--dry-run --verbose" - } - ] -} diff --git a/tests/test_responses.py b/tests/test_responses.py deleted file mode 100644 index b583341..0000000 --- a/tests/test_responses.py +++ /dev/null @@ -1,41 +0,0 @@ -import glob -import os -import pytest -from pathlib import Path - -# These will be imported from the schemas repository -from schemas.python.json_formatter import format_file -from schemas.python.signals_testing import find_test_yaml_files, register_test_classes - -REPO_ROOT = Path(__file__).parent.parent.absolute() -TEST_CASES_DIR = os.path.join(Path(__file__).parent, 'test_cases') - -# Find all test files grouped by model year -test_files_by_year = find_test_yaml_files(TEST_CASES_DIR) - -# Register test classes dynamically -register_test_classes(test_files_by_year) - -def get_json_files(): - """Get all JSON files from the signalsets/v3 directory.""" - signalsets_path = os.path.join(REPO_ROOT, 'signalsets', 'v3') - json_files = glob.glob(os.path.join(signalsets_path, '*.json')) - # Convert full paths to relative filenames - return [os.path.basename(f) for f in json_files] - -@pytest.mark.parametrize("test_file", - get_json_files(), - ids=lambda x: x.split('.')[0].replace('-', '_') # Create readable test IDs -) -def test_formatting(test_file): - """Test signal set formatting for all vehicle models in signalsets/v3/.""" - signalset_path = os.path.join(REPO_ROOT, 'signalsets', 'v3', test_file) - - formatted = format_file(signalset_path) - - with open(signalset_path) as f: - assert f.read() == formatted - -if __name__ == '__main__': - # Use pytest's main function with xdist arguments - pytest.main([__file__, '-xvs', '-n', 'auto']) diff --git a/tests/update_yaml_tests.py b/tests/update_yaml_tests.py deleted file mode 100644 index 41b3019..0000000 --- a/tests/update_yaml_tests.py +++ /dev/null @@ -1,93 +0,0 @@ -#!/usr/bin/env python3 -""" -Tool for updating YAML test cases with current signal values. -This is useful when signals are removed from signalsets and tests need to be updated. -""" - -import os -import sys -import argparse -import subprocess -from pathlib import Path - -# Add the current directory to the path so we can import our module -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) - -def ensure_schemas_repo(): - """Ensure the schemas repository is cloned, similar to devcontainer.json.""" - script_dir = os.path.dirname(os.path.abspath(__file__)) - schemas_dir = os.path.join(script_dir, 'schemas') - - # Check if schemas directory exists and is a git repository - if os.path.isdir(os.path.join(schemas_dir, '.git')): - # Try to pull latest changes - try: - print(f"Updating schemas repository...") - subprocess.run(['git', 'pull'], cwd=schemas_dir, check=True) - return True - except subprocess.CalledProcessError as e: - print(f"Warning: Failed to update schemas repository: {e}") - # Continue with existing repo - return True - elif os.path.exists(schemas_dir): - # Directory exists but might not be a git repository - print(f"Warning: schemas directory exists but might not be a git repository: {schemas_dir}") - return True - else: - # Need to clone the repository - try: - print(f"Cloning schemas repository...") - subprocess.run( - ['git', 'clone', '--depth=1', 'https://github.com/OBDb/.schemas.git', schemas_dir], - check=True - ) - return True - except subprocess.CalledProcessError as e: - print(f"Error: Failed to clone schemas repository: {e}") - return False - -def main(): - parser = argparse.ArgumentParser(description='Update YAML test expected values based on current signalsets') - parser.add_argument('--test-cases-dir', default=None, help='Path to test_cases directory') - parser.add_argument('--year', type=int, action='append', help='Specific model year(s) to update') - parser.add_argument('--dry-run', action='store_true', help='Show what would be changed without making changes') - parser.add_argument('--verbose', '-v', action='store_true', help='Show detailed output') - - args = parser.parse_args() - - # Find test_cases directory - if args.test_cases_dir: - test_cases_dir = args.test_cases_dir - else: - # Try to find it relative to current script - script_dir = os.path.dirname(os.path.abspath(__file__)) - test_cases_dir = os.path.join(script_dir, 'test_cases') - - if not os.path.isdir(test_cases_dir): - print(f"Test cases directory not found: {test_cases_dir}") - print(f"Creating directory: {test_cases_dir}") - os.makedirs(test_cases_dir) - - print(f"Using test cases directory: {test_cases_dir}") - - # Ensure we have the schemas repository - if not ensure_schemas_repo(): - print("Error: Could not set up schemas repository.") - sys.exit(1) - - # Import our module - try: - from schemas.python.yaml_test_updater import update_yaml_tests - update_yaml_tests(test_cases_dir, args.year, args.dry_run, args.verbose) - except ImportError as e: - print(f"Error importing yaml_test_updater module: {e}") - print("Make sure the schemas package is properly installed.") - sys.exit(1) - except Exception as e: - print(f"Error updating YAML tests: {e}") - sys.exit(1) - - print("Done!") - -if __name__ == "__main__": - main()