Skip to content

Commit

Permalink
update unit test of base gen metric
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoXing1996 committed Dec 15, 2022
1 parent 52efb14 commit 6b5f0ff
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/test_evaluation/test_metrics/test_base_gen_metric.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) OpenMMLab. All rights reserved.
from unittest.mock import MagicMock, patch

import pytest
import torch
from mmengine.model import MMDistributedDataParallel

Expand Down Expand Up @@ -43,6 +44,7 @@ def test_GenMetric():
# test get_metric_sampler
model = MagicMock()
dataset = MagicMock()
dataset.__len__.return_value = 10
dataloader = MagicMock()
dataloader.batch_size = 4
dataloader.dataset = dataset
Expand All @@ -57,6 +59,11 @@ def test_GenMetric():
metric.prepare(model, dataloader)
assert metric.data_preprocessor == preprocessor

# test raise error with dataset is length than real_nums
dataset.__len__.return_value = 5
with pytest.raises(AssertionError):
metric.get_metric_sampler(model, dataloader, [metric])


def test_GenerativeMetric():
metric = ToyGenerativeMetric(11, need_cond_input=True)
Expand Down

0 comments on commit 6b5f0ff

Please sign in to comment.