Skip to content

Commit

Permalink
CU-8694gzbn3: Add debug output when running k-fold tests to see where…
Browse files Browse the repository at this point in the history
… it may be stalling
  • Loading branch information
mart-r committed May 14, 2024
1 parent abd8d0b commit 03531da
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/stats/test_kfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,35 @@
from .helpers import MCTExportPydanticModel, nullify_doc_names_proj_ids


# TODO: REMOVE BELOW
def debug_print_test_names(cls):
class Wrapper(cls):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.debug_wrap_test_methods()

def debug_wrap_test_methods(self):
for name in dir(self):
attr = getattr(self, name)
if callable(attr) and not name.startswith("__"):
setattr(self, name, debug_print_test_name(attr))

def debug_print_test_name(func):
def wrapper(*args, **kwargs):
if func.__name__ == 'wrapper':
pass
elif func.__name__.startswith("test_"):
print("Running test method:", func.__name__, 'in', cls.__name__)
else:
print("Running non-test method:", func.__name__, 'in', cls.__name__)
return func(*args, **kwargs)
return wrapper

return Wrapper
# TODO: REMOVE ABOVE


@debug_print_test_names
class MCTExportTests(unittest.TestCase):
EXPORT_PATH = os.path.join(os.path.dirname(__file__), "..",
"resources", "medcat_trainer_export.json")
Expand All @@ -29,6 +58,7 @@ def assertIsMCTExport(self, obj):
self.assertIsInstance(model, MCTExportPydanticModel)


@debug_print_test_names
class KFoldCreatorTests(MCTExportTests):
K = 3
USE_ANNOTATIONS = False
Expand Down Expand Up @@ -116,6 +146,7 @@ class KFoldCreatorNewExportAnnsTests(KFoldCreatorNewExportTests):
USE_ANNOTATIONS = True


@debug_print_test_names
class KFoldCATTests(MCTExportTests):
_names = ['fps', 'fns', 'tps', 'prec', 'rec', 'f1', 'counts', 'examples']
EXPORT_PATH = NEW_EXPORT_PATH
Expand Down Expand Up @@ -143,6 +174,7 @@ def assertDictsAlmostEqual(self, d1: Dict[str, Union[int, float]], d2: Dict[str,
self.assertAlmostEqual(v1, v2, places=tol)


@debug_print_test_names
class KFoldStatsConsistencyTests(KFoldCATTests):

def test_mct_export_valid(self):
Expand All @@ -157,6 +189,7 @@ def test_stats_consistent(self):
self.assertEqual(stats1, stats2)


@debug_print_test_names
class KFoldMetricsTests(KFoldCATTests):
USE_ANNOTATIONS = False

Expand All @@ -176,6 +209,7 @@ class KFoldPerAnnsMetricsTests(KFoldMetricsTests):
USE_ANNOTATIONS = True


@debug_print_test_names
class KFoldDuplicatedTests(KFoldCATTests):
COPIES = 3

Expand Down

0 comments on commit 03531da

Please sign in to comment.