Skip to content

TEST: Add unit tests for pyrit/common/ utilities#1600

Merged
romanlutz merged 5 commits intomicrosoft:mainfrom
romanlutz:test/common-coverage
Apr 15, 2026
Merged

TEST: Add unit tests for pyrit/common/ utilities#1600
romanlutz merged 5 commits intomicrosoft:mainfrom
romanlutz:test/common-coverage

Conversation

@romanlutz
Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for 10 previously untested utility files in pyrit/common/.

New Test Files

Source File Tests Coverage
apply_defaults.py 22 Sentinel, scope hashing, registry CRUD, decorator with inheritance
csv_helper.py 5 Read/write/roundtrip
data_url_converter.py 4 Supported formats, errors, data URL output
deprecation.py 4 Warnings with callables, classes, strings, mixed
display_response.py 5 Notebook skip, blocked response, image read/display
path.py 14 Path constants, in_git_repo, get_default_data_path
question_answer_helpers.py 3 Prompt formatting
singleton.py 3 Identity, distinct classes, init preservation
utils.py 7 combine_list, to_sha256
yaml_loadable.py 4 Basic load, from_dict dispatch, error cases

Testing

All 71 tests pass locally.

romanlutz and others added 3 commits April 11, 2026 18:04
Adds tests for 10 previously untested utility files:
- apply_defaults.py (decorator, sentinel, registry)
- csv_helper.py (read/write/roundtrip)
- data_url_converter.py (format support, encoding)
- deprecation.py (warnings for callables, classes)
- display_response.py (notebook skip, image display)
- path.py (constants, git_repo detection, default paths)
- question_answer_helpers.py (prompt formatting)
- singleton.py (identity, distinct classes)
- utils.py (combine_list, to_sha256)
- yaml_loadable.py (basic load, from_dict, errors)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts:
#	tests/unit/common/test_csv_helper.py
@rlundeen2 rlundeen2 self-assigned this Apr 14, 2026
@rlundeen2 rlundeen2 requested a review from Copilot April 14, 2026 18:59
Copy link
Copy Markdown
Contributor

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

Note

Copilot was unable to run its full agentic suite in this review.

Adds missing unit coverage for pyrit/common/ utilities by introducing new pytest tests across multiple helper modules.

Changes:

  • Added unit tests for YAML loading (YamlLoadable), hashing/list utilities, singleton metaclass behavior, and prompt construction helpers.
  • Added unit tests for filesystem/path constants/helpers, image display behavior, deprecation warnings, CSV read/write helpers, and data-url conversion.
  • Introduced fixtures and mocking for async I/O and notebook-dependent behavior.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/unit/common/test_apply_defaults.py Covers default registry behavior and @apply_defaults decorator scenarios
tests/unit/common/test_csv_helper.py Adds coverage for CSV read/write and roundtrip behavior
tests/unit/common/test_data_url_converter.py Adds coverage for supported formats, errors, and data URL output
tests/unit/common/test_deprecation.py Validates warning emission/message contents across input types
tests/unit/common/test_display_response.py Tests notebook gating, blocked content logging, and image display flow with mocks
tests/unit/common/test_path.py Tests path constants plus in_git_repo / get_default_data_path
tests/unit/common/test_question_answer_helpers.py Validates evaluation prompt formatting for Q/A entries
tests/unit/common/test_singleton.py Tests singleton identity, class separation, and init-arg preservation
tests/unit/common/test_utils.py Tests list-combining behavior and SHA256 determinism/known value
tests/unit/common/test_yaml_loadable.py Tests YAML load success paths plus missing/invalid file error behavior

Comment thread tests/unit/common/test_path.py Outdated
Comment thread tests/unit/common/test_display_response.py Outdated
Comment thread tests/unit/common/test_singleton.py Outdated
Comment thread tests/unit/common/test_yaml_loadable.py Outdated
Copy link
Copy Markdown
Contributor

@rlundeen2 rlundeen2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the copilot review suggestions, but no blockers!

romanlutz and others added 2 commits April 15, 2026 11:33
- test_path: Assert is_absolute() instead of exists() for CI stability
- test_display_response: Patch display at module namespace instead of builtins
- test_singleton: Use autouse fixture for cleanup instead of inline cleanup
- test_yaml_loadable: Use Path() instead of string literal for consistency

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@romanlutz romanlutz merged commit 0d65999 into microsoft:main Apr 15, 2026
35 checks passed
@romanlutz romanlutz deleted the test/common-coverage branch April 15, 2026 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants