Skip to content
This repository was archived by the owner on Apr 30, 2026. It is now read-only.

Commit 0de3f62

Browse files
committed
Add unit tests for sdg.filterblock
This new file introduces some unit tests for the filterblock module. A previous commit introduced a bug fix to ensure that unexpected data does not cause this block to break. These tests exercise those fixes. The tests introduced here will run automatically in CI and help ensure that the problem does not reoccur. Signed-off-by: Russell Bryant <rbryant@redhat.com>
1 parent 97d3fcd commit 0de3f62

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/test_filterblock.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Standard
2+
from unittest.mock import patch
3+
import operator
4+
import unittest
5+
6+
# Third Party
7+
from datasets import Dataset, Features, Value
8+
9+
# First Party
10+
from instructlab.sdg.filterblock import FilterByValueBlock
11+
12+
13+
class TestFilterByValueBlock(unittest.TestCase):
14+
def setUp(self):
15+
self.block = FilterByValueBlock(
16+
filter_column="age",
17+
filter_value=30,
18+
operation=operator.eq,
19+
convert_dtype=int,
20+
)
21+
self.dataset = Dataset.from_dict(
22+
{"age": ["25", "30", "35", "forty", "45"]},
23+
features=Features({"age": Value("string")}),
24+
)
25+
26+
@patch("instructlab.sdg.filterblock.logger")
27+
def test_generate_mixed_types(self, mock_logger):
28+
filtered_dataset = self.block.generate(self.dataset)
29+
self.assertEqual(len(filtered_dataset), 1)
30+
self.assertEqual(filtered_dataset["age"], [30])
31+
mock_logger.error.assert_called()

0 commit comments

Comments
 (0)