Esempio 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!"
Esempio 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()
Esempio 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()
 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]
    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()
Esempio 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')
Esempio 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()
Esempio 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"
 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)
Esempio 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")
 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, [])
Esempio 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, [])
Esempio 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)
Esempio 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
Esempio 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()
Esempio 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()
Esempio 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)
Esempio 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"
    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])) == []
Esempio 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()
Esempio 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()
Esempio 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()
Esempio 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()
Esempio 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)
Esempio 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")
 def setUp(self):
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Esempio n. 29
0
 def setUp(self):
     self.dir = mkdtemp()
Esempio 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
Esempio n. 31
0
 def reset_environment(self):
     config.init()
     self.root_path = mkdtemp()
     self.filenames = \
         ['cover.jpg', 'info.jpg', 'title.jpg', 'title2.jpg']
Esempio 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)
Esempio n. 33
0
 def setUp(self):
     self.d = mkdtemp("ql-mod")
     sys.modules["qlfake"] = imp.new_module("qlfake")
Esempio 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)
Esempio n. 35
0
 def setUp(self):
     super(TFileBackedPlaylist, self).setUp()
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Esempio n. 36
0
 def setUp(self):
     self.dir = mkdtemp()
Esempio n. 37
0
 def setUp(self):
     super().setUp()
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Esempio n. 38
0
 def reset_environment(self):
     config.init()
     self.root_path = mkdtemp()
     self.filenames = \
         ['cover.jpg', 'info.jpg', 'title.jpg', 'title2.jpg']
Esempio 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
 def setUp(self):
     # on osx the temp folder returned is a symlink
     self.root = os.path.realpath(mkdtemp())
Esempio n. 41
0
 def choose(*args, **kwargs):
     return [mkdtemp()]
Esempio n. 42
0
 def setUp(self):
     self.temp = mkdtemp()
     self.temp2 = mkdtemp()
Esempio n. 43
0
def temp_dir() -> Path:
    out_path = Path(mkdtemp())
    yield out_path
    shutil.rmtree(out_path)