Ejemplo n.º 1
0
    def test_move_root(self):
        # TODO: mountpoint tests too
        self.library.filename = "moving"
        root = Path(normalize_path(mkdtemp(), True))
        other_root = Path(normalize_path(mkdtemp(), True))
        new_root = Path(normalize_path(mkdtemp(), True))
        in_song = FakeAudioFile(str(root / "in file.mp3"))
        in_song.sanitize()
        out_song = FakeAudioFile(str(other_root / "out file.mp3"))
        # Make sure they exists
        in_song.sanitize()
        out_song.sanitize()
        assert Path(in_song("~dirname")) == root, "test setup wrong"
        assert Path(out_song("~dirname")) == other_root, "test setup wrong"
        self.library.add([out_song, in_song])

        # Run it by draining the generator
        list(self.library.move_root(root, str(new_root)))
        msg = f"Dir wasn't updated in {root!r} -> {new_root!r} for {in_song.key}"
        assert Path(in_song("~dirname")) == new_root, msg
        assert Path(in_song("~filename")) == (new_root / "in file.mp3")
        assert Path(out_song(
            "~dirname")) == other_root, f"{out_song} was wrongly moved"
        assert in_song._written, "Song wasn't written to disk"
        assert not out_song._written, "Excluded songs was written!"
Ejemplo n.º 2
0
    def setUp(self):
        config.init()

        self.main = mkdtemp()

        self.dir1 = mkdtemp(dir=self.main)
        self.dir2 = mkdtemp(dir=self.main)

        h, self.cover1 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 10, 10)
        pb.savev(self.cover1, "png", [], [])

        h, self.cover2 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 20, 20)
        pb.savev(self.cover2, "png", [], [])

        fd, self.file1 = mkstemp(".mp3", dir=self.main)
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file1)

        fd, self.file2 = mkstemp(".mp3", dir=self.main)
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file2)

        self.manager = CoverManager()
Ejemplo n.º 3
0
    def setUp(self):
        config.init()

        self.main = mkdtemp()

        self.dir1 = mkdtemp(dir=self.main)
        self.dir2 = mkdtemp(dir=self.main)

        h, self.cover1 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 10, 10)
        pb.savev(self.cover1, "png", [], [])

        h, self.cover2 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 20, 20)
        pb.savev(self.cover2, "png", [], [])

        fd, self.file1 = mkstemp(".mp3", dir=self.main)
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file1)

        fd, self.file2 = mkstemp(".mp3", dir=self.main)
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.file2)

        self.manager = CoverManager()
Ejemplo n.º 4
0
 def test_hidden_dir(self):
     child = mkdtemp(dir=self.root, prefix=".")
     fd, name = mkstemp(dir=child)
     os.close(fd)
     assert list(iter_paths(child)) == []
     assert list(iter_paths(child, skip_hidden=False)) == [name]
     assert list(iter_paths(self.root)) == []
     assert list(iter_paths(self.root, skip_hidden=False)) == [name]
Ejemplo n.º 5
0
    def setUp(self):
        quodlibet.config.init()
        self.ROOTS = [mkdtemp(), mkdtemp()]
        self.INITIAL = self.ROOTS[0]
        self.PATHS = [
            os.path.join(self.ROOTS[0], "a"),
            os.path.join(self.ROOTS[0], "b"),
        ]

        for path in self.PATHS:
            open(path, "wb").close()

        self.fs = FileSelector(initial=self.INITIAL,
                               filter=(lambda s: s in self.PATHS),
                               folders=self.ROOTS)
        self.fs.connect('changed', self._changed)
        self.files = None
        self.fs.rescan()
Ejemplo n.º 6
0
 def setUp(self):
     self.tempdir = mkdtemp()
     self.pm = PluginManager(folders=[self.tempdir])
     self.confirmed = False
     self.handler = SongsMenuPluginHandler(self._confirmer, self._confirmer)
     self.pm.register_handler(self.handler)
     self.pm.rescan()
     self.assertEquals(self.pm.plugins, [])
     self.library = SongLibrary('foo')
 def setUp(self):
     self.tempdir = mkdtemp()
     self.pm = PluginManager(folders=[self.tempdir])
     self.confirmed = False
     self.handler = SongsMenuPluginHandler(self._confirmer, self._confirmer)
     self.pm.register_handler(self.handler)
     self.pm.rescan()
     self.assertEquals(self.pm.plugins, [])
     self.library = SongLibrary('foo')
