Add unit tests for exception handling#151
Conversation
There was a problem hiding this comment.
Code Review
This pull request unignores the tests/ directory and introduces a new test suite for the project's custom exception hierarchy. The feedback focuses on improving test accuracy by fixing a typo and directly verifying attributes, adhering to PEP 8 standards for None comparisons, and ensuring complete coverage of the exception hierarchy by adding a test for VectorStoreValidationError.
| def test_mssg_attribute_is_accessible(self): | ||
| err = XMemError("hello") | ||
| assert str(err) == "hello" |
There was a problem hiding this comment.
The test name test_mssg_attribute_is_accessible contains a typo (mssg) and the implementation redundantly checks the string representation instead of the actual message attribute. It should be updated to verify the attribute directly.
| def test_mssg_attribute_is_accessible(self): | |
| err = XMemError("hello") | |
| assert str(err) == "hello" | |
| def test_message_attribute_is_accessible(self): | |
| err = XMemError("hello") | |
| assert err.message == "hello" |
|
|
||
| def test_operation_is_none_by_default(self): | ||
| err = XMemError("message") | ||
| assert err.operation == None |
There was a problem hiding this comment.
According to PEP 8, comparisons to singletons like None should always be done with is or is not, never the equality operators.
| assert err.operation == None | |
| assert err.operation is None |
References
- Comparisons to singletons like None should always be done with 'is' or 'is not', never the equality operators. (link)
| def test_validation_error_is_not_a_vector_store_error(self): | ||
| err = ValidationError("bad input") | ||
| assert not isinstance(err, VectorStoreError) |
There was a problem hiding this comment.
The VectorStoreValidationError class is imported but not included in the hierarchy tests. It's important to verify that it correctly inherits from VectorStoreError to ensure the exception hierarchy is functioning as expected.
| def test_validation_error_is_not_a_vector_store_error(self): | |
| err = ValidationError("bad input") | |
| assert not isinstance(err, VectorStoreError) | |
| def test_vector_store_validation_error_is_caught_as_vector_store_error(self): | |
| with pytest.raises(VectorStoreError): | |
| raise VectorStoreValidationError("invalid metadata") | |
| def test_validation_error_is_not_a_vector_store_error(self): | |
| err = ValidationError("bad input") | |
| assert not isinstance(err, VectorStoreError) |
fixes #147
exception.py.