Skip to content

Commit e203ae7

Browse files
committed
chore: lint unit tests, setup pip compiler for requirements
1 parent 982c871 commit e203ae7

File tree

15 files changed

+562
-81
lines changed

15 files changed

+562
-81
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ repos:
77
hooks:
88
- id: codespell
99
args: ["--ignore-words=codespell.txt"]
10-
exclude: '(\.svg$|data/wfu-1-metaai\.yaml)'
10+
exclude: '(\.svg$|data/wfu-1-metaai\.yaml|^requirements/)'
1111
- repo: https://github.com/pre-commit/mirrors-prettier
1212
rev: v4.0.0-alpha.8
1313
hooks:

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ FROM base AS requirements
2525
WORKDIR /dist
2626

2727
# Copy the current directory contents into the container at /app
28-
COPY requirements/prod.txt requirements.txt
28+
COPY requirements/base.txt base.txt
29+
COPY requirements/local.txt local.txt
2930

3031
# Set environment variables
3132
ENV PYTHONPATH=/dist
3233

3334
# Install any needed packages specified in requirements.txt
34-
RUN pip install --no-cache-dir -r requirements.txt
35+
RUN pip install --no-cache-dir -r base.txt
3536

3637
# Install Python dependencies for the local environment for cases where
3738
# we're going to run python unit tests in the Docker container.

app/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""Database connection and utilities for MySQL."""
33

44
from contextlib import contextmanager
5-
from typing import Any, Dict, List, Optional
5+
from typing import Any, Dict, Iterator, List, Optional
66

77
import pymysql
88

@@ -73,7 +73,7 @@ def get_connection(self) -> pymysql.Connection:
7373
raise pymysql.Error(f"Failed to connect to MySQL database: {e}")
7474

7575
@contextmanager
76-
def get_cursor(self):
76+
def get_cursor(self) -> Iterator[pymysql.cursors.DictCursor]:
7777
"""
7878
Context manager for database operations with automatic connection handling.
7979
@@ -113,7 +113,7 @@ def execute_query(self, query: str, params: Optional[tuple] = None) -> List[Dict
113113
logger.debug("Executing query: %s with params: %s", query, params)
114114
with self.get_cursor() as cursor:
115115
cursor.execute(query, params or ())
116-
return cursor.fetchall()
116+
return list(cursor.fetchall())
117117

118118
def execute_update(self, query: str, params: Optional[tuple] = None) -> int:
119119
"""

app/tests/const.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Common constants for untit tests.
4+
"""
5+
6+
import os
7+
import sys
8+
from pathlib import Path
9+
10+
11+
HERE = os.path.abspath(os.path.dirname(__file__))
12+
PROJECT_ROOT = str(Path(HERE).parent.parent)
13+
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
14+
if PYTHON_ROOT not in sys.path:
15+
sys.path.append(PYTHON_ROOT) # noqa: E402
16+
17+
__all__ = ["HERE", "PROJECT_ROOT", "PYTHON_ROOT"]

app/tests/test_agent.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,13 @@
44
"""Test application."""
55

66
# python stuff
7-
import os
8-
import sys
97
import unittest
10-
from pathlib import Path
118
from unittest.mock import patch
129

1310
from app import agent
1411
from app.agent import main # noqa: E402
1512

1613

17-
HERE = os.path.abspath(os.path.dirname(__file__))
18-
PROJECT_ROOT = str(Path(HERE).parent.parent)
19-
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
20-
if PYTHON_ROOT not in sys.path:
21-
sys.path.append(PYTHON_ROOT) # noqa: E402
22-
23-
2414
class TestApplication(unittest.TestCase):
2515
"""Test application."""
2616

app/tests/test_database.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
"""Test database connectivity."""
55

66
# python stuff
7-
import os
8-
import sys
97
import unittest
10-
from pathlib import Path
118
from unittest.mock import MagicMock, patch
129

1310
import pymysql
@@ -16,13 +13,6 @@
1613
from app.logging_config import get_logger
1714

1815

19-
HERE = os.path.abspath(os.path.dirname(__file__))
20-
PROJECT_ROOT = str(Path(HERE).parent.parent)
21-
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
22-
if PYTHON_ROOT not in sys.path:
23-
sys.path.append(PYTHON_ROOT) # noqa: E402
24-
25-
2616
logger = get_logger(__name__)
2717

2818

app/tests/test_prompt.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
"""Test prompt."""
55

66
# python stuff
7-
import os
8-
import sys
97
import unittest
10-
from pathlib import Path
118
from unittest.mock import MagicMock, patch
129

1310
import httpx
@@ -16,13 +13,6 @@
1613
from app import prompt
1714

1815

19-
HERE = os.path.abspath(os.path.dirname(__file__))
20-
PROJECT_ROOT = str(Path(HERE).parent.parent)
21-
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
22-
if PYTHON_ROOT not in sys.path:
23-
sys.path.append(PYTHON_ROOT) # noqa: E402
24-
25-
2616
class DummyResponse:
2717
def __init__(self):
2818
self.request = None

app/tests/test_stackademy.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,14 @@
44
"""Test Stackademy application."""
55

66
# python stuff
7-
import os
8-
import sys
97
import unittest
10-
from pathlib import Path
118
from unittest.mock import Mock, patch
129

1310
from app.exceptions import ConfigurationException
1411
from app.logging_config import get_logger
1512
from app.stackademy import Stackademy
1613

1714

18-
HERE = os.path.abspath(os.path.dirname(__file__))
19-
PROJECT_ROOT = str(Path(HERE).parent.parent)
20-
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
21-
if PYTHON_ROOT not in sys.path:
22-
sys.path.append(PYTHON_ROOT) # noqa: E402
23-
24-
2515
logger = get_logger(__name__)
2616

2717

app/tests/test_structured_outputs.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,12 @@
44
"""Test structured outputs."""
55

66
# python stuff
7-
import os
8-
import sys
97
import unittest
10-
from pathlib import Path
118
from unittest.mock import PropertyMock, patch
129

1310
import app.structured_outputs as so
1411

1512

16-
HERE = os.path.abspath(os.path.dirname(__file__))
17-
PROJECT_ROOT = str(Path(HERE).parent.parent)
18-
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
19-
if PYTHON_ROOT not in sys.path:
20-
sys.path.append(PYTHON_ROOT) # noqa: E402
21-
22-
2313
class TestStructuredOutputs(unittest.TestCase):
2414
"""Test structured outputs."""
2515

app/tests/test_utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,12 @@
44
"""Test utils."""
55

66
# python stuff
7-
import os
8-
import sys
97
import unittest
10-
from pathlib import Path
118
from unittest.mock import patch
129

1310
from app import utils
1411

1512

16-
HERE = os.path.abspath(os.path.dirname(__file__))
17-
PROJECT_ROOT = str(Path(HERE).parent.parent)
18-
PYTHON_ROOT = str(Path(PROJECT_ROOT).parent)
19-
if PYTHON_ROOT not in sys.path:
20-
sys.path.append(PYTHON_ROOT) # noqa: E402
21-
22-
2313
class TestUtils(unittest.TestCase):
2414
"""Test utils."""
2515

0 commit comments

Comments
 (0)