Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KristopherKubicki
Copy link
Member

Summary

  • add unit tests for DARValidator

Testing

  • python -m unittest discover tests

@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 10:00
Copy link

@Copilot Copilot AI left a 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):

Comment on lines +42 to +58
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)
Copy link
Preview

Copilot AI May 27, 2025

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.

Suggested change
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant