Skip to content

Instantly share code, notes, and snippets.

@carlosble
Created July 8, 2020 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlosble/acc9e97027a151ae7a3fa6ed98f2e2e9 to your computer and use it in GitHub Desktop.
Save carlosble/acc9e97027a151ae7a3fa6ed98f2e2e9 to your computer and use it in GitHub Desktop.
import unittest
from camera import Controller, Sensor, Recorder
class CameraTests(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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment