class TPlaylistMux(TestCase): def setUp(self): self.q = PlaylistModel() self.pl = PlaylistModel() self.p = NullPlayer() self.mux = PlaylistMux(self.p, self.q, self.pl) self.p.setup(self.mux, None, 0) self.failUnless(self.pl.current is None) quodlibet.config.init() def test_destroy(self): self.mux.destroy() def test_only_pl(self): self.pl.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, list(range(10))) self.next() self.failUnless(self.mux.current is None) def test_only_q(self): self.q.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, list(range(10))) self.next() self.failUnless(self.mux.current is None) def test_mixed(self): self.q.set(range(5)) self.pl.set(range(5, 10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, list(range(10))) self.next() self.failUnless(self.mux.current is None) def test_newplaylist(self): self.pl.set(range(5, 10)) do_events() self.failUnless(self.mux.current is None) self.mux.go_to(7) self.failUnlessEqual(self.mux.current, 7) self.pl.set([3, 5, 12, 11]) do_events() self.failUnlessEqual(self.mux.current, None) self.pl.set([19, 8, 12, 3]) do_events() self.failUnlessEqual(self.mux.current, None) self.pl.set([3, 7, 9, 11]) do_events() self.mux.next() self.failUnlessEqual(self.mux.current, 9) def test_halfway(self): self.pl.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(5)] self.q.set(range(100, 105)) do_events() songs.extend([self.next() for i in range(10)]) self.failUnlessEqual( songs, [0, 1, 2, 3, 4, 100, 101, 102, 103, 104, 5, 6, 7, 8, 9]) self.next() self.failUnless(self.mux.current is None) def test_removal(self): self.pl.set(range(0, 5)) self.q.set(range(10, 15)) do_events() songs = [self.next() for i in range(3)] self.q.remove(self.q.find(14)) self.q.remove(self.q.find(13)) songs.extend([self.next() for i in range(5)]) self.failUnlessEqual(songs, [10, 11, 12, 0, 1, 2, 3, 4]) def next(self): self.mux.next() song = self.mux.current self.p.emit('song-started', self.mux.current) do_events() return song def test_goto(self): self.pl.set(range(10)) self.q.set(range(10, 20)) do_events() self.failUnless(self.mux.current is None) self.mux.go_to(5) self.failUnlessEqual(self.mux.current, 5) self.mux.go_to(2) self.failUnlessEqual(self.mux.current, 2) self.failUnlessEqual(self.next(), 10) self.mux.go_to(7) self.failUnlessEqual(self.mux.current, 7) self.failUnlessEqual(self.next(), 11) def test_random_queue_666(self): for i in range(5): self.mux.go_to(None) self.pl.set([1]) do_events() self.failUnless(self.mux.current is None) self.q.order = OrderShuffle() self.failUnless(self.next() == 1) self.q.set([10, 11]) do_events() value = self.next() self.failUnless( value in [10, 11], "got %r, expected 10 or 11" % value) if value == 10: next = 11 else: next = 10 self.failUnlessEqual(self.next(), next) def test_sourced(self): self.pl.set(range(10)) self.q.set(range(10)) self.mux.go_to(None) self.failUnless(self.pl.sourced) self.q.go_to(1) self.p.next() self.failIf(self.pl.sourced) def test_unqueue(self): self.q.set(range(100)) self.mux.unqueue(range(100)) self.failIf(len(self.q)) def test_queue(self): self.mux.enqueue(range(40)) self.failUnlessEqual(list(self.q.itervalues()), list(range(40))) def test_queue_move_entry(self): self.q.set(range(10)) self.p.next() self.assertEqual(self.p.song, 0) self.q.move_after(self.q[-1].iter, None) self.p.next() self.assertEqual(self.p.song, 9) def test_goto_queue(self): self.pl.set(range(20, 30)) self.q.set(range(10)) self.mux.go_to(self.q[-1].iter, source=self.q) self.assertTrue(self.q.sourced) self.assertEqual(self.mux.current, self.q[-1][0]) def test_queue_disable(self): self.pl.set(range(10)) self.q.set(range(10)) quodlibet.config.set("memory", "queue_disable", True) self.next() self.failUnlessEqual(len(self.pl.get()), len(range(10))) self.failUnlessEqual(len(self.q.get()), len(range(10))) self.assertTrue(self.pl.sourced) quodlibet.config.set("memory", "queue_disable", False) self.next() self.failUnlessEqual(len(self.pl.get()), len(range(10))) self.failUnlessEqual(len(self.q.get()), len(range(10)) - 1) self.assertTrue(self.q.sourced) def test_queue_keep_songs(self): self.q.set(range(10)) quodlibet.config.set("memory", "queue_keep_songs", True) self.next() self.failUnlessEqual(len(self.q.get()), len(range(10))) self.failUnlessEqual(self.q.current, None) self.mux.go_to(self.q[0].iter, source=self.q) self.failUnlessEqual(self.q.current, 0) self.next() self.failUnlessEqual(len(self.q.get()), len(range(10))) self.failUnlessEqual(self.q.current, 1) quodlibet.config.set("memory", "queue_keep_songs", False) self.next() self.failUnlessEqual(len(self.q.get()), len(range(10)) - 1) self.failUnless(self.q.current is None) def test_queue_disable_and_keep_songs(self): self.pl.set(range(10)) self.q.set(range(10)) self.mux.go_to(self.q[0].iter, source=self.q) quodlibet.config.set("memory", "queue_disable", True) quodlibet.config.set("memory", "queue_keep_songs", True) self.next() self.assertTrue(self.pl.sourced) def tearDown(self): self.p.destroy()
class TPlaylistMux(TestCase): def setUp(self): self.q = PlaylistModel() self.pl = PlaylistModel() self.p = NullPlayer() self.mux = PlaylistMux(self.p, self.q, self.pl) self.p.setup(self.mux, None, 0) self.failUnless(self.pl.current is None) def test_destroy(self): self.mux.destroy() def test_only_pl(self): self.pl.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, list(range(10))) self.next() self.failUnless(self.mux.current is None) def test_only_q(self): self.q.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, list(range(10))) self.next() self.failUnless(self.mux.current is None) def test_mixed(self): self.q.set(range(5)) self.pl.set(range(5, 10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, list(range(10))) self.next() self.failUnless(self.mux.current is None) def test_newplaylist(self): self.pl.set(range(5, 10)) do_events() self.failUnless(self.mux.current is None) self.mux.go_to(7) self.failUnlessEqual(self.mux.current, 7) self.pl.set([3, 5, 12, 11]) do_events() self.failUnlessEqual(self.mux.current, None) self.pl.set([19, 8, 12, 3]) do_events() self.failUnlessEqual(self.mux.current, None) self.pl.set([3, 7, 9, 11]) do_events() self.mux.next() self.failUnlessEqual(self.mux.current, 9) def test_halfway(self): self.pl.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(5)] self.q.set(range(100, 105)) do_events() songs.extend([self.next() for i in range(10)]) self.failUnlessEqual( songs, [0, 1, 2, 3, 4, 100, 101, 102, 103, 104, 5, 6, 7, 8, 9]) self.next() self.failUnless(self.mux.current is None) def test_removal(self): self.pl.set(range(0, 5)) self.q.set(range(10, 15)) do_events() songs = [self.next() for i in range(3)] self.q.remove(self.q.find(14)) self.q.remove(self.q.find(13)) songs.extend([self.next() for i in range(5)]) self.failUnlessEqual(songs, [10, 11, 12, 0, 1, 2, 3, 4]) def next(self): self.mux.next() song = self.mux.current self.p.emit('song-started', self.mux.current) do_events() return song def test_goto(self): self.pl.set(range(10)) self.q.set(range(10, 20)) do_events() self.failUnless(self.mux.current is None) self.mux.go_to(5) self.failUnlessEqual(self.mux.current, 5) self.mux.go_to(2) self.failUnlessEqual(self.mux.current, 2) self.failUnlessEqual(self.next(), 10) self.mux.go_to(7) self.failUnlessEqual(self.mux.current, 7) self.failUnlessEqual(self.next(), 11) def test_random_queue_666(self): for i in range(5): self.mux.go_to(None) self.pl.set([1]) do_events() self.failUnless(self.mux.current is None) self.q.order = ORDERS[1](self.pl) self.failUnless(self.next() == 1) self.q.set([10, 11]) do_events() value = self.next() self.failUnless( value in [10, 11], "got %r, expected 10 or 11" % value) if value == 10: next = 11 else: next = 10 self.failUnlessEqual(self.next(), next) def test_sourced(self): self.pl.set(range(10)) self.q.set(range(10)) self.mux.go_to(None) self.failUnless(self.pl.sourced) self.q.go_to(1) self.p.next() self.failIf(self.pl.sourced) def test_unqueue(self): self.q.set(range(100)) self.mux.unqueue(range(100)) self.failIf(len(self.q)) def test_queue(self): self.mux.enqueue(range(40)) self.failUnlessEqual(list(self.q.itervalues()), list(range(40))) def test_queue_move_entry(self): self.q.set(range(10)) self.p.next() self.assertEqual(self.p.song, 0) self.q.move_after(self.q[-1].iter, None) self.p.next() self.assertEqual(self.p.song, 9) def test_goto_queue(self): self.pl.set(range(20, 30)) self.q.set(range(10)) self.mux.go_to(self.q[-1].iter, source=self.q) self.assertTrue(self.q.sourced) self.assertEqual(self.mux.current, self.q[-1][0]) def tearDown(self): self.p.destroy()
class TPlaylistMux(TestCase): def setUp(self): self.q = PlaylistModel() self.pl = PlaylistModel() self.p = NullPlayer() self.mux = PlaylistMux(self.p, self.q, self.pl) self.p.setup(self.mux, None, 0) self.failUnless(self.pl.current is None) def test_only_pl(self): self.pl.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, range(10)) self.next() self.failUnless(self.mux.current is None) def test_only_q(self): self.q.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, range(10)) self.next() self.failUnless(self.mux.current is None) def test_mixed(self): self.q.set(range(5)) self.pl.set(range(5, 10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(10)] self.failUnlessEqual(songs, range(10)) self.next() self.failUnless(self.mux.current is None) def test_newplaylist(self): self.pl.set(range(5, 10)) do_events() self.failUnless(self.mux.current is None) self.mux.go_to(7) self.failUnlessEqual(self.mux.current, 7) self.pl.set([3, 5, 12, 11]) do_events() self.failUnlessEqual(self.mux.current, None) self.pl.set([19, 8, 12, 3]) do_events() self.failUnlessEqual(self.mux.current, None) self.pl.set([3, 7, 9, 11]) do_events() self.mux.next() self.failUnlessEqual(self.mux.current, 9) def test_halfway(self): self.pl.set(range(10)) do_events() self.failUnless(self.mux.current is None) songs = [self.next() for i in range(5)] self.q.set(range(100, 105)) do_events() songs.extend([self.next() for i in range(10)]) self.failUnlessEqual( songs, [0, 1, 2, 3, 4, 100, 101, 102, 103, 104, 5, 6, 7, 8, 9]) self.next() self.failUnless(self.mux.current is None) def test_removal(self): self.pl.set(range(0, 5)) self.q.set(range(10, 15)) do_events() songs = [self.next() for i in range(3)] self.q.remove(self.q.find(14)) self.q.remove(self.q.find(13)) songs.extend([self.next() for i in range(5)]) self.failUnlessEqual(songs, [10, 11, 12, 0, 1, 2, 3, 4]) def next(self): self.mux.next() song = self.mux.current self.p.emit('song-started', self.mux.current) do_events() return song def test_goto(self): self.pl.set(range(10)) self.q.set(range(10, 20)) do_events() self.failUnless(self.mux.current is None) self.mux.go_to(5) self.failUnlessEqual(self.mux.current, 5) self.mux.go_to(2) self.failUnlessEqual(self.mux.current, 2) self.failUnlessEqual(self.next(), 10) self.mux.go_to(7) self.failUnlessEqual(self.mux.current, 7) self.failUnlessEqual(self.next(), 11) def test_random_queue_666(self): for i in range(5): self.mux.go_to(None) self.pl.set([1]) do_events() self.failUnless(self.mux.current is None) self.q.order = ORDERS[1](self.pl) self.failUnless(self.next() == 1) self.q.set([10, 11]) do_events() value = self.next() self.failUnless( value in [10, 11], "got %r, expected 10 or 11" % value) if value == 10: next = 11 else: next = 10 self.failUnlessEqual(self.next(), next) def test_sourced(self): self.pl.set(range(10)) self.q.set(range(10)) self.mux.go_to(None) self.failUnless(self.pl.sourced) self.q.go_to(1) self.p.next() self.failIf(self.pl.sourced) def test_unqueue(self): self.q.set(range(100)) self.mux.unqueue(range(100)) self.failIf(len(self.q)) def test_queue(self): self.mux.enqueue(range(40)) self.failUnlessEqual(list(self.q.itervalues()), range(40)) def tearDown(self): self.p.destroy()