-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5df55e8
commit b7993d5
Showing
8 changed files
with
61 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
"""Configuration for tests.""" | ||
pytest_plugins = [ | ||
"secmlt.tests.fixtures", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Fixtures used for testing.""" | ||
import pytest | ||
import torch | ||
from torch.utils.data import DataLoader, TensorDataset | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def data_loader() -> DataLoader[tuple[torch.Tensor]]: | ||
""" | ||
Create fake data loader. | ||
Returns | ||
------- | ||
DataLoader[tuple[torch.Tensor]] | ||
A loader with random samples and labels. | ||
""" | ||
# Create a dummy dataset loader for testing | ||
data = torch.randn(100, 3, 32, 32) | ||
labels = torch.randint(0, 10, (100,)) | ||
dataset = TensorDataset(data, labels) | ||
return DataLoader(dataset, batch_size=10) | ||
|
||
|
||
@pytest.fixture(autouse=True, scope="session") | ||
def adv_loaders() -> list[DataLoader[tuple[torch.Tensor, ...]]]: | ||
""" | ||
Create fake adversarial loaders. | ||
Returns | ||
------- | ||
list[DataLoader[Tuple[torch.Tensor, ...]]] | ||
A list of multiple loaders (with same ordered labels). | ||
""" | ||
# Create a list of dummy adversarial example loaders for testing | ||
loaders = [] | ||
adv_labels = torch.randint(0, 10, (100,)) | ||
for _ in range(3): | ||
adv_data = torch.randn(100, 3, 32, 32) | ||
adv_dataset = TensorDataset(adv_data, adv_labels) | ||
loaders.append(DataLoader(adv_dataset, batch_size=10)) | ||
return loaders |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"""Mock classes for testing.""" | ||
import torch | ||
|
||
|
||
class MockModel(torch.nn.Module): | ||
"""Mock class for torch model.""" | ||
|
||
def forward(self, x: torch.Tensor) -> torch.Tensor: | ||
"""Return random outputs for classification and add fake gradients to x.""" | ||
# Mock output shape (batch_size, 10) | ||
x.grad = torch.rand_like(x) | ||
return torch.randn(x.size(0), 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.