Skip to content

Commit

Permalink
test: cobertura de código
Browse files Browse the repository at this point in the history
  • Loading branch information
RWallan committed May 20, 2024
1 parent a039d0f commit 62a128e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
1 change: 0 additions & 1 deletion openiziai/fine_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def status(self) -> Optional[str]:

return self._job_status.name

# TODO: Consertar mocks para testar a propriedade
@property
def model(self) -> Optional[GPTModel]:
if self._model:
Expand Down
39 changes: 39 additions & 0 deletions tests/test_fine_tuning.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from unittest.mock import MagicMock, mock_open, patch

import pytest
from openai import OpenAI
from pydantic import ValidationError

from openiziai.fine_tuning import FineTuning
Expand Down Expand Up @@ -81,3 +82,41 @@ def test_retrieve_fine_tuned_model(fine_tuning, valid_task):
assert fine_tuning.model.task == valid_task
assert fine_tuning.model.base_model == 'gpt-3.5-turbo'
assert fine_tuning.model.created_at


def test_start_fine_tuning_without_uploaded_file(fine_tuning):
assert not fine_tuning.start()


def test_retrieve_status_without_job(fine_tuning):
assert not fine_tuning.status


def test_retrieve_model_without_completed_job(valid_task):
mock_path = MagicMock(spec=Path)
mock_path.stat.return_value.st_size = 100000
client = MagicMock(spec=OpenAI)
files_mock = MagicMock(
create=MagicMock(return_value=MagicMock(id='file-id'))
)
fine_tuning_mock = MagicMock(
jobs=MagicMock(
create=MagicMock(return_value=MagicMock(id='job-id')),
retrieve=MagicMock(
return_value=MagicMock(status='failed', fine_tuned_model=None)
),
)
)

client.files = files_mock
client.fine_tuning = fine_tuning_mock

fine_tuning = FineTuning(
client=client, train_file=mock_path, task=valid_task
)

with patch('builtins.open', mock_open(read_data='data')):
fine_tuning.upload_file_to_openai().start()

assert fine_tuning.status == 'FAILED'
assert not fine_tuning.model

0 comments on commit 62a128e

Please sign in to comment.