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()
Exemple #3
0
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()

Exemple #6
0
from speedlib.dcc import dcc_object, dcc_trains
from speedlib.dcc.dcc_object import DCCObject
from speedlib.dcc .dcc_trains import Train



train1 = Train("DCC3",3) # Create the DCC controller with the RPi encoder, Create locos (args: Name, DCC Address) and Register locos on the controller

dcc_object.start() #Start the controller. Removes brake signal

train1.speed = 5 # set the speed to 14
train1.slower() # Reduce speed by one step
train1.faster() # Increase speed by one step
train1.f_light = True # Change fl function bit and allows to light it
train1.f2 = True
print(train1) # Print train1 information
dcc_object.stop() # Stop the controller
 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()
Exemple #10
0
 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()