def test_f3_with_invalid_parameter(self): """Test that the f3 function return an error when an invalid parameter is given""" with self.assertRaises(TypeError): DCCObject("DCC4", 4) dcc_object.start() DCCObject("DCC4", 4).f3 = "jcoe*z^n " dcc_object.stop()
def test_set_speed_with_invalid_parameter(self): """ Test that the set_speed function return an error when inavlid parameter is given""" with self.assertRaises(TypeError): DCCObject("DCC3", 3) dcc_object.start() DCCObject("DCC3", 3).speed = "gas" dcc_object.stop()
class TestTrain(unittest.TestCase): dcc_object.start() def test_init_with_invalid_adress(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(TypeError): dcc_trains.Train("DCC1", "ad") def test_init_with_invalid_name(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(TypeError): dcc_trains.Train(41, 5) def test_init_with_valid_adress_name(self): """ Test that the init function works when a correct adress and name are given""" dcc_trains.Train("DCC4", 4) def test_set_speed_with_invalid_parameter(self): """ Test that the set_speed function return an error when inavlid parameter is given""" with self.assertRaises(TypeError): dcc_trains.Train("DCC3", 3).speed = "gas" def test_set_speed_with_valid_parameter(self): """ Test that the set_speed function work when a valid parameter is given""" dcc_trains.Train("DCC6", 6).speed = 10 def test_f_light_with_valid_parameter(self): """Test that the fl function work when a valid parameter is given""" dcc_trains.Train("DCC4", 4).fl = True def test_f_light_with_invalid_parameter(self): """Test that the fl function return an error when an invalid parameter is given""" with self.assertRaises(TypeError): dcc_trains.Train("DCC4", 4).f_light = 5.6 def test_f1_with_invalid_parameter(self): """Test that the f1 function return an error when an invalid parameter is given""" with self.assertRaises(TypeError): dcc_trains.Train("DCC4", 4).f1 = "hzdlu" def test_f1_with_valid_parameter(self): """Test that the f1 function work when a valid parameter is given""" dcc_trains.Train("DCC4", 4).f1 = False def test_f2_with_valid_parameter(self): """Test that the f2 function work when a valid parameter is given""" dcc_trains.Train("DCC4", 4).f2 = False def test_f2_with_invalid_parameter(self): """Test that the f2 function return an error when an invalid parameter is given""" with self.assertRaises(TypeError): dcc_trains.Train("DCC4", 4).f2 = 6 def test_f3_with_invalid_parameter(self): """Test that the f3 function return an error when an invalid parameter is given""" with self.assertRaises(TypeError): dcc_trains.Train("DCC8", 8).f2 = " /" dcc_object.stop()
class TestSwitch(unittest.TestCase): dcc_object.start() def test_init_with_invalid_adress(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(TypeError): dcc_switches.Switch("DCC1", "ad", 1) def test_init_with_invalid_name(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(TypeError): dcc_switches.Switch(41, 5, 2) def test_init_with_invalid_biais_id(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(TypeError): dcc_switches.Switch("DCC3", "3", "c") def test_init_with_invalid_biais_id(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(ValueError): dcc_switches.Switch("DCC3", "3", 5) #def test_init_with_adress_out_of_range(self): #"""Check that init returns an error when entering an invalid parameter""" #with self.assertRaises(RuntimeError): #dcc_switches.Switch("DCC5", 5) def test_init_with_valid_adress_parameters(self): """ Test that the init function works when a correct adress name and biais_id are given""" dcc_switches.Switch("DCC3", 3, 1) def test_biais_with_valid_parameter(self): """Test that the fl function work when a valid parameter is given""" dcc_switches.Switch("DCC3", 3, 2).biais = True def test_biais_with_invalid_state_parameter(self): """Test that the fl function return an error when an invalid parameter is given""" with self.assertRaises(TypeError): dcc_switches.Switch("DCC3", 3, 2).biais = "j zxa" dcc_object.stop()
from speedlib.dcc import dcc_object, dcc_switches from speedlib.dcc.dcc_object import DCCObject from speedlib.dcc .dcc_switches import Switch # Create the DCC controller with the RPi encoder, Create a switch (args: Name, DCC Address, biais_id) # and Register locos on the controller S = Switch("DCC",3) dcc_object.start() #Start the controller. Removes brake signal print(S.biais) S.biais = [dcc_switches.biais1, True] #change the state of the biais S.biais = [dcc_switches.biais2, True] S.biais = [dcc_switches.biais1, True] dcc_object.stop()
arguments[1] : bool DESCRIPTION : change the state of the switch Returns ------- None. """ self.biais_id = arguments[0] if not isinstance(arguments[1], bool): raise TypeError(" var must me a boolean but got " + str(arguments[1])) if self.biais_id == 1: self.dccobject.f1 = arguments[1] self.dccobject.f_light = arguments[1] elif self.biais_id == 2: self.dccobject.f2 = arguments[1] self.dccobject.reverse() biais = property(_get_biais, _set_biais) if __name__ == "__main__": S = Switch("DCC3", 3) dcc_object.start() S.biais = [biais1, True] S.biais = [biais1, False] dcc_object.stop()
def test_f3_with_valid_parameter(self): """Test that the f3 function work when a valid parameter is given""" DCCObject("DCC4", 4) dcc_object.start() DCCObject("DCC4", 4).f3 = True dcc_object.stop()
def test_init_with_invalid_adress(self): """Check that init returns an error when entering an invalid parameter""" with self.assertRaises(TypeError): DCCObject("DCC1", "ad") dcc_object.start() dcc_object.stop()
def test_set_speed_with_valid_parameter(self): """ Test that the set_speed function work when a valid parameter is given""" DCCObject("DCC4", 4) dcc_object.start() DCCObject("DCC4", 4).speed = 10 dcc_object.stop()
def test_init_with_valid_adress_name(self): """ Test that the init function works when a correct adress and name are given""" DCCObject("DCC1", 1) dcc_object.start() dcc_object.stop()