def test_execute_wrapper_return_is_runnable(self): """ Test that the partial returned by execute_wrapper can be executed (kwargs are named correctly) """ rebin_to_dimensions_radio = mock.Mock() rebin_to_dimensions_radio.isChecked = mock.Mock(return_value=False) rebin_by_factor_radio = mock.Mock() rebin_by_factor_radio.isChecked = mock.Mock(return_value=True) factor = mock.Mock() factor.value = mock.Mock(return_value=0.5) mode_field = mock.Mock() mode_field.currentText = mock.Mock(return_value='reflect') execute_func = RebinFilter.execute_wrapper( rebin_to_dimensions_radio=rebin_to_dimensions_radio, rebin_by_factor_radio=rebin_by_factor_radio, factor=factor, mode_field=mode_field) images = th.generate_images() execute_func(images) self.assertEqual(rebin_to_dimensions_radio.isChecked.call_count, 1) self.assertEqual(rebin_by_factor_radio.isChecked.call_count, 1) self.assertEqual(factor.value.call_count, 1) self.assertEqual(mode_field.currentText.call_count, 1)
def test_execute_argument_order(self, ps_mock): images = th.generate_images() mode = 'reflect' cores = 4 progress_mock = mock.Mock() RebinFilter.filter_func(images=images, mode=mode, cores=cores, progress=progress_mock) ps_mock.execute.assert_called_once_with( partial_func=ps_mock.create_partial.return_value, num_operations=images.data.shape[0], cores=cores, msg="Applying Rebin", progress=progress_mock)
def test_not_executed_rebin_zero(self): images = th.generate_images() mode = 'reflect' val = 0 result = RebinFilter.filter_func(images, val, mode) npt.assert_equal(result, images)
def do_execute_xy(self, val=(512, 512)): images = th.generate_images(automatic_free=False) mode = 'reflect' expected_x = int(val[0]) expected_y = int(val[1]) result = RebinFilter.filter_func(images, rebin_param=val, mode=mode) npt.assert_equal(result.data.shape[1], expected_x) npt.assert_equal(result.data.shape[2], expected_y) images.free_memory()
def do_execute_xy(self, is_parallel: bool, val=(512, 512)): if is_parallel: images = th.generate_images((15, 8, 10)) else: images = th.generate_images() mode = 'reflect' expected_x = int(val[0]) expected_y = int(val[1]) result = RebinFilter.filter_func(images, rebin_param=val, mode=mode) npt.assert_equal(result.data.shape[1], expected_x) npt.assert_equal(result.data.shape[2], expected_y)
def do_execute_uniform(self, val=2.0, dtype=np.float32): images = th.generate_images(dtype=dtype) mode = 'reflect' expected_x = int(images.data.shape[1] * val) expected_y = int(images.data.shape[2] * val) result = RebinFilter.filter_func(images, val, mode) npt.assert_equal(result.data.shape[1], expected_x) npt.assert_equal(result.data.shape[2], expected_y) self.assertEqual(images.data.dtype, dtype) self.assertEqual(result.data.dtype, dtype)
def test_memory_change_acceptable(self): """ This filter will increase the memory usage as it has to allocate memory for the new resized shape """ images = th.generate_images() mode = 'reflect' # This about doubles the memory. Value found from running the test val = 100. expected_x = int(images.data.shape[1] * val) expected_y = int(images.data.shape[2] * val) cached_memory = get_memory_usage_linux(kb=True)[0] result = RebinFilter.filter_func(images, val, mode) self.assertLess(get_memory_usage_linux(kb=True)[0], cached_memory * 2) npt.assert_equal(result.data.shape[1], expected_x) npt.assert_equal(result.data.shape[2], expected_y)