Update test discovery and documentation for new module structure

- Fix CLI tool to look for tests in modules/{module}/tests/ instead of tests/
- Update test imports to use parent directory module imports
- Update Cursor rules to reflect new test structure:
  * Project structure shows tests/ subdirectory
  * Testing patterns show correct paths and import patterns
  * Development workflow shows updated test locations
- Test imports now work: from tensor_dev import Tensor
- CLI commands now find tests in correct locations

Tests are now properly organized and discoverable
This commit is contained in:
Vijay Janapa Reddi
2025-07-10 18:45:09 -04:00
parent 5a0ed75ef5
commit 3356a10495
7 changed files with 49 additions and 37 deletions

View File

@@ -1,6 +1,3 @@
---
description: Development workflow for TinyTorch, including CLI tool usage, development cycle, and module structure.
---
# TinyTorch Development Workflow
@@ -44,7 +41,7 @@ python bin/tito.py test --module tensor
- Updates package structure
3. **Test**: `python bin/tito.py test --module {module}`
- Runs module-specific tests
- Runs module-specific tests from `modules/{module}/tests/`
- Validates exported package code
- Ensures everything works end-to-end
@@ -58,6 +55,8 @@ python bin/tito.py test --module tensor
modules/{module}/{module}_dev.py → modules/{module}/{module}_dev.ipynb
tinytorch/core/{component}.py
modules/{module}/tests/test_{module}.py
```
## Module Structure
@@ -65,7 +64,12 @@ modules/{module}/{module}_dev.py → modules/{module}/{module}_dev.ipynb
Each module should be self-contained with:
- `{module}_dev.py` - Main development file (Python source)
- `{module}_dev.ipynb` - Generated notebook (auto-created)
- `test_{module}.py` - Module tests
- `README.md` - Documentation
- `README.md` - Module documentation
- `tests/` - Test directory
- `test_{module}.py` - Module tests
Students run and pass all tests locally within the module before using nbdev to export code to the tinytorch package and build/test the overall package.
Students run and pass all tests locally within the module before using nbdev to export code to the tinytorch package and build/test the overall package.

View File

@@ -62,3 +62,4 @@ This approach creates ML engineers who understand systems deeply, not just how t
- **Real implementation**: Code actually works, not just toy examples
- **Production ready**: Exports to a real Python package

View File

@@ -3,10 +3,11 @@
## Test File Structure
### Module Tests (`modules/{module}/test_{module}.py`)
### Module Tests (`modules/{module}/tests/test_{module}.py`)
- Test the educational module implementations
- Validate both student TODOs and hidden solutions
- Should work with both incomplete and complete implementations
- Import from the parent module's development file
### Package Tests (`tinytorch/tests/`)
- Test the exported package functionality
@@ -17,9 +18,9 @@
```python
# Module tests
modules/setup/test_setup.py
modules/tensor/test_tensor.py
modules/autograd/test_autograd.py
modules/setup/tests/test_setup.py
modules/tensor/tests/test_tensor.py
modules/autograd/tests/test_autograd.py
# Package tests
tinytorch/tests/test_tensor.py
@@ -30,8 +31,14 @@ tinytorch/tests/test_autograd.py
```python
import pytest
from modules.{module}.{module}_dev import ComponentName
# or from tinytorch.core.component import ComponentName
import sys
import os
# Add parent directory to path for module imports
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
# Import from the module's development file
from {module}_dev import ComponentName
class TestComponentName:
"""Test suite for ComponentName functionality."""
@@ -67,11 +74,11 @@ python bin/tito.py test --module tensor
# Test all modules
python bin/tito.py test --all
# Run package tests directly
pytest tinytorch/tests/
# Run specific test file directly
python -m pytest modules/tensor/tests/test_tensor.py -v
# Run specific test file
pytest modules/tensor/test_tensor.py -v
# Run from within module directory
cd modules/tensor && python -m pytest tests/ -v
```
## Test Categories
@@ -88,9 +95,5 @@ pytest modules/tensor/test_tensor.py -v
- Package tests ensure production readiness
- All tests should be fast and isolated
- Use descriptive test names that explain what's being tested
- All tests should be fast and isolated
- Use descriptive test names that explain what's being tested
- All tests should be fast and isolated
- Use descriptive test names that explain what's being tested
- Import from module development files, not the package (for module tests)

