Skip to content

Commit 6bdfb68

Browse files
added test for autolabel_metadata
1 parent 3d78f83 commit 6bdfb68

2 files changed

Lines changed: 43 additions & 1 deletion

File tree

t4_devkit/schema/tables/autolabel_metadata.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def to_autolabel_model(x) -> list[AutolabelModel] | None:
4444
return None
4545
if isinstance(x, list):
4646
return [AutolabelModel(**model) if isinstance(model, dict) else model for model in x]
47-
return x
47+
raise TypeError("Input must be None or a list of [dicts or AutolabelModel] instances.")
4848

4949

5050
@define(slots=False)
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import pytest
2+
from t4_devkit.schema.tables.autolabel_metadata import AutolabelModel, AutolabelMixin
3+
4+
5+
class TestAutolabelModel:
6+
"""Test cases for AutolabelModel class that are not covered elsewhere."""
7+
8+
def test_to_autolabel_model_type_error(self):
9+
"""Test to_autolabel_model raises TypeError for invalid input."""
10+
with pytest.raises(TypeError, match="Input must be None or a list of \\[dicts or AutolabelModel\\] instances."):
11+
AutolabelModel.to_autolabel_model("invalid_input")
12+
13+
def test_to_autolabel_model_type_error_with_dict(self):
14+
"""Test to_autolabel_model raises TypeError when input is a dict instead of list."""
15+
with pytest.raises(TypeError, match="Input must be None or a list of \\[dicts or AutolabelModel\\] instances."):
16+
AutolabelModel.to_autolabel_model({"name": "model1", "score": 0.8})
17+
18+
def test_to_autolabel_model_type_error_with_number(self):
19+
"""Test to_autolabel_model raises TypeError when input is a number."""
20+
with pytest.raises(TypeError, match="Input must be None or a list of \\[dicts or AutolabelModel\\] instances."):
21+
AutolabelModel.to_autolabel_model(123)
22+
23+
24+
class TestAutolabelMixin:
25+
"""Test cases for AutolabelMixin class that are not covered elsewhere."""
26+
27+
def test_autolabel_mixin_error_automatic_true_no_metadata(self):
28+
"""Test AutolabelMixin raises TypeError when automatic_annotation=True but autolabel_metadata=None."""
29+
with pytest.raises(TypeError, match="autolabel_metadata must be provided when automatic_annotation is True"):
30+
AutolabelMixin(automatic_annotation=True, autolabel_metadata=None)
31+
32+
def test_autolabel_mixin_error_automatic_false_with_metadata(self):
33+
"""Test AutolabelMixin raises TypeError when automatic_annotation=False but autolabel_metadata is provided."""
34+
models = [AutolabelModel(name="test_model", score=0.8)]
35+
with pytest.raises(TypeError, match="autolabel_metadata must be None when automatic_annotation is False"):
36+
AutolabelMixin(automatic_annotation=False, autolabel_metadata=models)
37+
38+
def test_autolabel_mixin_error_default_automatic_with_metadata(self):
39+
"""Test AutolabelMixin raises TypeError when default automatic_annotation=False but autolabel_metadata is provided."""
40+
models = [AutolabelModel(name="test_model", score=0.8)]
41+
with pytest.raises(TypeError, match="autolabel_metadata must be None when automatic_annotation is False"):
42+
AutolabelMixin(autolabel_metadata=models)

0 commit comments

Comments
 (0)