Skip to content

Commit 4549a93

Browse files
committed
tests should now all pass
1 parent 708bcf5 commit 4549a93

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

api/__init__.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1+
import re as _re
2+
import sqlite3
3+
import statistics as _statistics
4+
15
from flask import Flask
26
from flask_sqlalchemy import SQLAlchemy
37
from flask_restx import Api
48
from flask_cors import CORS
59
from flask_caching import Cache
610
from flask_limiter import Limiter
711
from flask_limiter.util import get_remote_address
12+
from sqlalchemy import event
13+
from sqlalchemy.engine import Engine
814
import os
915
from pathlib import Path
1016
import tempfile
1117

1218

19+
@event.listens_for(Engine, "connect")
20+
def _register_sqlite_functions(dbapi_conn, connection_record):
21+
"""Register MySQL-compatible functions for SQLite (used in CI and local tests)."""
22+
if not isinstance(dbapi_conn, sqlite3.Connection):
23+
return
24+
25+
class _PopStdDev:
26+
"""Population standard deviation aggregate (equivalent to MySQL STD())."""
27+
28+
def __init__(self):
29+
self._vals = []
30+
31+
def step(self, value):
32+
if value is not None:
33+
self._vals.append(float(value))
34+
35+
def finalize(self):
36+
if len(self._vals) < 2:
37+
return None
38+
return _statistics.pstdev(self._vals)
39+
40+
dbapi_conn.create_aggregate("std", 1, _PopStdDev)
41+
42+
def _regexp_replace(string, pattern, replacement):
43+
if string is None:
44+
return None
45+
return _re.sub(pattern, replacement, string)
46+
47+
dbapi_conn.create_function("regexp_replace", 3, _regexp_replace)
48+
49+
1350
def create_app():
1451
"""Initialize the app factory based on the official Flask documentation"""
1552
bar_app = Flask(__name__)

api/resources/gene_expression.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,6 @@
4747
class GeneExpression(Resource):
4848
def get(self, database, gene_id):
4949
"""Retrieve expression values for a gene from a given eFP database.
50-
51-
:param database: Database name (e.g., 'klepikova', 'embryo').
52-
:param gene_id: Gene or probeset ID (e.g., 'AT1G01010', '261585_at').
53-
:returns: JSON with expression values per sample, or an error message.
54-
:rtype: flask.Response
5550
"""
5651
database = str(escape(database))
5752
gene_id = str(escape(gene_id))

config/databases/annotations_lookup.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ CREATE TABLE `agi_alias` (
4545

4646
LOCK TABLES `agi_alias` WRITE;
4747
/*!40000 ALTER TABLE `agi_alias` DISABLE KEYS */;
48-
INSERT INTO `agi_alias` VALUES ('At1g01010','ANAC001','2022-06-30'),('At1g01010','NAC001','2022-06-30'),('At1g01010','NTL10','2022-06-30'),('At1g01020','ARV1','2022-06-30');
48+
INSERT INTO `agi_alias` VALUES ('AT1G01010','ANAC001','2022-06-30'),('AT1G01010','NAC001','2022-06-30'),('AT1G01010','NTL10','2022-06-30'),('AT1G01020','ARV1','2022-06-30');
4949
/*!40000 ALTER TABLE `agi_alias` ENABLE KEYS */;
5050
UNLOCK TABLES;
5151

@@ -71,7 +71,7 @@ CREATE TABLE `at_agi_lookup` (
7171

7272
LOCK TABLES `at_agi_lookup` WRITE;
7373
/*!40000 ALTER TABLE `at_agi_lookup` DISABLE KEYS */;
74-
INSERT INTO `at_agi_lookup` VALUES ('261568_at','At1g01030','2010-12-20'),('261585_at','At1g01010','2009-07-29'),('261585_at','At1g01010','2010-12-20');
74+
INSERT INTO `at_agi_lookup` VALUES ('261568_at','AT1G01030','2010-12-20'),('261585_at','AT1G01010','2009-07-29'),('261585_at','AT1G01010','2010-12-20');
7575
/*!40000 ALTER TABLE `at_agi_lookup` ENABLE KEYS */;
7676
UNLOCK TABLES;
7777
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

tests/resources/test_fastpheno.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -202,19 +202,14 @@ def test_timeseries_tree(self):
202202
def test_timeseries_genotype_aggregate(self):
203203
"""Tests GET /fastpheno/timeseries/genotype/<tree_site_id>/<band>/aggregate"""
204204
response = self.app_client.get("/fastpheno/timeseries/genotype/619/398nm/aggregate")
205-
expected = {
206-
"wasSuccessful": True,
207-
"data": [
208-
{
209-
"flight_date": "2022-06-10T00:00:00",
210-
"flights_pk": 14,
211-
"avg_value": 0.036833333,
212-
"std_value": 0.0016526006441027672,
213-
"n_trees": 3,
214-
},
215-
],
216-
}
217-
self.assertEqual(response.json, expected)
205+
self.assertTrue(response.json["wasSuccessful"])
206+
self.assertEqual(len(response.json["data"]), 1)
207+
row = response.json["data"][0]
208+
self.assertEqual(row["flight_date"], "2022-06-10T00:00:00")
209+
self.assertEqual(row["flights_pk"], 14)
210+
self.assertEqual(row["n_trees"], 3)
211+
self.assertAlmostEqual(row["avg_value"], 0.036833333, places=7)
212+
self.assertAlmostEqual(row["std_value"], 0.0016526006441027672, places=12)
218213

219214
# With site filter
220215
response = self.app_client.get("/fastpheno/timeseries/genotype/619/398nm/aggregate?site=Pintendre")

0 commit comments

Comments
 (0)