class _BaseTest(): def setup_method(self): self.mock_ubcalc = createMockUbcalc(None) self.mock_geometry = createMockDiffractometerGeometry() names = ['delta', NUNAME, 'mu', 'eta', 'chi', 'phi'] self.mock_hardware = SimpleHardwareAdapter(names) self.constraints = YouConstraintManager(self.mock_hardware) self.calc = YouHklCalculator(self.mock_ubcalc, self.mock_geometry, self.mock_hardware, self.constraints) self.mock_hardware.set_lower_limit('delta', 0) self.mock_hardware.set_upper_limit('delta', 179.999) self.mock_hardware.set_lower_limit('mu', 0) self.mock_hardware.set_lower_limit('eta', 0) self.mock_hardware.set_lower_limit('chi', -10) self.places = 11 def _configure_ub(self): ZROT = z_rotation(self.zrot * TORAD) # -PHI YROT = y_rotation(self.yrot * TORAD) # +CHI U = ZROT * YROT UB = U * self.B self.mock_ubcalc.UB = UB def _check_hkl_to_angles(self, testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected={}): print ('_check_hkl_to_angles(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() pos, virtual = self.calc.hklToAngles(hkl[0], hkl[1], hkl[2], wavelength) assert_array_almost_equal(pos.totuple(), pos_expected.totuple(), self.places) assert_second_dict_almost_in_first(virtual, virtual_expected) def _check_angles_to_hkl(self, testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected={}): print ('_check_angles_to_hkl(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() hkl, virtual = self.calc.anglesToHkl(pos, wavelength) assert_array_almost_equal(hkl, hkl_expected, self.places, note="***Test (not diffcalc!) incorrect*** : the desired settings do not map to the target hkl") assert_second_dict_almost_in_first(virtual, virtual_expected) @raises(DiffcalcException) def _check_hkl_to_angles_fails(self, *args): self._check_hkl_to_angles(*args) def case_generator(self): for case in self.cases: yield (self._check_angles_to_hkl, case.name, self.zrot, self.yrot, case.hkl, case.position, self.wavelength, {}) test_method = (self._check_hkl_to_angles_fails if case.fails else self._check_hkl_to_angles) yield (test_method, case.name, self.zrot, self.yrot, case.hkl, case.position, self.wavelength, {})
class _BaseTest(): def setup_method(self): self.mock_ubcalc = createMockUbcalc(None) self.mock_geometry = createMockDiffractometerGeometry() names = ['delta', NUNAME, 'mu', 'eta', 'chi', 'phi'] self.mock_hardware = SimpleHardwareAdapter(names) self.constraints = YouConstraintManager(self.mock_hardware) self.calc = YouHklCalculator(self.mock_ubcalc, self.mock_geometry, self.mock_hardware, self.constraints) self.mock_hardware.set_lower_limit('delta', 0) self.mock_hardware.set_upper_limit('delta', 179.999) self.mock_hardware.set_lower_limit(NUNAME, 0) self.mock_hardware.set_upper_limit(NUNAME, 179.999) self.mock_hardware.set_lower_limit('mu', 0) self.mock_hardware.set_lower_limit('eta', 0) self.mock_hardware.set_lower_limit('chi', -10) self.places = 11 def _configure_ub(self): ZROT = z_rotation(self.zrot * TORAD) # -PHI YROT = y_rotation(self.yrot * TORAD) # +CHI U = ZROT * YROT UB = U * self.B self.mock_ubcalc.UB = UB def _check_hkl_to_angles(self, testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected={}): print('_check_hkl_to_angles(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl, pos_expected, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() pos, virtual = self.calc.hklToAngles(hkl[0], hkl[1], hkl[2], wavelength) assert_array_almost_equal(pos.totuple(), pos_expected.totuple(), self.places) assert_second_dict_almost_in_first(virtual, virtual_expected) def _check_angles_to_hkl(self, testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected={}): print('_check_angles_to_hkl(%s, %.1f, %.1f, %s, %s, %.2f, %s)' % (testname, zrot, yrot, hkl_expected, pos, wavelength, virtual_expected)) self.zrot, self.yrot = zrot, yrot self._configure_ub() hkl, virtual = self.calc.anglesToHkl(pos, wavelength) assert_array_almost_equal( hkl, hkl_expected, self.places, note= "***Test (not diffcalc!) incorrect*** : the desired settings do not map to the target hkl" ) assert_second_dict_almost_in_first(virtual, virtual_expected) @raises(DiffcalcException) def _check_hkl_to_angles_fails(self, *args): self._check_hkl_to_angles(*args) def case_generator(self): for case in self.cases: yield (self._check_angles_to_hkl, case.name, self.zrot, self.yrot, case.hkl, case.position, self.wavelength, {}) test_method = (self._check_hkl_to_angles_fails if case.fails else self._check_hkl_to_angles) yield (test_method, case.name, self.zrot, self.yrot, case.hkl, case.position, self.wavelength, {})