def setUp(self): # note that because Manta and MIDISource are imported with from... # then we have to patch them in the mantaseq namespace self.manta_patch = patch('mantaseq.Manta') self.manta_patch.start() self.midi_patch = patch('mantaseq.MIDISource') self.midi_patch.start() self.time_patch = patch('time.time', side_effect = lambda: self.logical_time) self.time_patch.start() # allow the logical time of a test to be set self.logical_time = 1000 self.seq = MantaSeq() self.event_queue = [] self.seq._manta.process.side_effect = self.get_next_event self.seq._manta.set_led_pad.side_effect = self.set_led_state self.led_states = [OFF] * 48 self.seq.start()
class MockedBoundaryTest(unittest.TestCase): def setUp(self): # note that because Manta and MIDISource are imported with from... # then we have to patch them in the mantaseq namespace self.manta_patch = patch('mantaseq.Manta') self.manta_patch.start() self.midi_patch = patch('mantaseq.MIDISource') self.midi_patch.start() self.time_patch = patch('time.time', side_effect = lambda: self.logical_time) self.time_patch.start() # allow the logical time of a test to be set self.logical_time = 1000 self.seq = MantaSeq() self.event_queue = [] self.seq._manta.process.side_effect = self.get_next_event self.seq._manta.set_led_pad.side_effect = self.set_led_state self.led_states = [OFF] * 48 self.seq.start() def step_time(self, amount): self.logical_time += amount def tearDown(self): self.manta_patch.stop() self.midi_patch.stop() self.time_patch.stop() def add_sequenced_note(self, step, pad_offset, velocity): self.enqueue_step_select(step) self.enqueue_note_value_event(pad_offset, velocity) self.enqueue_step_deselect(step) self.enqueue_note_value_event(pad_offset, 0) def set_step_cc(self, step, cc_num, value): self.enqueue_step_select(step) self.enqueue_slider_value_event(cc_num-1, value) self.enqueue_step_deselect(step) def set_led_state(self, led_state, pad_num): self.led_states[pad_num] = led_state def get_next_event(self): # each element in event_queue should be a list of events to be # returned by a manta.process() call, or a single event in which # case it gets wrapped in a list before being returned if self.event_queue: event = self.event_queue.pop(0) try: # just to check whether it's iterable iter(event) return event except TypeError: return [event] else: return [] def process_queued_manta_events(self): '''Calls the MantaSeq.process() call for each queued manta message''' for i in range(len(self.event_queue)): self.seq.process() def enqueue_step_deselect(self, step_num): self.event_queue.append(PadVelocityEvent(step_num, 0)) def enqueue_step_select(self, step_num): self.event_queue.append(PadVelocityEvent(step_num, 100)) def enqueue_note_velocity_event(self, pad_offset, velocity): self.event_queue.append(PadVelocityEvent(pad_offset + 16, velocity)) def enqueue_note_value_event(self, pad_offset, value): self.event_queue.append(PadValueEvent(pad_offset + 16, value)) def enqueue_slider_value_event(self, slider_num, value): self.event_queue.append(SliderValueEvent(slider_num, True, value)) def enqueue_slider_release_event(self, slider_num): self.event_queue.append(SliderValueEvent(slider_num, False, 0xFFFF)) def enqueue_button_velocity_event(self, button_num, velocity): self.event_queue.append(ButtonVelocityEvent(button_num, velocity)) def assert_midi_note_sent(self, note, velocity): self.seq._midi_source.send.assert_any_call(make_note(note, velocity)) def assert_midi_cc_sent(self, cc_num, value): self.seq._midi_source.send.assert_any_call(make_cc(cc_num, value)) def assert_no_midi_note_sent(self): calls = self.seq._midi_source.send.mock_calls for name, args, kwargs in calls: note_tuple = args[0] if note_tuple[0] == 0x90: self.fail('Expected no MIDI Note sent, got %d, %d' % (note_tuple[1], note_tuple[2])) def assert_led_state(self, pad_num, state): self.assertEqual(self.led_states[pad_num], state)