Skip to content

Commit

Permalink
CU-86956du3q: Add usage of regression suite name from the name of the…
Browse files Browse the repository at this point in the history
… file being read
  • Loading branch information
mart-r committed Aug 19, 2024
1 parent e5db542 commit 46b66cf
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions medcat/utils/regression/checking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging
import tqdm
import datetime
import os

from pydantic import BaseModel, Field

Expand Down Expand Up @@ -285,9 +286,9 @@ class RegressionSuite:
use_report (bool): Whether or not to use the report functionality (defaults to False)
"""

def __init__(self, cases: List[RegressionCase], metadata: MetaData) -> None:
def __init__(self, cases: List[RegressionCase], metadata: MetaData, name: str) -> None:
self.cases: List[RegressionCase] = cases
self.report = MultiDescriptor(name='ALL') # TODO - allow setting names
self.report = MultiDescriptor(name=name)
self.metadata = metadata
for case in self.cases:
self.report.parts.append(case.report)
Expand Down Expand Up @@ -385,15 +386,16 @@ def __eq__(self, other: object) -> bool:
return self.cases == other.cases

@classmethod
def from_dict(cls, in_dict: dict) -> 'RegressionSuite':
def from_dict(cls, in_dict: dict, name: str) -> 'RegressionSuite':
"""Construct a RegressionChecker from a dict.
Most of the parsing is handled in RegressionChecker.from_dict.
This just assumes that each key in the dict is a name
and each value describes a RegressionCase.
Args:
in_dict (dict): The input dict
in_dict (dict): The input dict.
name (str): The name of the regression suite.
Returns:
RegressionChecker: The built regression checker
Expand All @@ -409,7 +411,7 @@ def from_dict(cls, in_dict: dict) -> 'RegressionSuite':
metadata = MetaData.unknown()
else:
metadata = MetaData.parse_obj(in_dict['meta'])
return RegressionSuite(cases=cases, metadata=metadata)
return RegressionSuite(cases=cases, metadata=metadata, name=name)

@classmethod
def from_yaml(cls, file_name: str) -> 'RegressionSuite':
Expand All @@ -425,14 +427,14 @@ def from_yaml(cls, file_name: str) -> 'RegressionSuite':
"""
with open(file_name) as f:
data = yaml.safe_load(f)
return RegressionSuite.from_dict(data)
return RegressionSuite.from_dict(data, name=os.path.basename(file_name))

@classmethod
def from_mct_export(cls, file_name: str) -> 'RegressionSuite':
with open(file_name) as f:
data = json.load(f)
converted = MedCATTrainerExportConverter(data).convert()
return RegressionSuite.from_dict(converted)
return RegressionSuite.from_dict(converted, name=os.path.basename(file_name))


class MalformedRegressionCaseException(ValueError):
Expand Down

0 comments on commit 46b66cf

Please sign in to comment.