From 614eb0cb7f52b403f8b1e618d946b47e507a9f8e Mon Sep 17 00:00:00 2001 From: Bruno Domingues Date: Mon, 20 Oct 2025 22:22:38 -0300 Subject: [PATCH] SIENTIAPDE-1255: Add unit tests for utils.split_train_test function --- tests/sientia/test_utils.py | 59 +++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/sientia/test_utils.py diff --git a/tests/sientia/test_utils.py b/tests/sientia/test_utils.py new file mode 100644 index 0000000..c2b7a8a --- /dev/null +++ b/tests/sientia/test_utils.py @@ -0,0 +1,59 @@ +from model_manager.sientia import utils + + +def test_split_train_test_default(monkeypatch): + captured_args = {} + + def fake_train_test_split(*args, **kwargs): + captured_args['args'] = args + captured_args['kwargs'] = kwargs + return ('X_train', 'X_test', 'y_train', 'y_test') + + monkeypatch.setattr(utils, 'train_test_split', fake_train_test_split) + + X = [1, 2, 3, 4] + y = [0, 1, 0, 1] + + result = utils.split_train_test(X, y) + + assert captured_args['args'] == (X, y) + assert captured_args['kwargs'] == { + 'test_size': None, + 'train_size': None, + 'random_state': None, + 'shuffle': True, + 'stratify': None, + } + assert result == ('X_train', 'X_test', 'y_train', 'y_test') + + +def test_split_train_test_with_parameters(monkeypatch): + captured_kwargs = {} + + def fake_train_test_split(*args, **kwargs): + captured_kwargs.update(kwargs) + return ('train_X', 'test_X', 'train_y', 'test_y') + + monkeypatch.setattr(utils, 'train_test_split', fake_train_test_split) + + X = [[1], [2], [3], [4]] + y = [0, 1, 0, 1] + + result = utils.split_train_test( + X, + y, + test_size=0.25, + train_size=0.75, + random_state=42, + shuffle=False, + stratify=y, + ) + + assert captured_kwargs == { + 'test_size': 0.25, + 'train_size': 0.75, + 'random_state': 42, + 'shuffle': False, + 'stratify': y, + } + assert result == ('train_X', 'test_X', 'train_y', 'test_y')