mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-04-28 23:57:32 -05:00
Fix test imports to use rock solid foundation approach
- Update all test files to import from tinytorch.core.* instead of relative paths - Consistent with rock solid foundation principle - Tests now use stable package imports, not local module imports - Ensures tests validate the actual exported package functionality - Aligns with production usage patterns
This commit is contained in:
@@ -1,18 +1,15 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Tests for the setup module using pytest.
|
||||
Test suite for the setup module.
|
||||
This tests the student implementations to ensure they work correctly.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import numpy as np
|
||||
import sys
|
||||
import os
|
||||
from pathlib import Path
|
||||
from io import StringIO
|
||||
|
||||
# Add the parent directory to the path so we can import setup_dev
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
||||
from setup_dev import hello_tinytorch, add_numbers, SystemInfo, DeveloperProfile
|
||||
# Import from the main package (rock solid foundation)
|
||||
from tinytorch.core.utils import hello_tinytorch, add_numbers, SystemInfo, DeveloperProfile
|
||||
|
||||
|
||||
class TestSetupFunctions:
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
"""
|
||||
Tests for TinyTorch Tensor module.
|
||||
|
||||
Tests the core tensor functionality including creation, arithmetic operations,
|
||||
utility methods, and edge cases.
|
||||
|
||||
These tests work with the current implementation and provide stretch goals
|
||||
for students to implement additional methods.
|
||||
Test suite for the tensor module.
|
||||
This tests the student implementations to ensure they work correctly.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import numpy as np
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the parent directory to path to import tensor_dev
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
# Import from the module's development file
|
||||
# Note: This imports the instructor version with full implementation
|
||||
from tensor_dev import Tensor
|
||||
# Import from the main package (rock solid foundation)
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
def safe_numpy(tensor):
|
||||
"""Get numpy array from tensor, using .numpy() if available, otherwise .data"""
|
||||
|
||||
@@ -10,10 +10,7 @@ import os
|
||||
|
||||
# Import from the main package (rock solid foundation)
|
||||
from tinytorch.core.tensor import Tensor
|
||||
|
||||
# Import our implementations from the local module for testing
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
|
||||
from activations_dev import ReLU, Sigmoid, Tanh, Softmax
|
||||
from tinytorch.core.activations import ReLU, Sigmoid, Tanh, Softmax
|
||||
|
||||
|
||||
class TestReLU:
|
||||
|
||||
@@ -1,28 +1,17 @@
|
||||
"""
|
||||
Tests for TinyTorch Layers module.
|
||||
|
||||
Tests the core layer functionality including Dense layers, activation functions,
|
||||
and layer composition.
|
||||
|
||||
These tests work with the current implementation and provide stretch goals
|
||||
for students to implement additional features.
|
||||
Test suite for the layers module.
|
||||
This tests the student implementations to ensure they work correctly.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import numpy as np
|
||||
import sys
|
||||
import os
|
||||
|
||||
# Add the parent directory to path to import layers_dev
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
# Import from the module's development file
|
||||
# Note: This imports the instructor version with full implementation
|
||||
from layers_dev import Dense, Tensor
|
||||
|
||||
# Import activation functions from the activations module
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(__file__)), '..', '02_activations'))
|
||||
from activations_dev import ReLU, Sigmoid, Tanh
|
||||
# Import from the main package (rock solid foundation)
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.layers import Dense
|
||||
from tinytorch.core.activations import ReLU, Sigmoid, Tanh
|
||||
|
||||
def safe_numpy(tensor):
|
||||
"""Get numpy array from tensor, using .numpy() if available, otherwise .data"""
|
||||
|
||||
@@ -1,29 +1,20 @@
|
||||
"""
|
||||
Tests for TinyTorch DataLoader module.
|
||||
|
||||
Tests follow the "Build → Use → Understand" pattern:
|
||||
1. Build Dataset → Test with local test data
|
||||
2. Build DataLoader → Test batching test data
|
||||
3. Build Normalizer → Test normalizing test data
|
||||
4. Build Pipeline → Test complete test pipeline
|
||||
|
||||
These tests work with small local test data for fast, reliable testing.
|
||||
Test suite for the dataloader module.
|
||||
This tests the student implementations to ensure they work correctly.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import pytest
|
||||
import numpy as np
|
||||
import sys
|
||||
import os
|
||||
import tempfile
|
||||
import shutil
|
||||
import pickle
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
# Add the parent directory to path to import dataloader_dev
|
||||
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
|
||||
|
||||
# Import from the module's development file
|
||||
from dataloader_dev import Dataset, DataLoader, CIFAR10Dataset, Normalizer, create_data_pipeline, Tensor
|
||||
# Import from the main package (rock solid foundation)
|
||||
from tinytorch.core.tensor import Tensor
|
||||
from tinytorch.core.dataloader import Dataset, DataLoader, CIFAR10Dataset, Normalizer, create_data_pipeline
|
||||
|
||||
def safe_numpy(tensor):
|
||||
"""Get numpy array from tensor, using .data attribute"""
|
||||
|
||||
Reference in New Issue
Block a user