Bug fix/exceptions - #74
Conversation
* Move to single test workflow for PR and push reduce code duplication --------- Co-authored-by: egrace479 <e.campolongo479@gmail.com>
…nto refactoring_validation
egrace479
left a comment
There was a problem hiding this comment.
I think we should probably have process point exceptions defined instead of trying to anticipate which may be raised. @thompsonmj what do you think?
| def setUp(self): | ||
| self.buddy_check = BuddyCheck() | ||
| self.buddy_check_filename = BuddyCheck(buddy_id='filename') | ||
| self.buddy_check_id_col = BuddyCheck(buddy_id = "filename", buddy_col = "sha256") | ||
|
|
||
| self.img_source_file = tempfile.NamedTemporaryFile(delete=False, mode='w') # noqa: SIM115 | ||
| self.checksum_source_file = tempfile.NamedTemporaryFile(delete=False, mode='w') # noqa: SIM115 | ||
|
|
||
| self.img_source_file.write("""filename,checksum | ||
| image1.jpg,abc123 | ||
| image2.jpg,def456 | ||
| image3.jpg,ghi789 | ||
| """) | ||
| self.img_source_file.close() | ||
|
|
||
| self.checksum_source_file.write("""filename,md5 | ||
| image1.jpg,abc123 | ||
| image2.jpg,def456 | ||
| image3.jpg,ghi789 | ||
| """) | ||
| self.checksum_source_file.close() | ||
|
|
||
|
|
||
| def tearDown(self): | ||
| self.img_source_file.close() | ||
| self.checksum_source_file.close() | ||
| os.remove(self.img_source_file.name) |
There was a problem hiding this comment.
| os.remove(self.img_source_file.name) | |
| def setUp(self): | |
| self.buddy_check = BuddyCheck() | |
| self.buddy_check_filename = BuddyCheck(buddy_id='filename') | |
| self.buddy_check_id_col = BuddyCheck(buddy_id="filename", buddy_col="sha256") | |
| with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix=".csv") as f: | |
| f.write("""filename,checksum | |
| image1.jpg,abc123 | |
| image2.jpg,def456 | |
| image3.jpg,ghi789 | |
| """) | |
| self.img_source_file = f.name | |
| with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix=".csv") as f: | |
| f.write("""filename,md5 | |
| image1.jpg,abc123 | |
| image2.jpg,def456 | |
| image3.jpg,ghi789 | |
| """) | |
| self.checksum_source_file = f.name | |
| def tearDown(self): | |
| os.remove(self.img_source_file) | |
| os.remove(self.checksum_source_file) |
There was a problem hiding this comment.
Implemented change to remove ruff ignore
There was a problem hiding this comment.
Pull request overview
Replaces broad exception handling with targeted exceptions and updates related tests and development tooling.
Changes:
- Adds domain-specific CSV, checksum, and verification exceptions.
- Narrows download and image-processing exception handling.
- Updates tests, Ruff configuration, and CI workflows.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/cautiousrobot/exceptions.py |
Adds custom exception classes. |
src/cautiousrobot/utils.py |
Uses targeted CSV and Pillow exceptions. |
src/cautiousrobot/download.py |
Handles Requests exceptions specifically. |
src/cautiousrobot/__main__.py |
Revises CLI exception handling. |
src/cautiousrobot/__init__.py |
Adjusts method exposure assignments. |
tests/test_roll_call.py |
Cleans unused tuple values. |
tests/test_downsample.py |
Uses a specific mocked exception. |
tests/test_download.py |
Tests connection failure handling. |
tests/test_download_images.py |
Updates main-flow mocks and exception expectations. |
tests/test_buddycheck.py |
Revises temporary CSV setup. |
pyproject.toml |
Pins Ruff in development dependencies. |
.pre-commit-config.yaml |
Replaces the remote Ruff hook with a local hook. |
.gitignore |
Ignores the uv lockfile. |
.github/workflows/run-tests.yml |
Consolidates linting and test CI. |
.github/workflows/run-push-tests.yml |
Removes the redundant push workflow. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| except ChecksumError as e: | ||
| print(e) | ||
| return None, None |
| except BuddyCheckError as e: | ||
| print(e) |
| data_df = process_csv(csv_path, expected_cols) | ||
| except Exception as missing_cols: # noqa: BLE001 | ||
| sys.exit(f"{missing_cols} Please adjust inputs and try again.") | ||
| data_df = process_csv(csv_path, expected_cols) #Exception handling process_csv |
| _ = buddy_check_instance.validate_download | ||
| _ = buddy_check_instance.check_alignment |
There was a problem hiding this comment.
I think we actually want to just expose BuddyCheck, since otherwise this is instantiating it with the defaults and those methods would be fixed on what they could validate or check (i.e., only the source values could be set, not the values for the checksum DataFrame).
| - id: ruff | ||
|
|
||
| name: ruff | ||
| entry: uv run --extra dev ruff check --force-exclude |
egrace479
left a comment
There was a problem hiding this comment.
Need to also delete these instantiations
Co-authored-by: Elizabeth Campolongo <38985481+egrace479@users.noreply.github.com>
Change generic exceptions to specific exceptions defined in utils.py