View File

@@ -1,7 +1,3 @@
---
alwaysApply: true
description: TinyTorch Project Structure Guide
---
# TinyTorch Project Structure Guide
@@ -40,8 +36,9 @@ Each module follows the NBDev educational pattern:
modules/{module_name}/
├── {module_name}_dev.py # Main Python source (Jupytext format)
├── {module_name}_dev.ipynb # Generated notebook (auto-created)
├── test_{module_name}.py # Tests
└── README.md # Documentation
├── README.md # Documentation
└── tests/ # Test directory
└── test_{module_name}.py # Module tests
```
## Development Workflow
@@ -52,6 +49,8 @@ modules/{module_name}/
4. **Build**: Code exports to `tinytorch/core/{component}.py`
The `#| default_exp` directive controls where code exports to in the package.
The `#| default_exp` directive controls where code exports to in the package.

View File

@@ -37,3 +37,4 @@ These preferences ensure consistency across the TinyTorch educational framework
- **Package structure**: Code exports from `modules/` to `tinytorch/` package
These preferences ensure consistency across the TinyTorch educational framework and smooth development workflow.

View File

@@ -351,8 +351,12 @@ def cmd_test(args):
import subprocess
failed_modules = []
# Count existing test files
existing_tests = [p for p in valid_modules if Path(f"tests/test_{p}.py").exists()]
# Count existing test files in modules/{module}/tests/
existing_tests = []
for module in valid_modules:
test_path = Path(f"modules/{module}/tests/test_{module}.py")
if test_path.exists():
existing_tests.append(module)
console.print(Panel(f"🧪 Running tests for {len(existing_tests)} modules",
title="Test Suite", border_style="bright_cyan"))
@@ -370,7 +374,7 @@ def cmd_test(args):
for module in existing_tests:
progress.update(task, description=f"Testing {module}...")
test_file = f"tests/test_{module}.py"
test_file = f"modules/{module}/tests/test_{module}.py"
result = subprocess.run([sys.executable, "-m", "pytest", test_file, "-v"],
capture_output=True, text=True)
@@ -395,7 +399,7 @@ def cmd_test(args):
elif args.module in valid_modules:
# Run specific module tests
import subprocess
test_file = f"tests/test_{args.module}.py"
test_file = f"modules/{args.module}/tests/test_{args.module}.py"
console.print(Panel(f"🧪 Running tests for module: [bold cyan]{args.module}[/bold cyan]",
title="Single Module Test", border_style="bright_cyan"))
@@ -433,7 +437,7 @@ def cmd_submit(args):
submit_text.append(f"📤 Submitting module: {args.module}\n\n", style="bold cyan")
submit_text.append("🚧 Submission system not yet implemented.\n\n", style="yellow")
submit_text.append("For now, make sure all tests pass with:\n", style="dim")
submit_text.append(f" python -m pytest tests/test_{args.module}.py -v", style="bold white")
submit_text.append(f" python -m pytest modules/{args.module}/tests/test_{args.module}.py -v", style="bold white")
console.print(Panel(submit_text, title="Module Submission", border_style="bright_yellow"))

View File

@@ -10,11 +10,11 @@ import os
import pytest
import numpy as np
# Add project root to path for imports
project_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
sys.path.insert(0, project_root)
# Add the parent directory to path to import tensor_dev
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
from tinytorch.core.tensor import Tensor
# Import from the module's development file
from tensor_dev import Tensor
class TestTensorCreation:
"""Test tensor creation from different data types."""