This directory contains unit tests for the Auto Link Obsidian project.
You can run all tests using the test runner script at the project root:
python run_tests.py
Or you can run individual test files directly:
python -m tests.test_utils
python -m tests.test_semantic_linker
The tests are organized as follows:
test_utils.py
: Tests for utility functions in utils.pytest_semantic_linker.py
: Tests for semantic_linker.py including frontmatter extraction and embedding functions
When adding new tests:
- Create a new file named
test_<module_name>.py
for the module you're testing - Follow the unittest framework pattern:
- Import unittest and the module being tested
- Create a class that extends unittest.TestCase
- Write methods that start with 'test_' to test individual functions
- Use assertions to validate expected behavior
- Consider using mocks for external dependencies like API calls
- Ensure your tests are isolated and don't depend on external state
The goal is to achieve high test coverage for all critical components:
- Utility functions
- Parsing and content manipulation
- Semantic linking logic
- Embedding generation and handling
- Caching mechanisms
- Error handling
Here's a simple example of a test:
def test_generate_note_hash(self):
"""Test generating a content hash."""
content1 = "Test content"
content2 = "Test content"
content3 = "Different content"
hash1 = utils.generate_note_hash(content1)
hash2 = utils.generate_note_hash(content2)
hash3 = utils.generate_note_hash(content3)
self.assertEqual(hash1, hash2) # Same content should have same hash
self.assertNotEqual(hash1, hash3) # Different content should have different hash