Ejemplo n.º 8
0
    def setUp(self):
        quodlibet.config.init()
        self.ROOTS = [mkdtemp(), mkdtemp()]
        self.INITIAL = self.ROOTS[0]
        self.PATHS = [
            os.path.join(self.ROOTS[0], "a"),
            os.path.join(self.ROOTS[0], "b"),
        ]

        for path in self.PATHS:
            open(path, "wb").close()

        self.fs = FileSelector(
            initial=self.INITIAL, filter=(lambda s: s in self.PATHS),
            folders=self.ROOTS)
        self.fs.connect('changed', self._changed)
        self.files = None
        self.fs.rescan()
Ejemplo n.º 9
0
    def test_remove_roots(self):
        self.library.filename = "removing"
        root = Path(normalize_path(mkdtemp(), True))
        other_root = Path(normalize_path(mkdtemp(), True))
        out_song = FakeAudioFile(str(other_root / "out file.mp3"))
        in_song = FakeAudioFile(str(root / "in file.mp3"))
        in_song.sanitize()
        out_song.sanitize()
        self.library.add([in_song, out_song])
        assert in_song in self.library, "test seems broken"

        # Run it by draining the generator
        list(self.library.remove_roots([root]))

        assert in_song not in self.library
        assert out_song in self.library, "removed too many files"
        assert self.removed == [in_song], "didn't signal the song removal"
        assert not self.changed, "shouldn't have changed any tracks"
Ejemplo n.º 10
0
 def setUp(self):
     quodlibet.config.init()
     self.lib = quodlibet.browsers.search.library = FileLibrary()
     quodlibet.browsers.search.library.librarian = SongLibrarian()
     for af in self.SONGS:
         af.sanitize()
     self.lib.add(self.SONGS)
     self._dir = mkdtemp()
     self.pl = FileBackedPlaylist.new(self._dir, "Foobar", self.lib)
     self.pl.extend(self.SONGS)
Ejemplo n.º 11
0
 def setUp(self):
     self.tempdir = mkdtemp()
     self.pm = PluginManager(folders=[self.tempdir])
     self.confirmed = False
     self.mock_browser = self.MockBrowser()
     self.handler = PlaylistPluginHandler(self._confirmer)
     self.pm.register_handler(self.handler)
     self.pm.rescan()
     self.assertEquals(self.pm.plugins, [])
     self.library = SongLibrary("foo")
Ejemplo n.º 12
0
 def setUp(self):
     self.tempdir = mkdtemp()
     self.pm = PluginManager(folders=[self.tempdir])
     self.lib = SongLibrarian()
     self.player = player.init_player("nullbe", self.lib)
     self.handler = EventPluginHandler(
         librarian=self.lib, player=self.player)
     self.pm.register_handler(self.handler)
     self.pm.rescan()
     self.assertEquals(self.pm.plugins, [])
Ejemplo n.º 13
0
 def setUp(self):
     self.tempdir = mkdtemp()
     self.pm = PluginManager(folders=[self.tempdir])
     self.lib = SongLibrarian()
     self.player = player.init_player("nullbe", self.lib)
     self.handler = EventPluginHandler(
         librarian=self.lib, player=self.player)
     self.pm.register_handler(self.handler)
     self.pm.rescan()
     self.assertEquals(self.pm.plugins, [])
Ejemplo n.º 14
0
 def setUp(self):
     quodlibet.config.init()
     self.lib = quodlibet.browsers.search.library = FileLibrary()
     quodlibet.browsers.search.library.librarian = SongLibrarian()
     for af in self.SONGS:
         af.sanitize()
     self.lib.add(self.SONGS)
     self._dir = mkdtemp()
     self.pl = FileBackedPlaylist.new(self._dir, "Foobar", self.lib)
     self.pl.extend(self.SONGS)
Ejemplo n.º 15
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.º 16
0
    def setUp(self):
        self.manager = CoverManager()

        self.dir = mkdtemp()
        self.song = self.an_album_song()

        # Safety check
        self.failIf(glob.glob(os.path.join(self.dir + "*.jpg")))
        files = [self.full_path("12345.jpg"), self.full_path("nothing.jpg")]
        for f in files:
            open(f, "w").close()
