Esempio n. 1
0
 def test_init(self):
     expected = (Note(5), Note(7))
     seq1 = Sequence(Note(5), Note(7))
     self.assertEqual(seq1.notes, expected)
     seq2 = Sequence((Note(5), Note(7)))
     self.assertEqual(seq2.notes, expected)
     seq3 = Sequence(expected)
     self.assertEqual(seq3.notes, expected)
Esempio n. 2
0
    def test_multiple_callbacks_same_sequence(self):
        mock1 = unittest.mock.Mock()
        mock2 = unittest.mock.Mock()
        seq1 = Sequence(Note(20), Note(40), Note(60))
        seq2 = Sequence(Note(20), Note(40), Note(60))
        self.MEL.add_handler(mock1, seq1)
        self.MEL.add_handler(mock2, seq2)

        press_sequence(self.loopback, seq1)
        mock1.assert_called()
        mock2.assert_called()
Esempio n. 3
0
    def test_trigger_on_sequence(self):
        mock = unittest.mock.Mock()
        seq1 = Sequence(Note(1), Note(2), Note(3))
        self.assertFalse(self.MEL.handlers)  # Empty check
        self.MEL.add_handler(mock, seq1)

        press_sequence(self.loopback, seq1)
        mock.assert_called()
Esempio n. 4
0
 def test_chord_and_sequence(self):
     chord_mock = unittest.mock.Mock()
     sequence_mock = unittest.mock.Mock()
     c1 = Chord(Note(1), Note(2), Note(3))
     seq1 = Sequence(Note(1), Note(2), Note(3))
     self.MEL.add_handler(chord_mock, c1)
     self.MEL.add_handler(sequence_mock, seq1)
     press_chord(self.loopback, c1)  # Should trigger both
     chord_mock.assert_called()
     sequence_mock.assert_called()
Esempio n. 5
0
 def test_sequence_handlers_add_remove(self):
     mock1 = unittest.mock.Mock()
     mock2 = unittest.mock.Mock()
     seq1 = Sequence(Note(1), Note(2), Note(3))
     seq2 = Sequence(Note(4), Note(5), Note(6))
     self.assertFalse(self.MEL.handlers)  # Empty
     self.MEL.add_handler(mock1, seq1)
     self.assertTrue(self.MEL.handlers)  # Not empty
     self.MEL.clear_handlers()
     self.assertFalse(self.MEL.handlers)
     # Now test a single removal
     self.MEL.add_handler(mock1, seq1)
     self.MEL.add_handler(mock2, seq2)
     self.assertTrue(self.MEL.handlers)  # Not empty
     self.assertIn(seq1, self.MEL.handlers)
     self.assertIn(seq2, self.MEL.handlers)
     self.MEL.clear_handlers(seq1)
     self.assertNotIn(seq1, self.MEL.handlers)
     self.assertIn(seq2, self.MEL.handlers)
Esempio n. 6
0
 def test_handler_remove_class(self):
     mock1 = unittest.mock.Mock()
     mock2 = unittest.mock.Mock()
     c1 = Chord.from_ident("C4 Major")
     s1 = Sequence.from_midi_list([1, 2, 3])
     self.MEL.add_handler(mock1, c1)
     self.MEL.add_handler(mock2, s1)
     self.assertIn(c1, self.MEL.handlers)
     self.assertIn(s1, self.MEL.handlers)
     self.MEL.clear_handlers(Chord)
     self.assertNotIn(c1, self.MEL.handlers)
     self.assertIn(s1, self.MEL.handlers)
Esempio n. 7
0
 def test_eq_deque(self):
     notes = (Note(15), Note(10), Note(20))
     seq1 = Sequence(notes)
     notes_deque = collections.deque()
     notes_deque.append(Note(50))  # Fill with some junk first
     notes_deque.append(Note(50))
     notes_deque.append(Note(50))
     for n in notes:
         notes_deque.append(n)
     self.assertEqual(seq1, notes_deque)
     notes_deque.append(Note(51))
     self.assertNotEqual(seq1, notes_deque)
Esempio n. 8
0
 def test_equality(self):
     c1 = Chord(Note(69), Note(73), Note(76))
     c2 = Chord(Note(69), Note(73), Note(76))
     self.assertEqual(c1, c2)
     nl_ordered = NoteList(Note(69), Note(73), Note(76))  # Pre-ordered
     self.assertEqual(nl_ordered, c1)
     nl_unordered = NoteList(Note(73), Note(69), Note(76))  # Un-ordered
     self.assertEqual(nl_unordered, c1)
     seq1 = Sequence(Note(69), Note(73), Note(76))
     self.assertNotEqual(c1, seq1)
     # Different note list lengths should automatically be not equal
     c3 = Chord(Note(69), Note(73), Note(76), Note(100))
     self.assertNotEqual(c1, c3)
Esempio n. 9
0
    def test_decorator_sequence(self):
        mock = unittest.mock.Mock()
        self.assertFalse(self.MEL.handlers)  # Empty

        seq1 = Sequence(Note(5), Note(10), Note(15))

        @self.MEL.on_notes(seq1)
        def sub():
            mock()

        press_sequence(self.loopback, seq1)
        self.assertTrue(self.MEL.handlers)  # Not empty
        mock.assert_called()
Esempio n. 10
0
 def test_hash(self):
     seq1 = Sequence(Note(69), Note(73), Note(76))
     self.assertEqual(hash(seq1), 643362958232848345)
     self.assertEqual(Sequence.__hash__, NoteList.__hash__)
Esempio n. 11
0
 def test_eq_notelist(self):
     notes = (Note(15), Note(10), Note(20))
     seq1 = Sequence(notes)
     nl1 = NoteList(notes)
     self.assertEqual(seq1, nl1)
Esempio n. 12
0
 def test_eq_sequence(self):
     notes = (Note(15), Note(10), Note(20))
     seq1 = Sequence(notes)
     seq2 = Sequence.from_midi_list([15, 10, 20])
     self.assertEqual(seq1, seq2)
Esempio n. 13
0
 def test_eq_chord(self):
     notes = (Note(15), Note(10), Note(20))
     seq1 = Sequence(notes)
     c1 = Chord(notes)
     self.assertNotEqual(seq1, c1)  # Chord should sort the notes, while Sequence doesn't
Esempio n. 14
0
 def test_eq_tuple(self):
     notes = (Note(15), Note(10), Note(20))
     seq1 = Sequence(notes)
     self.assertEqual(seq1, notes)
Esempio n. 15
0
 def test_sequence_length(self):
     with self.assertRaises(ValueError):
         Sequence.from_midi_list(list(range(Sequence.maxlen + 1)))