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 #14

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Next Next commit
feat: add tests for main.py
sweep-nightly[bot] authored Oct 12, 2023
commit 15beb04e9da043b37ef92f0d9048ee3744ee5ede
30 changes: 30 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pytest
from pytest_mock import MockerFixture
from torchvision import datasets
from torch.utils.data import DataLoader
from src import main

def test_data_loading_and_preprocessing(mocker: MockerFixture):
"""Test the data loading and preprocessing steps."""
mock_mnist = mocker.patch.object(datasets, 'MNIST')
mock_dataloader = mocker.patch.object(DataLoader, '__init__')

main.load_and_preprocess_data()

mock_mnist.assert_called_once_with('.', download=True, train=True, transform=main.transform)
mock_dataloader.assert_called_once_with(mock_mnist.return_value, batch_size=64, shuffle=True)

def test_model_definition():
"""Test the model definition."""
model = main.Net()

assert isinstance(model, main.Net)
assert isinstance(model.fc1, nn.Linear)
assert model.fc1.in_features == 784
assert model.fc1.out_features == 128
assert isinstance(model.fc2, nn.Linear)
assert model.fc2.in_features == 128
assert model.fc2.out_features == 64
assert isinstance(model.fc3, nn.Linear)
assert model.fc3.in_features == 64
assert model.fc3.out_features == 10