forked from 0xWheatyz/SPARC
Merge pull request 'ci: add pytest and ruff linting to CI workflow' (#32) from feature/ci-testing-linting into main
This commit was merged in pull request #32.
This commit is contained in:
@@ -9,7 +9,43 @@ on:
|
|||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install system dependencies
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
apk add --no-cache git python3 py3-pip gcc musl-dev libpq-dev python3-dev
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
git clone http://gitea.gitea.svc.cluster.local/${{ gitea.repository }}.git .
|
||||||
|
git checkout ${{ gitea.sha }}
|
||||||
|
|
||||||
|
- name: Install Python dependencies
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
pip3 install --break-system-packages -r requirements.txt ruff
|
||||||
|
|
||||||
|
- name: Run ruff linter
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
ruff check SPARC/ tests/
|
||||||
|
|
||||||
|
- name: Run pytest
|
||||||
|
shell: sh
|
||||||
|
env:
|
||||||
|
DATABASE_URL: "sqlite://"
|
||||||
|
API_KEY: "test-key"
|
||||||
|
OPENROUTER_API_KEY: "test-key"
|
||||||
|
JWT_SECRET: "test-secret-for-ci"
|
||||||
|
APP_ENV: "development"
|
||||||
|
run: |
|
||||||
|
python3 -m pytest tests/ -v --tb=short -x
|
||||||
|
|
||||||
build-api:
|
build-api:
|
||||||
|
needs: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
@@ -81,6 +117,7 @@ jobs:
|
|||||||
echo "API image available at ${{ steps.tags.outputs.IMAGE_TAG }}"
|
echo "API image available at ${{ steps.tags.outputs.IMAGE_TAG }}"
|
||||||
|
|
||||||
build-frontend:
|
build-frontend:
|
||||||
|
needs: test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Install dependencies
|
- name: Install dependencies
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
name: Test and Lint
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- name: Install system dependencies
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
apk add --no-cache git python3 py3-pip gcc musl-dev libpq-dev python3-dev
|
||||||
|
|
||||||
|
- name: Checkout code
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
git clone http://gitea.gitea.svc.cluster.local/${{ gitea.repository }}.git .
|
||||||
|
git checkout ${{ gitea.sha }}
|
||||||
|
|
||||||
|
- name: Install Python dependencies
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
pip3 install --break-system-packages -r requirements.txt ruff
|
||||||
|
|
||||||
|
- name: Run ruff linter
|
||||||
|
shell: sh
|
||||||
|
run: |
|
||||||
|
ruff check SPARC/ tests/
|
||||||
|
|
||||||
|
- name: Run pytest
|
||||||
|
shell: sh
|
||||||
|
env:
|
||||||
|
DATABASE_URL: "sqlite://"
|
||||||
|
API_KEY: "test-key"
|
||||||
|
OPENROUTER_API_KEY: "test-key"
|
||||||
|
JWT_SECRET: "test-secret-for-ci"
|
||||||
|
APP_ENV: "development"
|
||||||
|
run: |
|
||||||
|
python3 -m pytest tests/ -v --tb=short -x
|
||||||
+3
-2
@@ -1,3 +1,4 @@
|
|||||||
from .types import Patents, Patent
|
from .types import Patent as Patent
|
||||||
|
from .types import Patents as Patents
|
||||||
|
|
||||||
all = ["Patents", "Patent"]
|
__all__ = ["Patents", "Patent"]
|
||||||
|
|||||||
+2
-2
@@ -13,9 +13,9 @@ from SPARC import config
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
from SPARC.database import DatabaseClient
|
from SPARC.database import DatabaseClient
|
||||||
from SPARC.serp_api import SERP
|
|
||||||
from SPARC.llm import LLMAnalyzer
|
from SPARC.llm import LLMAnalyzer
|
||||||
from SPARC.types import Patent, Patents, CompanyAnalysisResult, BatchAnalysisResult
|
from SPARC.serp_api import SERP
|
||||||
|
from SPARC.types import BatchAnalysisResult, CompanyAnalysisResult, Patent, Patents
|
||||||
|
|
||||||
|
|
||||||
class CompanyAnalyzer:
|
class CompanyAnalyzer:
|
||||||
|
|||||||
+7
-6
@@ -1,14 +1,15 @@
|
|||||||
"""Database client for storing and retrieving LLM messages and user authentication."""
|
"""Database client for storing and retrieving LLM messages and user authentication."""
|
||||||
|
|
||||||
import contextlib
|
import contextlib
|
||||||
import psycopg2
|
|
||||||
from psycopg2.pool import ThreadedConnectionPool
|
|
||||||
from psycopg2.extras import RealDictCursor
|
|
||||||
from typing import Dict, List, Optional
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
import json
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import json
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from typing import Dict, List, Optional
|
||||||
|
|
||||||
import bcrypt
|
import bcrypt
|
||||||
|
import psycopg2
|
||||||
|
from psycopg2.extras import RealDictCursor
|
||||||
|
from psycopg2.pool import ThreadedConnectionPool
|
||||||
|
|
||||||
|
|
||||||
class DatabaseClient:
|
class DatabaseClient:
|
||||||
|
|||||||
+8
-5
@@ -1,12 +1,15 @@
|
|||||||
import os
|
import os
|
||||||
import serpapi
|
|
||||||
from SPARC import config
|
|
||||||
import re
|
import re
|
||||||
import pdfplumber # pip install pdfplumber
|
|
||||||
import requests
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
from SPARC.types import Patents, Patent
|
|
||||||
|
import pdfplumber # pip install pdfplumber
|
||||||
|
import requests
|
||||||
|
import serpapi
|
||||||
|
|
||||||
|
from SPARC import config
|
||||||
|
from SPARC.types import Patent, Patents
|
||||||
|
|
||||||
|
|
||||||
class SERP:
|
class SERP:
|
||||||
def query(company: str, days_back: int = None) -> Patents:
|
def query(company: str, days_back: int = None) -> Patents:
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
[lint]
|
||||||
|
select = ["E", "F", "I"]
|
||||||
|
ignore = [
|
||||||
|
"E501", # line too long (handled by formatter)
|
||||||
|
]
|
||||||
|
|
||||||
|
[lint.per-file-ignores]
|
||||||
|
"tests/*" = ["E402", "F841"] # allow import not at top of file, unused vars (mocks) in tests
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
"""Tests for the high-level company analyzer orchestration."""
|
"""Tests for the high-level company analyzer orchestration."""
|
||||||
|
|
||||||
|
from unittest.mock import MagicMock, Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import Mock, patch, call, MagicMock
|
|
||||||
from SPARC.analyzer import CompanyAnalyzer
|
from SPARC.analyzer import CompanyAnalyzer
|
||||||
from SPARC.types import Patent, Patents, CompanyAnalysisResult, BatchAnalysisResult
|
from SPARC.types import BatchAnalysisResult, Patent, Patents
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(autouse=True)
|
@pytest.fixture(autouse=True)
|
||||||
@@ -24,7 +26,7 @@ class TestCompanyAnalyzer:
|
|||||||
"""Test analyzer initialization with API key."""
|
"""Test analyzer initialization with API key."""
|
||||||
mock_llm = mocker.patch("SPARC.analyzer.LLMAnalyzer")
|
mock_llm = mocker.patch("SPARC.analyzer.LLMAnalyzer")
|
||||||
|
|
||||||
analyzer = CompanyAnalyzer(openrouter_api_key="test-key")
|
_analyzer = CompanyAnalyzer(openrouter_api_key="test-key") # noqa: F841
|
||||||
|
|
||||||
mock_llm.assert_called_once_with(api_key="test-key")
|
mock_llm.assert_called_once_with(api_key="test-key")
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -1,12 +1,13 @@
|
|||||||
"""Tests for FastAPI web service endpoints."""
|
"""Tests for FastAPI web service endpoints."""
|
||||||
|
|
||||||
import pytest
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock
|
||||||
|
|
||||||
|
import pytest
|
||||||
from fastapi.testclient import TestClient
|
from fastapi.testclient import TestClient
|
||||||
|
|
||||||
from SPARC.api import app
|
from SPARC.api import app
|
||||||
from SPARC.types import CompanyAnalysisResult, BatchAnalysisResult
|
from SPARC.types import BatchAnalysisResult, CompanyAnalysisResult
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,9 @@
|
|||||||
"""Tests for LLM analysis functionality."""
|
"""Tests for LLM analysis functionality."""
|
||||||
|
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from unittest.mock import Mock, MagicMock, patch
|
|
||||||
from SPARC.llm import LLMAnalyzer
|
from SPARC.llm import LLMAnalyzer
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,8 @@
|
|||||||
"""Tests for SERP API patent retrieval and parsing functionality."""
|
"""Tests for SERP API patent retrieval and parsing functionality."""
|
||||||
|
|
||||||
import os
|
|
||||||
import pytest
|
|
||||||
from unittest.mock import patch, Mock
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from unittest.mock import Mock
|
||||||
|
|
||||||
from SPARC.serp_api import SERP
|
from SPARC.serp_api import SERP
|
||||||
from SPARC.types import Patent
|
from SPARC.types import Patent
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user