Skip to content

Conversation

@ZackAttack614
Copy link
Collaborator

Overview

This PR adds unit test coverage for broad swaths of the HEXRD core section. It does not offer complete coverage, but is a stepping stone in the path to 100% library coverage. Upon merge, this will bring total coverage up to 67%.

The only changes to the library code itself amount to fixing which Exceptions are thrown in error cases. Previously, there were assert checks and incorrect RuntimeErrors thrown, which have been fixed for production use to ValueError and TypeError handling instead.

Affected Workflows

This PR does not affect end users, but does increase the amount of unit test coverage the HEXRD library has for developer use.

Documentation Changes

No changes to documentation, as the places where there were changes to the library itself were not documented prior. This amounts to only fixes for the Exception types that are thrown.

The _copy_input_if_needed function does not work unless it's float64. Is that a problem?
@codecov
Copy link

codecov bot commented Dec 13, 2025

Codecov Report

❌ Patch coverage is 66.03774% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.82%. Comparing base (28b0cbc) to head (62fa782).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
hexrd/core/instrument/hedm_instrument.py 10.52% 17 Missing ⚠️
hexrd/__init__.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #864       +/-   ##
===========================================
+ Coverage   56.19%   68.82%   +12.63%     
===========================================
  Files         143      144        +1     
  Lines       22069    22090       +21     
===========================================
+ Hits        12401    15203     +2802     
+ Misses       9668     6887     -2781     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

return output


# TODO: This function does not work when array or kernel are 32-bit float types.
Copy link
Collaborator

@psavery psavery Dec 15, 2025

Choose a reason for hiding this comment

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

This function was copied from astropy. It does tend to be one of the more time-consuming functions that run for things like SNIP algorithms. If astropy ever makes significant performance improvements to their code, we may want to copy it again from. Here is the latest version.

We might should avoid from deviating too far from their code, since we may rely on them for updates.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is there a good reason for us to have our own version of this? Would it not make more sense to simply use their version instead of an old copy?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think astropy has too many dependencies, and if we add them as a dependency we end up requiring all of their dependencies too.

This module was relatively stand-alone so it was easier to copy over.


@active_beam_name.setter
def active_beam_name(self, name: str):
if self._active_beam_name not in self.beam_dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch! I actually think this might fix a GUI error we've seen.

det = instr.detectors['det1']
det.tvec = np.array([0.0, 0.0, -1000.0])
instr.tvec = np.zeros(3)
type(det).pixel_area = PropertyMock(return_value=1.0)
Copy link
Collaborator

Choose a reason for hiding this comment

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

The detector's pixel_area attribute is being modified here.

Copy link
Collaborator

@psavery psavery left a comment

Choose a reason for hiding this comment

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

LGTM

@ZackAttack614
Copy link
Collaborator Author

Start to add unit tests to core, slight improvement in Exception management

@ZackAttack614 ZackAttack614 merged commit 5ab82ac into master Dec 15, 2025
10 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.

3 participants