Exemple #1
0
    def _validateIsInQ(self, property_name):
        ws = self.getProperty(property_name).value
        if not ws:
            return True  # Mandatory validators to take care of this. Early exit.

        targetUnit = UnitFactory.create('MomentumTransfer')
        return targetUnit.caption() == ws.getAxis(0).getUnit().caption()
Exemple #2
0
    def test_keys_returns_a_non_empty_python_list_of_unit_keys(self):
        known_units = UnitFactory.getKeys()

        self.assertEquals(type(known_units), list)
        # Check length is at least the known core units
        # but allow for others to be added
        core_units = ['Empty', 'Label', 'TOF', 'Wavelength','Energy',
                      'Energy_inWavenumber', 'dSpacing', 'MomentumTransfer',
                      'QSquared', 'DeltaE', 'DeltaE_inWavenumber', 'Momentum']
        self.assertTrue(len(core_units) <= len(known_units))

        for unit in core_units:
            self.assertTrue(unit in known_units, "%s unit not found in UnitFactory keys" % unit)
Exemple #3
0
 def test_known_unit_can_be_created(self):
     energy = UnitFactory.create("Energy")
     self.assertTrue(isinstance(energy, Unit))
Exemple #4
0
 def _get_unit_from_unit_factory(self, parameter_name: str) -> str:
     """Returns the units of a parameter if it exists in the UnitFactory."""
     if self._is_in_unit_factory(parameter_name):
         return UnitFactory.create(parameter_name).label()
     return ""
 def test_utf8_is_converted_to_unicode_object(self):
     tof = UnitFactory.Instance().create("TOF")
     unit_lbl = tof.symbol()
     self.assertTrue(isinstance(unit_lbl.utf8(), six.text_type))
     self.assertEquals(u"\u03bcs", unit_lbl.utf8())
     self.assertEquals("\mu s", unit_lbl.latex())
 def _is_in_unit_factory(parameter_name: str) -> bool:
     """Returns true of the provided parameter exists in the UnitFactory."""
     return parameter_name in UnitFactory.getKeys()
Exemple #7
0
 def test_failure_quick_conversion_failure_with_same_input(self):
     energy = UnitFactory.Instance().create("Energy")
     self.assertRaises(RuntimeError, energy.quickConversion, "Energy")
Exemple #8
0
 def test_quick_conversion_with_unit_input(self):
     energy = UnitFactory.Instance().create("Energy")
     wavelength = UnitFactory.Instance().create("Wavelength")
     factor, power = energy.quickConversion(wavelength)
     self.assertAlmostEquals(factor, 9.04456756843)
     self.assertEquals(power, -0.5)
Exemple #9
0
 def test_known_unit_can_be_created(self):
     energy = UnitFactory.create("Energy")
     self.assertTrue(isinstance(energy, Unit))