Ejemplo n.º 1
0
    def test_masked_handling(self):
        if os.name == "nt":
            # FIXME: masking isn't properly implemented on Windows
            return
        # playlists can contain songs and paths for masked handling..
        lib = FileLibrary("foobar")
        with self.wrap("playlist", lib) as pl:
            song = Fakesong({"date": "2038", "~filename": fsnative(u"/fake")})
            song.sanitize()
            lib.add([song])

            # mask and update
            lib.mask("/")
            pl.append(song)
            pl.remove_songs([song])
            self.failUnless("/fake" in pl)

            pl.extend(self.TWO_SONGS)

            # check if collections can handle the mix
            self.failUnlessEqual(pl("date"), "2038")

            # unmask and update
            lib.unmask("/")
            pl.add_songs(["/fake"], lib)
            self.failUnless(song in pl)

            lib.destroy()
Ejemplo n.º 2
0
 def test_read(self):
     lib = FileLibrary("foobar")
     lib.add(NUMERIC_SONGS)
     with self.wrap("playlist", lib) as pl:
         pl.extend(NUMERIC_SONGS)
         pl.write()
         self.assertEqual(len(pl), len(NUMERIC_SONGS))
Ejemplo n.º 3
0
 def test_load_legacy_format_to_xspf(self):
     playlist_fn = "old"
     songs_lib = FileLibrary()
     songs_lib.add(NUMERIC_SONGS)
     old_pl = FileBackedPlaylist(self.temp, playlist_fn)
     old_pl.extend(NUMERIC_SONGS)
     pl = XSPFBackedPlaylist.from_playlist(old_pl,
                                           songs_lib=songs_lib,
                                           pl_lib=None)
     expected_filenames = {s("~filename") for s in NUMERIC_SONGS}
     assert {s("~filename") for s in pl.songs} == expected_filenames
Ejemplo n.º 4
0
 def setUp(self):
     self.p = NullPlayer()
     self.dir = mkdtemp()
     self.lib = FileLibrary()
     self.song = AudioFile({
         "~filename": A_PATH,
         "title": "bar",
         "~#length": 10
     })
     self.lib.add([self.song])
     self.filename = os.path.join(self.dir, "foo")
     self.fs = FSInterface(self.filename, self.p, self.lib)
Ejemplo n.º 5
0
 def test_v1_load_non_compliant_xspf(self):
     """See #3983"""
     songs_lib = FileLibrary()
     test_filename = ("/music/Funk & Disco/"
                      "Average White Band - Pickin' Up The Pieces/"
                      "Average White Band - Your Love Is a Miracle.flac")
     songs_lib.add([AudioFile({"~filename": test_filename})])
     playlist_fn = "non-compliant.xspf"
     path = str(Path(__file__).parent / "data")
     pl = XSPFBackedPlaylist(path,
                             playlist_fn,
                             songs_lib=songs_lib,
                             pl_lib=None)
     assert {s("~filename") for s in pl.songs}, set(test_filename)
Ejemplo n.º 6
0
 def setUp(self):
     # Testing locally is VERY dangerous without this...
     self.assertTrue(_TEMP_DIR in _DEFAULT_PLAYLIST_DIR or os.name == "nt",
                     msg="Failing, don't want to delete %s" % _DEFAULT_PLAYLIST_DIR)
     try:
         os.mkdir(_DEFAULT_PLAYLIST_DIR)
     except EnvironmentError:
         pass
     quodlibet.config.init()
     self.lib = FileLibrary()
     self.lib.librarian = SongLibrarian()
     for af in self.SONGS:
         af.sanitize()
     self.lib.add(self.SONGS)
Ejemplo n.º 7
0
class TPlaylistMenu(TestCase):
    SONG = AudioFile({
        "title": "two",
        "artist": "mu",
        "~filename": dummy_path(u"/dev/zero")
    })
    SONGS = [
        AudioFile({
            "title": "one",
            "artist": "piman",
            "~filename": dummy_path(u"/dev/null")
        }),
        SONG,
    ]

    def setUp(self):
        # Testing locally is VERY dangerous without this...
        self.assertTrue(_TEMP_DIR in _DEFAULT_PLAYLIST_DIR or os.name == "nt",
                        msg="Failing, don't want to delete %s" %
                        _DEFAULT_PLAYLIST_DIR)
        try:
            os.mkdir(_DEFAULT_PLAYLIST_DIR)
        except EnvironmentError:
            pass
        quodlibet.config.init()
        self.lib = FileLibrary()
        self.lib.librarian = SongLibrarian()
        for af in self.SONGS:
            af.sanitize()
        self.lib.add(self.SONGS)

    def tearDown(self):
        self.lib.destroy()
        self.lib.librarian.destroy()
        quodlibet.config.quit()

    def test__on_new_playlist_activate(self):
        main = qltk.MenuItem('Menu')
        menu = StubbedPlaylistMenu(self.SONGS,
                                   PlaylistLibrary(SongFileLibrary()))
        main.set_submenu(menu)

        pl = menu._on_new_playlist_activate(main, self.SONGS)

        self.failUnless(pl, msg="No playlists added")
        self.failUnlessEqual(pl.songs, self.SONGS)
Ejemplo n.º 8
0
 def test_difficult_names(self):
     lib = FileLibrary("foobar")
     tempdir = mkdtemp()
     self.add_songs_in_temp_dir(lib, tempdir, NUMERIC_SONGS)
     name = "c:?\"problem?\" / foo* / 100% É™! COM"
     with self.wrap(name, lib) as pl:
         pl.extend(NUMERIC_SONGS)
         pl.write()
         assert pl.songs == NUMERIC_SONGS
         with self.wrap(name, lib) as pl2:
             assert pl2.songs == NUMERIC_SONGS
Ejemplo n.º 9
0
class TFSInterface(TestCase):
    def setUp(self):
        self.p = NullPlayer()
        self.dir = mkdtemp()
        self.lib = FileLibrary()
        self.song = AudioFile({
            "~filename": A_PATH,
            "title": "bar",
            "~#length": 10
        })
        self.lib.add([self.song])
        self.filename = os.path.join(self.dir, "foo")
        self.fs = FSInterface(self.filename, self.p, self.lib)

    def tearDown(self):
        self.p.destroy()
        self.lib.destroy()
        shutil.rmtree(self.dir)

    def test_init(self):
        run_gtk_loop()
        self.failIf(os.path.exists(self.filename))

    def test_start(self):
        self.p.emit('song_started', self.song)
        run_gtk_loop()
        with open(self.filename, "rb") as h:
            self.failUnless(b"title=bar\n" in h.read())

    def test_song_ended(self):
        self.p.emit('song-started', self.song)
        run_gtk_loop()
        self.p.emit('song-ended', {}, False)
        run_gtk_loop()
        self.failIf(os.path.exists(self.filename))

    def test_elapsed(self):
        self.p.seek(123456)
        self.p.emit('song-started', AudioFile({"~#length": 10}))
        run_gtk_loop()
        with open(self.filename, "rb") as h:
            contents = h.read()
        assert b"~#elapsed=123.456" in contents
        assert b"~elapsed=2:03\n" in contents

    def test_current_song_changed(self):
        self.p.song = self.song
        self.song["title"] = "new!"
        self.lib.changed([self.song])
        run_gtk_loop()
        with open(self.filename, "rb") as h:
            contents = h.read()
        assert b"title=new!\n" in contents
Ejemplo n.º 10
0
 def test_no_pl_lib(self):
     """Probably not possible in real runtime situations"""
     assert PlaylistsBrowser(FileLibrary("no-playlists"))