Ejemplo n.º 17
0
    def setUp(self):
        config.init()

        self.manager = CoverManager()
        self.dir = mkdtemp()
        self.song = self.an_album_song()

        # Safety check
        self.failIf(glob.glob(os.path.join(self.dir + "*.jpg")))
        files = [self.full_path("12345.jpg"), self.full_path("nothing.jpg")]
        for f in files:
            open(f, "w").close()
Ejemplo n.º 18
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.º 19
0
    def test_move_root_gone_source_dir(self):
        # See #3967
        self.library.filename = "moving"
        gone_root = Path(normalize_path("/gone", True))
        new_root = Path(normalize_path(mkdtemp(), True))
        song = FakeAudioFile(str(gone_root / "in file.mp3"))
        assert Path(song("~dirname")) == gone_root, "test setup wrong"
        self.library.add([song])

        # Run it by draining the generator
        list(self.library.move_root(gone_root, str(new_root)))
        assert Path(song("~dirname")) == new_root
        assert song._written, "Song wasn't written to disk"
Ejemplo n.º 20
0
    def test_with_dir_symlink(self):
        child = mkdtemp(dir=self.root)
        link = os.path.join(self.root, "foo")
        os.symlink(child, link)
        fd, name = mkstemp(dir=link)
        os.close(fd)

        assert name not in list(iter_paths(self.root))
        assert list(iter_paths(link)) == list(iter_paths(child))

        assert list(iter_paths(link, exclude=[link])) == []
        assert list(iter_paths(child, exclude=[child])) == []
        assert list(iter_paths(link, exclude=[child])) == []
Ejemplo n.º 21
0
    def setUp(self):
        config.init()

        self.main = mkdtemp()

        self.dir1 = mkdtemp(dir=self.main)
        self.dir2 = mkdtemp(dir=self.main)

        h, self.cover1 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 10, 10)
        pb.savev(self.cover1, "png", [], [])

        h, self.cover2 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 20, 20)
        pb.savev(self.cover2, "png", [], [])

        self.file1 = get_temp_copy(get_data_path('silence-44-s.mp3'))
        self.file2 = get_temp_copy(get_data_path('silence-44-s.mp3'))

        self.manager = CoverManager()
Ejemplo n.º 22
0
    def setUp(self):
        config.init()

        self.main = mkdtemp()

        self.dir1 = mkdtemp(dir=self.main)
        self.dir2 = mkdtemp(dir=self.main)

        h, self.cover1 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 10, 10)
        pb.savev(self.cover1, "png", [], [])

        h, self.cover2 = mkstemp(".png", dir=self.main)
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 20, 20)
        pb.savev(self.cover2, "png", [], [])

        self.file1 = get_temp_copy(get_data_path('silence-44-s.mp3'))
        self.file2 = get_temp_copy(get_data_path('silence-44-s.mp3'))

        self.manager = CoverManager()
Ejemplo n.º 23
0
    def setUp(self):
        self.manager = CoverManager()

        self.dir = mkdtemp()
        self.song = AudioFile({
            "~filename": os.path.join(self.dir, "asong.ogg"),
            "album": u"Quuxly",
        })

        # Safety check
        self.failIf(glob.glob(os.path.join(self.dir + "*.jpg")))
        files = [self.full_path("12345.jpg"), self.full_path("nothing.jpg")]
        for f in files:
            open(f, "w").close()
Ejemplo n.º 24
0
    def setUp(self):
        self.manager = CoverManager()

        self.dir = mkdtemp()
        self.song = AudioFile({
            "~filename": os.path.join(self.dir, "asong.ogg"),
            "album": u"Quuxly",
        })

        # Safety check
        self.failIf(glob.glob(os.path.join(self.dir + "*.jpg")))
        files = [self.full_path("12345.jpg"), self.full_path("nothing.jpg")]
        for f in files:
            open(f, "w").close()
Ejemplo n.º 25
0
 def setUp(self):
     self.p = NullPlayer()
     self.dir = mkdtemp()
     self.filename = os.path.join(self.dir, "foo")
     self.fs = FSInterface(self.filename, self.p)
