class TestDummyHardwareAdapter(object): def setup_method(self): self.hardware = DummyHardwareAdapter( ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) def test__init__(self): assert self.hardware.get_position() == [0.] * 6 assert self.hardware.get_energy() == 12.39842 assert self.hardware.get_wavelength() == 1. assert (self.hardware.get_axes_names() == ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) def test__repr__(self): print self.hardware.__repr__() def testSetGetPosition(self): pass def testSetGetEnergyWavelength(self): pass def testget_position_by_name(self): self.hardware.position = [1., 2., 3., 4., 5., 6.] assert self.hardware.get_position_by_name('gamma') == 3 with pytest.raises(ValueError): self.hardware.get_position_by_name('not an angle name')
class TestDummyHardwareAdapter(unittest.TestCase): def setUp(self): self.hardware = DummyHardwareAdapter( ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) def test__init__(self): self.assertEquals(self.hardware.get_position(), [0.] * 6) self.assertEquals(self.hardware.get_energy(), 12.39842) self.assertEquals(self.hardware.get_wavelength(), 1.) self.assertEquals(self.hardware.get_axes_names(), ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) def test__repr__(self): print self.hardware.__repr__() def testSetGetPosition(self): pass def testSetGetEnergyWavelength(self): pass def testget_position_by_name(self): self.hardware.position = [1., 2., 3., 4., 5., 6.] self.assertEqual(self.hardware.get_position_by_name('gamma'), 3.) self.assertRaises(ValueError, self.hardware.get_position_by_name, 'not an angle name')
class TestDummyHardwareAdapter(object): def setup_method(self): self.hardware = DummyHardwareAdapter( ['alpha', 'delta', 'gamma', 'omega', 'chi', 'phi']) def test__init__(self): assert self.hardware.get_position() == [0.] * 6 assert self.hardware.get_energy() == 12.39842 assert self.hardware.get_wavelength() == 1. assert (self.hardware.get_axes_names() == ('alpha', 'delta', 'gamma', 'omega', 'chi', 'phi')) def test__repr__(self): print self.hardware.__repr__() def testSetGetPosition(self): pass def testSetGetEnergyWavelength(self): pass def testget_position_by_name(self): self.hardware.position = [1., 2., 3., 4., 5., 6.] assert self.hardware.get_position_by_name('gamma') == 3 with pytest.raises(ValueError): self.hardware.get_position_by_name('not an angle name') def testLowerLimitSetAndGet(self): self.hardware.set_lower_limit('alpha', -1) self.hardware.set_lower_limit('delta', -2) self.hardware.set_lower_limit('gamma', -3) with pytest.raises(ValueError): self.hardware.set_lower_limit('not an angle', 1) self.hardware.set_lower_limit('delta', None) print "Should print WARNING:" self.hardware.set_lower_limit('delta', None) assert self.hardware.get_lower_limit('alpha') == -1 assert self.hardware.get_lower_limit('gamma') == -3 def testUpperLimitSetAndGet(self): self.hardware.set_upper_limit('alpha', 1) self.hardware.set_upper_limit('delta', 2) self.hardware.set_upper_limit('gamma', 3) with pytest.raises(ValueError): self.hardware.set_upper_limit('not an angle', 1) self.hardware.set_upper_limit('delta', None) print "Should print WARNING:" self.hardware.set_upper_limit('delta', None) assert self.hardware.get_upper_limit('alpha') == 1 assert self.hardware.get_upper_limit('gamma') == 3 def testis_position_within_limits(self): self.hardware.set_upper_limit('alpha', 1) self.hardware.set_upper_limit('delta', 2) self.hardware.set_lower_limit('alpha', -1) assert self.hardware.is_position_within_limits([0, 0, 999]) assert self.hardware.is_position_within_limits([1, 2, 999]) assert self.hardware.is_position_within_limits([-1, -999, 999]) assert not self.hardware.is_position_within_limits([1.01, 0, 999]) assert not self.hardware.is_position_within_limits([0, 2.01, 999]) assert not self.hardware.is_position_within_limits([-1.01, 0, 999]) def testIsAxisWithinLimits(self): self.hardware.set_upper_limit('alpha', 1) self.hardware.set_upper_limit('delta', 2) self.hardware.set_lower_limit('gamma', -1) assert self.hardware.is_axis_value_within_limits('alpha', 0) assert self.hardware.is_axis_value_within_limits('delta', 0) assert self.hardware.is_axis_value_within_limits('gamma', 999) assert self.hardware.is_axis_value_within_limits('alpha', 1) assert self.hardware.is_axis_value_within_limits('delta', 2) assert self.hardware.is_axis_value_within_limits('gamma', 999) assert self.hardware.is_axis_value_within_limits('alpha', -1) assert self.hardware.is_axis_value_within_limits('delta', -999) assert not self.hardware.is_axis_value_within_limits('alpha', 1.01) assert not self.hardware.is_axis_value_within_limits('delta', 2.01) assert not self.hardware.is_axis_value_within_limits('alpha', 1.01)