Skip to content

Commit

Permalink
Plz, hope this is the last one for code cov
Browse files Browse the repository at this point in the history
  • Loading branch information
darshdinger committed Oct 14, 2024
1 parent 351b9f9 commit fab6f90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/unit/backend/service/test_ReductionService.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,18 @@ def test_fetchReductionGroceries_creates_versions(self):
assert self.request.versions.calibration == 1
assert self.request.versions.normalization == 2

def test_reduction_with_artificial_norm_response(self):
artificial_response = ArtificialNormResponse(diffractionWorkspace="mock_diffraction_ws")
self.instance.fetchReductionGroceries = mock.Mock(return_value=artificial_response)

self.instance.dataFactoryService.calibrationExists = mock.Mock(return_value=True)
self.instance.dataFactoryService.normalizationExists = mock.Mock(return_value=True)

result = self.instance.reduction(self.request)

assert result == artificial_response
self.instance.fetchReductionGroceries.assert_called_once_with(self.request)


class TestReductionServiceMasks:
@pytest.fixture(autouse=True, scope="class")
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/meta/test_Decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ def test_stateValidationExceptionWritePerms():
assert "The following error occurred:Test Exception\n\nPlease contact your CIS." in str(excinfo.value)


def test_stateValidationExceptionNoTraceback():
exception = Exception("Test Exception without traceback")

with patch("snapred.backend.error.StateValidationException.logger") as logger_mock:
with patch("traceback.extract_tb", return_value=None):
with pytest.raises(StateValidationException) as excinfo:
raise StateValidationException(exception)

assert "Instrument State for given Run Number is invalid! (see logs for details.)" in str(excinfo.value)

logger_mock.error.assert_called_once_with("Test Exception without traceback")


@ExceptionHandler(StateValidationException)
def throwsStateException():
raise RuntimeError("I love exceptions!!! Ah ha ha!")
Expand Down

0 comments on commit fab6f90

Please sign in to comment.