Skip to content

Add tests for additional h5py.File exceptions#1258

Merged
mhucka merged 3 commits intoquantumlib:mainfrom
mhucka:add-test-more-file-exceptions
Apr 10, 2026
Merged

Add tests for additional h5py.File exceptions#1258
mhucka merged 3 commits intoquantumlib:mainfrom
mhucka:add-test-more-file-exceptions

Conversation

@mhucka
Copy link
Copy Markdown
Contributor

@mhucka mhucka commented Apr 6, 2026

This adds tests for a couple of exceptions that were not yet covered.

(Tests generated with the help of Jules.)

This adds tests for a couple of exceptions that were not yet covered.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds unit tests to verify the exception handling of the get_from_file method in the MolecularData class. The new test cases use mocking to simulate KeyError and IOError scenarios, ensuring the method returns None as expected. I have no feedback to provide.

@mhucka mhucka requested review from mpharrigan and ncrubin April 6, 2026 05:25
@mpharrigan
Copy link
Copy Markdown
Collaborator

What's Jules?

Copy link
Copy Markdown
Collaborator

@mpharrigan mpharrigan left a comment

Choose a reason for hiding this comment

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

it's strange that the desired behavior under test is to swallow the bad inputs and errors and just return None, but if this is for test coverage then ok

@mhucka
Copy link
Copy Markdown
Contributor Author

mhucka commented Apr 8, 2026

What's Jules?

It is jules.google.com

@mhucka
Copy link
Copy Markdown
Contributor Author

mhucka commented Apr 8, 2026

it's strange that the desired behavior under test is to swallow the bad inputs and errors and just return None, but if this is for test coverage then ok

I'm not sure if I understand, but it might worth noting that get_from_file() returns None for these exceptions. The test here is basically "if h5py.File raises these two exceptions, does execution inside get_from_file() go down the expected paths?".

        try:
            with h5py.File("{}.hdf5".format(self.filename), "r") as f:
                data = f[property_name][...]
        except KeyError:
            data = None
        except IOError:
            data = None
        return data

I'm not sure how else to cover the two paths except to fake an exception and check that data = None. Maybe I'm missing something?

@mhucka mhucka requested a review from mpharrigan April 8, 2026 01:33
@mhucka mhucka merged commit 41e01cf into quantumlib:main Apr 10, 2026
24 checks passed
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.

2 participants