From 9fe0b798a121d480b067fe9cb5f4b9c939e1afe8 Mon Sep 17 00:00:00 2001 From: Michal Sejak Date: Mon, 16 Dec 2024 14:02:28 +0100 Subject: [PATCH] Improved coverage, explicitly set mdformat github version --- .pre-commit-config.yaml | 2 +- tests/configs/reid.yaml | 2 +- tests/integration/test_reid.py | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c7779beb..226a18b8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,4 +20,4 @@ repos: hooks: - id: mdformat additional_dependencies: - - mdformat-gfm + - mdformat-gfm==0.3.7 diff --git a/tests/configs/reid.yaml b/tests/configs/reid.yaml index 21ca2748..c79e4f8e 100644 --- a/tests/configs/reid.yaml +++ b/tests/configs/reid.yaml @@ -15,7 +15,7 @@ model: params: loss_name: SupConLoss embedding_size: *embedding_size - cross_batch_memory_size: &memory_size 200 + cross_batch_memory_size: &memory_size 4 attached_to: GhostFaceNetsV2 metrics: diff --git a/tests/integration/test_reid.py b/tests/integration/test_reid.py index 0d006072..8094dd80 100644 --- a/tests/integration/test_reid.py +++ b/tests/integration/test_reid.py @@ -88,7 +88,9 @@ def clear_files(): @pytest.mark.parametrize("loss_name", not_class_based_losses) -def test_reid(opts: dict[str, Any], infer_path: Path, loss_name: str): +def test_available_losses( + opts: dict[str, Any], infer_path: Path, loss_name: str +): config_file = "tests/configs/reid.yaml" opts["model.losses.0.params.loss_name"] = loss_name @@ -113,3 +115,28 @@ def test_reid(opts: dict[str, Any], infer_path: Path, loss_name: str): assert len(list(infer_path.iterdir())) == 0 model.infer(view="val", save_dir=infer_path) assert infer_path.exists() + + +@pytest.mark.parametrize("loss_name", CLASS_EMBEDDING_LOSSES) +@pytest.mark.parametrize("num_classes", [-2, NUM_INDIVIDUALS]) +def test_unsupported_class_based_losses( + opts: dict[str, Any], loss_name: str, num_classes: int +): + config_file = "tests/configs/reid.yaml" + opts["model.losses.0.params.loss_name"] = loss_name + opts["model.losses.0.params.num_classes"] = num_classes + opts["model.nodes.0.params.num_classes"] = num_classes + + with pytest.raises(ValueError): + model = LuxonisModel(config_file, opts) + model.train() + + +@pytest.mark.parametrize("loss_name", ["NonExistentLoss"]) +def test_nonexistent_losses(opts: dict[str, Any], loss_name: str): + config_file = "tests/configs/reid.yaml" + opts["model.losses.0.params.loss_name"] = loss_name + + with pytest.raises(ValueError): + model = LuxonisModel(config_file, opts) + model.train()