Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests using mocker to main.py #89

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from unittest.mock import Mock, patch

import pytest

from main import Net, trainset, transform


def test_data_loading_and_preprocessing():
"""
Test the data loading and preprocessing steps.
This test asserts that the correct transformations are applied to the dataset and that the DataLoader is created with the correct parameters.
"""
with patch("main.datasets.MNIST", new=Mock()) as mock_dataset, patch(
"main.DataLoader", new=Mock()
) as mock_dataloader:
pytest.assertTrue(mock_dataset.called)
pytest.assertEqual(mock_dataset.call_args[1]["transform"], transform)
pytest.assertTrue(mock_dataloader.called)
pytest.assertEqual(mock_dataloader.call_args[0][0], trainset)
pytest.assertEqual(mock_dataloader.call_args[1]["batch_size"], 64)
pytest.assertTrue(mock_dataloader.call_args[1]["shuffle"])


def test_model_definition():
"""
Test the model definition.
This test asserts that the model is defined correctly.
"""
with patch("main.Net", new=Mock()) as mock_model:
pytest.assertTrue(mock_model.called)
pytest.assertIsInstance(mock_model.return_value, Net)
Loading