Exemple #1
0
    def __init__(self, name, adress):
        """
        Parameters
        ----------
        name : string
            DESCRIPTION : It is the name of the train
        adress : int
            DESCRIPTION This is the address on which it was programmed
        biais_id : int
            DESCRIPTION Allows you to choose which servomotor will be used
        Returns
        -------
        None.

        """
        self.name = name
        self.adress = adress
        self.biais_id = 1

        if not isinstance(self.biais_id, int):
            raise TypeError("biais_id must be an int but got " +
                            str(self.biais_id))
        if self.biais_id not in [1, 2]:
            raise ValueError("biais_id must be an 1 or 2 but got " +
                             str(self.biais_id))
        if not isinstance(name, str):
            raise TypeError(" name must be a str but got " + str(name))
        if not isinstance(adress, int):
            raise TypeError("adress must be an integer but got  " +
                            str(adress))
        #if adress not in range(101, 126):
        #raise RuntimeError("""The address must be between 101 and 125 but got """+str(adress))

        self.dccobject = DCCObject(name, adress)
 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 #4
0
 def __init__(self, name, adress):
     """ this function takes a name and an address (an integer # 0) as
     parameters to create a train and  register it  on the controller
     """
     if not isinstance(name, str):
         raise TypeError(" name must be a str but got " + str(name))
     if not isinstance(adress, int):
         raise TypeError("adress must be an integer but got  " +
                         str(adress))
     if adress not in range(1, 100):
         raise RuntimeError("""The address must be between 1 and 127 but
           got """ + str(adress))
     self.dccobject = DCCObject(name, adress)
Exemple #5
0
class Switch():
    """ This class is used to control Servo motors """
    def __init__(self, name, adress):
        """
        Parameters
        ----------
        name : string
            DESCRIPTION : It is the name of the train
        adress : int
            DESCRIPTION This is the address on which it was programmed
        biais_id : int
            DESCRIPTION Allows you to choose which servomotor will be used
        Returns
        -------
        None.

        """
        self.name = name
        self.adress = adress
        self.biais_id = 1

        if not isinstance(self.biais_id, int):
            raise TypeError("biais_id must be an int but got " +
                            str(self.biais_id))
        if self.biais_id not in [1, 2]:
            raise ValueError("biais_id must be an 1 or 2 but got " +
                             str(self.biais_id))
        if not isinstance(name, str):
            raise TypeError(" name must be a str but got " + str(name))
        if not isinstance(adress, int):
            raise TypeError("adress must be an integer but got  " +
                            str(adress))
        #if adress not in range(101, 126):
        #raise RuntimeError("""The address must be between 101 and 125 but got """+str(adress))

        self.dccobject = DCCObject(name, adress)

    def _get_biais(self):
        """
        Returns
        -------
        TYPE
            DESCRIPTION : Returns the current state of the switch

        """
        if self.biais_id == 1:
            return biais1, self.dccobject.f1, self.dccobject.f_light
        elif self.biais_id == 2:
            return biais2, self.dccobject.f2

    def _set_biais(self, arguments):
        """
        Parameters
        ----------
        arguments : array
        arguments[0] : int
            DESCRIPTION :  represents the num of the servo motor we would like
                           pilote
        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)
Exemple #6
0
class Train():
    """
        Train class
    """
    def __init__(self, name, adress):
        """ this function takes a name and an address (an integer # 0) as
        parameters to create a train and  register it  on the controller
        """
        if not isinstance(name, str):
            raise TypeError(" name must be a str but got " + str(name))
        if not isinstance(adress, int):
            raise TypeError("adress must be an integer but got  " +
                            str(adress))
        if adress not in range(1, 100):
            raise RuntimeError("""The address must be between 1 and 127 but
              got """ + str(adress))
        self.dccobject = DCCObject(name, adress)

    def faster(self):
        """ Increase 1 speed step"""
        self.dccobject.faster()

    def reverse(self):
        """Change the direction"""
        self.dccobject.reverse()

    def slower(self):
        """Reduce the speed"""
        self.dccobject.slower()

    def __repr__(self):
        return self.dccobject.__repr__()

    def _get_speed(self):
        """ Returns the current speed of the train """
        return self.dccobject.speed

    def _set_speed(self, new_speed):
        """ change the speed"""
        self.dccobject.speed = new_speed

    speed = property(_get_speed, _set_speed)

    def _get_f_light(self):
        """Returns the current state of fl """
        return self.dccobject.fl

    def _set_f_light(self, var):
        """ change the state of fl """
        self.dccobject.fl = var

    f_light = property(_get_f_light, _set_f_light)

    def _get_f1(self):
        """Returns the current state of f1 """
        return self.dccobject.f1

    def _set_f1(self, var):
        """ change the state of f1 """
        self.dccobject.f1 = var

    f1 = property(_get_f1, _set_f1)

    def _get_f2(self):
        """Returns the current state of f1 """
        return self.dccobject.f1

    def _set_f2(self, var):
        """ change the state of f1 """
        self.dccobject.f2 = var

    f2 = property(_get_f2, _set_f2)

    def _get_f3(self):
        """Returns the current state of f1 """
        return self.dccobject.f3

    def _set_f3(self, var):
        """ change the state of f1 """
        self.dccobject.f3 = var

    f3 = property(_get_f3, _set_f3)

    def _get_f4(self):
        """Returns the current state of f1 """
        return self.dccobject.f4

    def _set_f4(self, var):
        """ change the state of f1 """
        self.dccobject.f4 = var

    f4 = property(_get_f4, _set_f4)
 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()