Skip to content

Test that str/repr of user-facing objects never raise#974

Open
yrasool wants to merge 4 commits into
idaholab:developfrom
yrasool:test-str-repr-152
Open

Test that str/repr of user-facing objects never raise#974
yrasool wants to merge 4 commits into
idaholab:developfrom
yrasool:test-str-repr-152

Conversation

@yrasool

@yrasool yrasool commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

#152 asked for unit tests so that broken custom __str__ / __repr__ methods get caught before users hit them. The original report was a Volume.__repr__ crash because _volume is not set when a Volume is parsed in the data block.

This adds one regression test that calls str() and repr() on every user-facing object of a parsed problem and asserts neither raises. That covers the problem itself, its top-level objects (input file, message, title, mode), each object collection and its members, the data-block inputs, and the cell-block modifiers. It runs over four fixtures so both the cell-block and data-block forms are exercised.

Fixes #152


General Checklist

  • I have performed a self-review of my own code.
  • The code follows the standards outlined in the development documentation.
  • I have formatted my code with black version 25 or 26.
  • I have added tests that prove my fix is effective or that my feature works (if applicable).

LLM Disclosure

  1. Are you?

    • A human user
    • A large language model (LLM), including ones acting on behalf of a human
  2. Were any large language models (LLM or "AI") used in to generate any of this code?

  • Yes
    • Model(s) used: Claude (Claude Code): Opus 4.8, Fable 5
  • No

Documentation Checklist

  • I have documented all added classes and methods.
  • For infrastructure updates, I have updated the developer's guide.
  • For significant new features, I have added a section to the getting started guide.

(Documentation checklist N/A: test-only change, no new public classes or methods.)

Additional Notes for Reviewers

Ensure that:

  • This PR fully addresses and resolves the referenced issue(s).
  • The submitted code is consistent with the merge checklist outlined here.
  • The PR covers all relevant aspects according to the development guidelines.
  • 100% coverage of the patch is achieved, or justification for a variance is given. (Patch is test code, which is excluded from coverage measurement.)

📚 Documentation preview 📚: https://montepy--974.org.readthedocs.build/en/974/

Copilot AI review requested due to automatic review settings June 23, 2026 01:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an integration regression test intended to catch crashes in user-facing __str__/__repr__ implementations (per #152) by iterating through objects from several parsed-problem fixtures and calling str()/repr() on each.

Changes:

  • Add _user_facing_objects(problem) generator to enumerate problem/collections/members/data inputs and selected cell modifiers.
  • Add parametrized integration test to assert str()/repr() calls do not raise across multiple fixtures.

Comment thread tests/test_integration.py Outdated
Copilot AI review requested due to automatic review settings June 23, 2026 01:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread tests/test_integration.py Outdated
Comment on lines +221 to +240
def _user_facing_objects(problem):
"""Yield a problem's user-facing objects: the problem, every collection
and its members, the data-block inputs, and the cell-block modifiers."""
yield problem
for collection in (
problem.cells,
problem.surfaces,
problem.materials,
problem.universes,
problem.transforms,
):
yield collection
yield from collection
# data-block inputs, e.g. ``Volume``, ``Mode`` (see the original report)
yield from problem.data_inputs
# cell-block modifier objects
for cell in problem.cells:
yield cell.importance
yield cell.fill

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added back then as well: the helper now yields input_file, message, title, and the problem level mode (skipping None for problems without a message). Also just merged develop in and added a type hint to the helper in d5dcd3d.

Add a regression test exercising `str()` and `repr()` across the
problem, its top-level objects (input file, message, title, mode),
every object collection and its members, the data-block inputs (e.g.
`Volume`), and the cell-block modifiers, over four fixtures covering
both the cell-block and data-block forms.

Guards against `__repr__` accessing an attribute that is not populated
in every context (e.g. a `Volume` parsed in the data block). The test
only asserts the result is a string, since an empty string is a valid
representation.

Fixes idaholab#152
@yrasool yrasool force-pushed the test-str-repr-152 branch from bb0c327 to b2ee4ee Compare June 23, 2026 01:47
@MicahGale

Copy link
Copy Markdown
Collaborator

@yrasool Please make sure to use the full PR template.

Copilot AI review requested due to automatic review settings June 23, 2026 02:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review is ineligible. To be eligible to request a review, you need a paid Copilot license, or your organization must enable Copilot code review.

@yrasool

yrasool commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

Please make sure to use the full PR template.

HI Michael I appreciate the feedback and I do apologize for not using the format. I did edit my description again according to format.

@MicahGale MicahGale self-assigned this Jul 9, 2026
@MicahGale MicahGale added CI/CD Continuous Integration and/or Continuous Deployment code improvement A feature request that will improve the software and its maintainability, but be invisible to users. labels Jul 9, 2026
Copilot AI review requested due to automatic review settings July 9, 2026 18:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD Continuous Integration and/or Continuous Deployment code improvement A feature request that will improve the software and its maintainability, but be invisible to users.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Test __str__ and __repr__ printing of user-facing objects

3 participants