Skip to content

Commit bf2b4bf

Browse files
Use approval tests for result image rendering
* Add approval tests * Make TODOs into a bug (#49)
1 parent 4422fc4 commit bf2b4bf

26 files changed

Lines changed: 3047 additions & 212 deletions

.github/workflows/server-pr.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ jobs:
9292
- name: Run tests
9393
run: |
9494
source .venv/bin/activate
95-
coverage run -m pytest
95+
coverage run -m pytest -rxXs --approvaltests-use-reporter='PythonNativeReporter'
9696
coverage report
9797
working-directory: ${{ env.working-directory }}
9898

server/poetry.lock

Lines changed: 170 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ itsdangerous = "^2.2.0"
2727
asgi-csrf = "^0.11"
2828
apscheduler = "^3.11.0"
2929
httpx = "^0.28.1"
30+
approvaltests = "^15.1.0"
31+
pytest-approvaltests = "^0.2.4"
3032

3133
[tool.poetry.group.dev.dependencies]
3234
mypy = "^1.5.1"

server/test/conftest.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Shared pytest fixtures."""
22

33
import json
4+
import logging
45
import os
56
from pathlib import Path
67

@@ -10,10 +11,12 @@
1011
from sqlalchemy.orm import Session, sessionmaker
1112
from testcontainers.postgres import PostgresContainer
1213

13-
from ttfd import abomination, crud
14+
from ttfd import abomination, crud, reactions
1415
from ttfd.deps import get_db
1516
from ttfd.main import app
16-
from ttfd.models import Base
17+
from ttfd.models import Base, Reaction
18+
19+
logger = logging.getLogger(__name__)
1720

1821

1922
@pytest.fixture(scope="session")
@@ -35,6 +38,7 @@ def database(setup_postgres):
3538
# 2. Find all metabolites referenced by those and add dummies
3639
metabolites = json.loads(Path("test/metabolites-test-generated.json").read_text())
3740
paths = json.loads(Path("test/paths-test-generated.json").read_text())
41+
reactions = json.loads(Path("test/reactions-test-generated.json").read_text())
3842
# 3.
3943
session_factory = sessionmaker(
4044
bind=engine,
@@ -60,6 +64,19 @@ def database(setup_postgres):
6064
categories=[],
6165
)
6266

67+
for reaction, instances in reactions.items():
68+
for num, instance in enumerate(instances):
69+
crud.insert_reaction(
70+
session,
71+
reaction,
72+
None,
73+
num,
74+
None,
75+
[],
76+
instance["left"],
77+
instance["right"],
78+
)
79+
6380
for path in paths:
6481
rp, met, br, lo, p = path.split("\n")
6582
lp = abomination.LabelingPath(
@@ -125,6 +142,7 @@ def regression_database(setup_postgres):
125142
@pytest.fixture
126143
def test_client(database: Session):
127144
"""Provide a http client to access the app in a test environment."""
145+
128146
def get_db_override():
129147
return database
130148

0 commit comments

Comments
 (0)