1+ from __future__ import annotations
2+
13from datetime import date , datetime
24from typing import Any , Literal , TypedDict
35
6+ import test_results_parser
47from sqlalchemy .dialects .postgresql import insert
58from sqlalchemy .orm import Session
6- from test_results_parser import Testrun
79
810from database .models import (
911 DailyTestRollup ,
@@ -51,7 +53,7 @@ def modify_structures(
5153 test_instances_to_write : list [dict [str , Any ]],
5254 test_flag_bridge_data : list [dict ],
5355 daily_totals : dict [str , DailyTotals ],
54- testrun : Testrun ,
56+ testrun : test_results_parser . Testrun ,
5557 upload : Upload ,
5658 repoid : int ,
5759 branch : str | None ,
@@ -104,7 +106,7 @@ def modify_structures(
104106def generate_test_dict (
105107 test_id : str ,
106108 repoid : int ,
107- testrun : Testrun ,
109+ testrun : test_results_parser . Testrun ,
108110 flags_hash : str ,
109111 framework : str | None ,
110112) -> dict [str , Any ]:
@@ -123,7 +125,7 @@ def generate_test_dict(
123125def generate_test_instance_dict (
124126 test_id : str ,
125127 upload : Upload ,
126- testrun : Testrun ,
128+ testrun : test_results_parser . Testrun ,
127129 commit_sha : str ,
128130 branch : str | None ,
129131 repoid : int ,
@@ -142,13 +144,11 @@ def generate_test_instance_dict(
142144
143145
144146def update_daily_totals (
145- daily_totals : dict ,
147+ daily_totals : dict [ str , DailyTotals ] ,
146148 test_id : str ,
147149 duration_seconds : float | None ,
148150 outcome : Literal ["pass" , "failure" , "error" , "skip" ],
149151):
150- daily_totals [test_id ]["last_duration_seconds" ] = duration_seconds
151-
152152 # logic below is a little complicated but we're basically doing:
153153
154154 # (old_avg * num of values used to compute old avg) + new value
@@ -192,8 +192,8 @@ def create_daily_totals(
192192 daily_totals [test_id ] = {
193193 "test_id" : test_id ,
194194 "repoid" : repoid ,
195- "last_duration_seconds" : duration_seconds ,
196- "avg_duration_seconds" : duration_seconds ,
195+ "last_duration_seconds" : duration_seconds or 0.0 ,
196+ "avg_duration_seconds" : duration_seconds or 0.0 ,
197197 "pass_count" : 1 if outcome == "pass" else 0 ,
198198 "fail_count" : 1 if outcome == "failure" or outcome == "error" else 0 ,
199199 "skip_count" : 1 if outcome == "skip" else 0 ,
@@ -290,7 +290,7 @@ def write_testruns(
290290 branch_name : str ,
291291 upload : Upload ,
292292 framework : str | None ,
293- testruns : list [Testrun ],
293+ testruns : list [test_results_parser . Testrun ],
294294 ):
295295 tests_to_write : dict [str , dict [str , Any ]] = {}
296296 test_instances_to_write : list [dict [str , Any ]] = []
@@ -326,6 +326,3 @@ def write_testruns(
326326
327327 if len (test_instances_to_write ) > 0 :
328328 save_test_instances (self .db_session , test_instances_to_write )
329-
330- upload .state = "v2_persisted"
331- self .db_session .commit ()
0 commit comments