Exemple #1
0
class TestLampController(unittest.TestCase):
    def setUp(self):
        self.controller = LampController()
        self.controller.create_lamp(1)
        self.controller.create_lamp(2)
        self.controller.create_colorLamp(3, 'Black')
    
    def test_set_on(self):        
        self.controller.set_on(2)
        self.assertTrue(self.controller.get_status(2))
    
    def test_test_off(self):
        self.controller.set_off(2)
        self.assertFalse(self.controller.get_status(2))
Exemple #2
0
 def run(self):
     lamp_controller = None
     try:
         lamp = self._create_objects()
         lamp_controller = LampController(lamp, self.logger)
         # MAIN LOOP
         while True:
             self._commands_controller(lamp_controller)
             time.sleep(3)  # every 3 seconds
     except Exception:
         self.logger.exception("Exception: %s", sys.exc_info()[1])
     except KeyboardInterrupt:
         self.logger.warn("Cancelled by user: %s", sys.exc_info()[1])
     finally:
         lamp_controller.switch_off()
class TestLampController(unittest.TestCase):
    def setUp(self):
        self.controller = LampController()

    def test_set_on(self):
        self.controller.set_on()
        self.assertTrue(self.controller.get_status())

    def test_test_off(self):
        self.controller.set_off()
        self.assertFalse(self.controller.get_status())
 def test_turn_on(self):
     controller = LampController()
     controller.turn_on()
     self.assertTrue(controller.is_on())
 def test_set_on(self):
     controller = LampController()
     controller.set_on()
     self.assertTrue(controller.get_status())
 def test_test_off(self):
     controller = LampController()
     controller.set_off()
     self.assertFalse(controller.get_status())
 def setUp(self):
     self.controller = LampController()
     self.controller.create_lamp(1)
     self.controller.create_lamp(2)
     self.controller.create_ColorLamp(3, 'white')
     self.controller.create_LampArray(4)
class TestLampController(unittest.TestCase):
    def setUp(self):
        self.controller = LampController()
        self.controller.create_lamp(1)
        self.controller.create_lamp(2)
        self.controller.create_ColorLamp(3, 'white')
        self.controller.create_LampArray(4)

    def test_set_on(self):        
        self.controller.set_on(2)
        self.assertTrue(self.controller.get_status(2))
    
    def test_set_off(self):
        self.controller.set_off(2)
        self.assertFalse(self.controller.get_status(2))

    def test_add_lamp(self):
        self.controller.add_lamp(1, 4)
        lista = []
        lista.append({'ID':1,'lamp':self.controller.get_lamp(1)})
        self.assertEqual(lista, self.controller.get_list(4))
    
    def test_remove_lamp(self):
        self.controller.add_lamp(1, 4)
        lista = []
        self.controller.remove_lamp(1, 4)
        self.assertEqual(lista, self.controller.get_list(4))

    def test_in_array(self):
        self.controller.add_lamp(1, 4)
        self.assertTrue(self.controller.in_array(1))
        self.assertFalse(self.controller.in_array(2))
        self.controller.remove_lamp(1, 4)
        self.assertFalse(self.controller.in_array(1))
Exemple #9
0
from controllers import LampController

if __name__ == "__main__":
    controller = LampController()
    while True:
        line = input()

        if line == "":
            exit(0)

        commands = line.split("")

        if commands[0] == "CL":
            # Create simple lamp with ID
            lamp_id = commands[1]
        elif commands[0] == "CCL":
            # Create color lamp with ID
            lamp_color = commands[1]
            lamp_id = commands[2]
        elif commands[0] == "CLA":
            # Create an empty lamp array with ID
            lamp_id = commands[1]
        elif commands[0] == "ALA":
            # Add lamp to array
            lamp_id = commands[1]
            lamp_array_id = commands[2]
        elif commands[0] == "RLA":
            # Remove lamp from array
            lamp_id = commands[1]
            lamp_array_id = commands[2]
        elif commands[0] == "S":
Exemple #10
0
from controllers import LampController

if __name__ == "__main__":
    controller = LampController()
    while True:
        line = input()

        if line == "":
            exit(0)

        if line == "ON":
            # Liga a lampada
            controller.on()
            print("Lamp status set to ON.")
        if line == "OFF":
            # Desliga a lampada
            pass
        if line == "STATUS":
            # Mostra estado da lampada
            pass
Exemple #11
0
from controllers import LampController

if __name__ == "__main__":
    controller = LampController()

    while True:
        line = input()

        if line == "":
            exit(0)

        if line == "ON":
            controller.turn_on()
            print("Lamp is on.")
        elif line == "OFF":
            controller.turn_off()
            print("Lamp is off.")
        elif line == "STATE":
            is_on = controller.is_on()  # boolean
            if is_on:
                print("Lamp is on.")
            else:
                print("Lamp is off.")
Exemple #12
0
 def setUp(self):
     self.controller = LampController()
     self.controller.create_lamp(1)
     self.controller.create_lamp(2)
     self.controller.create_colorLamp(3, 'Black')
Exemple #13
0
from controllers import LampController

if __name__ == "__main__":
    controller = LampController()
    while True:
        line = input()

        if line == "":
            exit(0)
        
        if line == "ON":
            # Liga a lampada
            controller.set_on()
            print("Lamp status set to ON.")
        if line == "OFF":
            # Desliga a lampada
            pass
        if line == "STATUS":
            # Mostra estado da lampada
            pass
 def setUp(self):
     self.controller = LampController()
Exemple #15
0
from controllers import LampController

if __name__ == "__main__":
    controller = LampController()
    while True:
        line = input()

        if line == "":
            exit(0)

        commands = line.split("")

        if commands[0] == "CL":
            # Create simple lamp with ID
            lamp_id = commands[1]
            controller.create_lamp(lamp_id)
        elif commands[0] == "CCL":
            # Create color lamp with ID
            lamp_color = commands[1]
            lamp_id = commands[2]
            controller.create_colorLamp(lamp_id, lamp_color)
        elif commands[0] == "CLA":
            # Create an empty lamp array with ID
            lamp_id = commands[1]
            controller.create_lampArray(lamp_id)
        elif commands[0] == "ALA":
            # Add lamp to array
            lamp_id = commands[1]
            lamp_array_id = commands[2]
            controller.add_lamp(lamp_id, lamp_array_id)
        elif commands[0] == "RLA":
 def test_turn_off_after_turn_on(self):
     controller = LampController()
     controller.turn_on()
     controller.turn_off()
     self.assertFalse(controller.is_on())