Ejemplo n.º 26
0
 def setUp(self):
     self.d = mkdtemp("ql-mod")
     spec = importlib.machinery.ModuleSpec("qlfake", None)
     sys.modules["qlfake"] = importlib.util.module_from_spec(spec)
 def setUp(self):
     self.d = mkdtemp("ql-mod")
     sys.modules["qlfake"] = imp.new_module("qlfake")
Ejemplo n.º 28
0
 def setUp(self):
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Ejemplo n.º 29
0
 def setUp(self):
     self.dir = mkdtemp()
Ejemplo n.º 30
0
"""TODO: Share better with, i.e. test MenuItemPlugin directly"""

import os

from gi.repository import Gtk
from quodlibet.browsers import Browser

from quodlibet.library import SongLibrary
from quodlibet.plugins.playlist import PlaylistPlugin, PlaylistPluginHandler
from quodlibet.util.collection import Playlist
from tests import TestCase, mkstemp, mkdtemp
from quodlibet.plugins import PluginManager, Plugin
from tests.helper import capture_output

MAX_PLAYLISTS = 50
DIR = mkdtemp()
TEST_PLAYLIST = Playlist(DIR, "foo")


def generate_playlists(n):
    return [Playlist(DIR, "Playlist %d" % x) for x in range(n)]


class TPlaylistPlugins(TestCase):
    class MockBrowser(Browser):
        def __init__(self):
            super(TPlaylistPlugins.MockBrowser, self).__init__()
            self.activated = False

        def activate(self):
            self.activated = True
Ejemplo n.º 31
0
 def reset_environment(self):
     config.init()
     self.root_path = mkdtemp()
     self.filenames = \
         ['cover.jpg', 'info.jpg', 'title.jpg', 'title2.jpg']
Ejemplo n.º 32
0
 def setUp(self):
     self.p = NullPlayer()
     self.dir = mkdtemp()
     self.filename = os.path.join(self.dir, "foo")
     self.fs = FSInterface(self.filename, self.p)
Ejemplo n.º 33
0
 def setUp(self):
     self.d = mkdtemp("ql-mod")
     sys.modules["qlfake"] = imp.new_module("qlfake")
Ejemplo n.º 34
0
 def test_download_fails_for_non_existent(self):
     songs = [an_rf(i) for i in range(3)]
     d = DownloadProgress(songs)
     for _ in d.download_songs(mkdtemp()):
         run_gtk_loop()
     assert d.failed == set(songs)
Ejemplo n.º 35
0
 def setUp(self):
     super(TFileBackedPlaylist, self).setUp()
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Ejemplo n.º 36
0
 def setUp(self):
     self.dir = mkdtemp()
Ejemplo n.º 37
0
 def setUp(self):
     super().setUp()
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Ejemplo n.º 38
0
 def reset_environment(self):
     config.init()
     self.root_path = mkdtemp()
     self.filenames = \
         ['cover.jpg', 'info.jpg', 'title.jpg', 'title2.jpg']
Ejemplo n.º 39
0
import os
import shutil

from gi.repository import Gtk
from quodlibet.browsers import Browser

from quodlibet.library import SongLibrary
from quodlibet.plugins.playlist import PlaylistPlugin, PlaylistPluginHandler
from quodlibet.util.collection import Playlist
from tests import TestCase, mkstemp, mkdtemp
from quodlibet.plugins import PluginManager, Plugin
from tests.helper import capture_output

MAX_PLAYLISTS = 50
DIR = mkdtemp()
TEST_PLAYLIST = Playlist(DIR, "foo")


def generate_playlists(n):
    return [Playlist(DIR, "Playlist %d" % x) for x in range(n)]


class TPlaylistPlugins(TestCase):
    class MockBrowser(Browser):
        def __init__(self):
            super(TPlaylistPlugins.MockBrowser, self).__init__()
            self.activated = False

        def activate(self):
            self.activated = True
Ejemplo n.º 40
0
 def setUp(self):
     # on osx the temp folder returned is a symlink
     self.root = os.path.realpath(mkdtemp())
Ejemplo n.º 41
0
 def choose(*args, **kwargs):
     return [mkdtemp()]
Ejemplo n.º 42
0
 def setUp(self):
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Ejemplo n.º 43
0
def temp_dir() -> Path:
    out_path = Path(mkdtemp())
    yield out_path
    shutil.rmtree(out_path)