-
Notifications
You must be signed in to change notification settings - Fork 0
Add dar validator tests #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Add dar validator tests #1
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds unit tests to verify the behavior of DARValidator
.
- Introduces
tests/test_dar_validator.py
with setup/teardown for sample.dar
files. - Adds two basic test cases: one for a valid DAR and one for a malformed DAR.
Comments suppressed due to low confidence (2)
tests/test_dar_validator.py:60
- Asserting only that there is at least one error doesn't verify specific validation rules. It would be more robust to assert on expected error messages or count specific failure types to ensure the validator handles each invalid field correctly.
self.assertGreater(len(errors), 0)
tests/test_dar_validator.py:52
- No test covers the case of invalid JSON or unreadable files. Adding a test for malformed JSON syntax or a missing file would ensure the validator handles parsing errors and file I/O exceptions gracefully.
def test_validate_correct_dar(self):
with open(self.valid_file, 'w', encoding='utf-8') as f: | ||
json.dump(valid_dar, f) | ||
|
||
with open(self.invalid_file, 'w', encoding='utf-8') as f: | ||
json.dump(invalid_dar, f) | ||
|
||
def tearDown(self): | ||
os.remove(self.valid_file) | ||
os.remove(self.invalid_file) | ||
|
||
def test_validate_correct_dar(self): | ||
validator = DARValidator(self.valid_file) | ||
errors = validator.validate() | ||
self.assertEqual(errors, []) | ||
|
||
def test_validate_malformed_dar(self): | ||
validator = DARValidator(self.invalid_file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoding filenames in the working directory can lead to collisions or leftover files if a test crashes. Consider using Python's tempfile module (e.g., tempfile.NamedTemporaryFile or pytest's tmp_path) to create isolated temporary files.
with open(self.valid_file, 'w', encoding='utf-8') as f: | |
json.dump(valid_dar, f) | |
with open(self.invalid_file, 'w', encoding='utf-8') as f: | |
json.dump(invalid_dar, f) | |
def tearDown(self): | |
os.remove(self.valid_file) | |
os.remove(self.invalid_file) | |
def test_validate_correct_dar(self): | |
validator = DARValidator(self.valid_file) | |
errors = validator.validate() | |
self.assertEqual(errors, []) | |
def test_validate_malformed_dar(self): | |
validator = DARValidator(self.invalid_file) | |
self.valid_file = tempfile.NamedTemporaryFile(delete=False, suffix=".dar", mode='w', encoding='utf-8') | |
json.dump(valid_dar, self.valid_file) | |
self.valid_file.close() | |
self.invalid_file = tempfile.NamedTemporaryFile(delete=False, suffix=".dar", mode='w', encoding='utf-8') | |
json.dump(invalid_dar, self.invalid_file) | |
self.invalid_file.close() | |
def tearDown(self): | |
os.remove(self.valid_file.name) | |
os.remove(self.invalid_file.name) | |
def test_validate_correct_dar(self): | |
validator = DARValidator(self.valid_file.name) | |
errors = validator.validate() | |
self.assertEqual(errors, []) | |
def test_validate_malformed_dar(self): | |
validator = DARValidator(self.invalid_file.name) |
Copilot uses AI. Check for mistakes.
Summary
Testing
python -m unittest discover tests