Exemplo n.º 1
0
class CameraTestsUsingMonkeyPatchingForMocks(unittest.TestCase):
    sensor: Sensor
    recorder: Recorder
    controller: Controller

    def setUp(self) -> None:
        self.sensor = Sensor()  # mocks
        self.recorder = Recorder()  # mocks
        self.controller = Controller(self.sensor, self.recorder)
        self.called = False

    def test_asks_the_recorder_to_stop_recording_when_no_information_received_from_sensor(
            self):
        self.sensor.is_detecting_movement = lambda: False
        self.recorder.stop_recording = self.save_call

        self.controller.record_movement()

        self.assertTrue(self.called)

    def test_asks_the_recorder_to_start_recording_when_no_sensor_detects_movement(
            self):
        self.sensor.is_detecting_movement = lambda: True
        self.recorder.start_recording = self.save_call

        self.controller.record_movement()

        self.assertTrue(self.called)

    def save_call(self):
        self.called = True
Exemplo n.º 2
0
class CameraTestsUsingMonkeyPatchingForMocks(unittest.TestCase):

    sensor: Sensor
    recorder: Recorder
    controller: Controller

    def setUp(self):
        self.sensor = Sensor()
        self.recorder = Recorder()
        self.controller = Controller(self.sensor, self.recorder)
        self.called = False

    def test_asks_the_recorder_to_stop_recording_when_no_information_received_from_sensor(self):
        ###### SIMULACIÓN monkey patching
        self.sensor.is_detecting_movement = lambda : False
        self.recorder.stop_recording = self.save_call
        ###### FIN SIMULACION

        self.controller.record_movement()  # Usa ya las dependencias simuladas
        self.assertTrue(self.called)

    def test_asks_the_recorder_to_start_recording_when_sensor_detects_movement(self):
        ###### SIMULACIÓN monkey patching
        self.sensor.is_detecting_movement = lambda: True
        self.recorder.start_recording = self.save_call
        ###### FIN SIMULACION

        self.controller.record_movement()  # Usa ya las dependencias simuladas
        self.assertTrue(self.called)

    def save_call(self):
        self.called = True
Exemplo n.º 3
0
    def test_asks_the_recorder_to_start_recording_when_sensor_detects_movement(self):
        sensor = StubMovementSensor()
        recorder = SpyRecorder()
        controller = Controller(sensor, recorder)

        controller.record_movement()
        self.assertTrue(recorder.start_called)
Exemplo n.º 4
0
    def test_asks_the_recorder_to_stop_recording_when_no_information_received_from_sensor(self):
        sensor = StubNoMovementSensor()
        recorder = SpyRecorder()
        controller = Controller(sensor, recorder)

        controller.record_movement()
        self.assertTrue(recorder.stop_called)
Exemplo n.º 5
0
 def test_check_the_sensor_once_per_second(self):
     sensor = Stub(Sensor)
     recorder = Spy(Recorder)
     controller = Controller(sensor, recorder)
     # medir aqui la hora
     controller.record_movement(3)
     # volver a medir aquí la hora
     assert_that(recorder.stop_recording, called().times(3))
Exemplo n.º 6
0
    def test_asks_the_recorder_to_stop_recording_when_no_information_received_from_sensor(self):
        sensor = Stub(Sensor)
        recorder = Spy(Recorder)
        controller = Controller(sensor, recorder)

        controller.record_movement()

        assert_that(recorder.stop_recording, called())
Exemplo n.º 7
0
    def test_stops_the_recording_if_sensor_raises_an_exception(self):
        with Stub(Sensor) as sensor:
            sensor.is_detecting_movement().raises(ValueError)
        recorder = Spy(Recorder)
        controller = Controller(sensor, recorder)

        controller.record_movement()

        assert_that(recorder.stop_recording, called())
Exemplo n.º 8
0
 def setUp(self) -> None:
     self.sensor = Sensor()  # mocks
     self.recorder = Recorder()  # mocks
     self.controller = Controller(self.sensor, self.recorder)
     self.called = False
Exemplo n.º 9
0
 def setUp(self):
     self.sensor = Sensor()
     self.recorder = Recorder()
     self.controller = Controller(self.sensor, self.recorder)
     self.called = False