示例#1
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()
示例#2
0
 def setUp(self):
     config.init()
     fd, self.filename = mkstemp(".mp3")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.filename)
     fd, self.filename2 = mkstemp(".mp3")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'mutagen-bug.mp3'), self.filename2)
示例#3
0
    def setUp(self):
        fd, self.f = mkstemp(".wma")
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'test.wma'), self.f)
        self.song = WMAFile(self.f)

        fd, self.f2 = mkstemp(".wma")
        os.close(fd)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.f2)
        self.song2 = WMAFile(self.f2)
示例#4
0
 def setUp(self):
     config.init()
     fd, self.f = mkstemp(".ogg")
     os.close(fd)
     fd, self.f2 = mkstemp(".mp3")
     os.close(fd)
     fd, self.f3 = mkstemp(".mp3")
     os.write(fd, "garbage")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.ogg'), self.f)
     shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.f2)
     self.s = MusicFile(self.f)
     self.s2 = MusicFile(self.f2)
示例#5
0
    def setUp(self):
        super(TOperonImageSet, self).setUp()
        from gi.repository import GdkPixbuf

        h, self.filename = mkstemp(".png")
        os.close(h)
        wide = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
        wide.savev(self.filename, "png", [], [])

        h, self.fcover = mkstemp(".wma")
        os.close(h)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
        self.cover = MusicFile(self.fcover)
示例#6
0
 def setUp(self):
     quodlibet.config.init()
     h, self.fname = mkstemp()
     os.close(h)
     with open(self.fname + ".saved", "w") as f:
         f.write("%s\n%s\n" % (self.TEST_KV_DATA[0][1], self.TEST_KV_DATA[0][0]))
     self.sae = StandaloneEditor(self.fname, "test", None, None)
    def create_plugin(self, id='', name='', desc='', icon='',
                      funcs=None, mod=False):
        fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir)
        file = os.fdopen(fd, 'w')

        if mod:
            indent = ''
        else:
            file.write(
                "from quodlibet.plugins.songsmenu import SongsMenuPlugin\n")
            file.write("class %s(SongsMenuPlugin):\n" % name)
            indent = '    '
            file.write("%spass\n" % indent)

        if name:
            file.write("%sPLUGIN_ID = %r\n" % (indent, name))
        if name:
            file.write("%sPLUGIN_NAME = %r\n" % (indent, name))
        if desc:
            file.write("%sPLUGIN_DESC = %r\n" % (indent, desc))
        if icon:
            file.write("%sPLUGIN_ICON = %r\n" % (indent, icon))
        for f in (funcs or []):
            if f in ["__init__"]:
                file.write("%sdef %s(self, *args): super(%s, self).__init__("
                           "*args); raise Exception(\"as expected\")\n"
                           % (indent, f, name))
            else:
                file.write("%sdef %s(*args): return args\n" % (indent, f))
        file.flush()
        file.close()
示例#8
0
    def test_validate(self):
        # strip translatable prefix from tags
        from xml.etree import ElementTree
        tree = ElementTree.parse(self.PATH)
        for x in tree.iter():
            if x.tag.startswith("_"):
                x.tag = x.tag[1:]
        fd, name = mkstemp(suffix=".appdata.xml")
        os.close(fd)

        with open(name, "wb") as temp:
            header = open(self.PATH, "rb").read().splitlines()[0]
            temp.write(header + "\n")
            temp.write(ElementTree.tostring(tree.getroot(), encoding="utf-8"))

        # pass to desktop-file-validate
        try:
            subprocess.check_output(
                ["appdata-validate", "--nonet", name],
                stderr=subprocess.STDOUT)
        except OSError:
            # appdata-validate not available
            return
        except subprocess.CalledProcessError as e:
            raise Exception(e.output)
        finally:
            os.remove(name)
 def test_load_noexist(self):
     fd, filename = mkstemp()
     os.close(fd)
     os.unlink(filename)
     library = self.Library()
     library.load(filename)
     assert len(library) == 0
示例#10
0
 def setUp(self):
     TVCCover.setUp(self)
     h, self.filename = mkstemp(".ogg")
     os.close(h)
     shutil.copy(os.path.join(DATA_DIR, 'empty.ogg'), self.filename)
     self.MutagenType = OggVorbis
     self.QLType = OggFile
示例#11
0
 def setUp(self):
     TVCCover.setUp(self)
     h, self.filename = mkstemp(".flac")
     os.close(h)
     shutil.copy(os.path.join(DATA_DIR, 'empty.flac'), self.filename)
     self.MutagenType = FLAC
     self.QLType = FLACFile
示例#12
0
 def test_trash_removes_file(self):
     filename = mkstemp()[1]
     with open(filename, "w") as f:
         f.write("\n")
     self.failUnless(os.path.exists(filename))
     trash(filename)
     self.failIf(os.path.exists(filename))
    def setUp(self):
        from gi.repository import GdkPixbuf

        h, self.filename = mkstemp()
        os.close(h)
        pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
        pb.savev(self.filename, "png", [], [])
示例#14
0
    def test_validate(self):
        with open(self.PATH, "rb") as template:
            desktop_data = template.read()

        # copy to a temp file and strip "_ from translatable entries
        fd, name = mkstemp(suffix=".desktop")
        os.close(fd)
        with open(name, "wb") as temp:
            new_lines = []
            for l in desktop_data.splitlines():
                if l.startswith("_"):
                    l = l[1:]
                new_lines.append(l)
            temp.write("\n".join(new_lines))

        # pass to desktop-file-validate
        try:
            output = subprocess.check_output(
                ["desktop-file-validate", name], stderr=subprocess.STDOUT)
        except OSError:
            # desktop-file-validate not available
            return
        except subprocess.CalledProcessError as e:
            output = e.output
        finally:
            os.remove(name)

        if output:
            raise Exception(output)
    def create_plugin(self, id="", name="", desc="", icon="", funcs=None, mod=False):
        fd, fn = mkstemp(suffix=".py", text=True, dir=self.tempdir)
        file = os.fdopen(fd, "w")

        if mod:
            indent = ""
        else:
            file.write("from quodlibet.plugins.playlist import PlaylistPlugin\n")
            file.write("class %s(PlaylistPlugin):\n" % name)
            indent = "    "
            file.write("%spass\n" % indent)

        if name:
            file.write("%sPLUGIN_ID = %r\n" % (indent, name))
        if name:
            file.write("%sPLUGIN_NAME = %r\n" % (indent, name))
        if desc:
            file.write("%sPLUGIN_DESC = %r\n" % (indent, desc))
        if icon:
            file.write("%sPLUGIN_ICON = %r\n" % (indent, icon))
        for f in funcs or []:
            if f in ["__init__"]:
                file.write(
                    "%sdef %s(self, *args): super(%s, self).__init__("
                    '*args); raise Exception("as expected.")\n' % (indent, f, name)
                )
            else:
                file.write("%sdef %s(*args): return args\n" % (indent, f))
        file.flush()
        file.close()
示例#16
0
    def setUp(self):
        super(TOperonImageExtract, self).setUp()

        h, self.fcover = mkstemp(".wma")
        os.close(h)
        shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
        self.cover = MusicFile(self.fcover)
示例#17
0
    def test_savedsearch(self):
        if 'include_saved' not in self.plugins:
            return

        plugin = self.plugins['include_saved'].cls()

        self.failUnlessRaises(QueryPluginError, plugin.parse_body, None)

        try:
            fd, filename = mkstemp(text=True)
            file = os.fdopen(fd, 'w')
            file.write("artist=a\nQuery 1\ngenre=classical\nAnother query")
            file.close()

            self.failUnlessRaises(QueryPluginError, plugin.parse_body,
                                  'missing query')
            self.failUnlessRaises(QueryPluginError, plugin.parse_body,
                                  'artist=a')

            self.failUnless(plugin.parse_body('  quEry 1',
                            query_path_=filename))

            query1 = plugin.parse_body('Query 1', query_path_=filename)
            query2 = plugin.parse_body('another query', query_path_=filename)
            song = AudioFile({'artist': u'a', 'genre': u'dance'})
            self.failUnless(plugin.search(song, query1))
            self.failIf(plugin.search(song, query2))
        finally:
            os.remove(filename)
示例#18
0
 def setUp(self):
     config.init()
     init_fake_app()
     fd, self.fn = mkstemp()
     os.close(fd)
     pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
     pb.savev(self.fn, "png", [], [])
 def test_one_file_exclude(self):
     fd, name = mkstemp(dir=self.root)
     os.close(fd)
     assert list(iter_paths(self.root, exclude=[self.root])) == []
     assert list(iter_paths(self.root,
                            exclude=[os.path.dirname(self.root)])) == []
     assert list(iter_paths(self.root, exclude=[name])) == []
     assert list(iter_paths(self.root, exclude=[name + "a"])) == [name]
示例#20
0
 def enabled(self):
     # https://github.com/quodlibet/quodlibet/issues/1093
     fd, filename = mkstemp('.shelve')
     os.close(fd)
     os.unlink(filename)
     s = shelve.open(filename)
     s["foobar"] = PickleMe()
     s.close()
 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 test_parse_empty(self):
     h, name = mkstemp()
     os.close(h)
     open(name, "w").close()
     pl = self.Parse(name)
     os.unlink(name)
     self.failUnlessEqual(0, len(pl))
     pl.delete()
 def test_from_path_empty(self):
     h, empty = mkstemp()
     os.close(h)
     try:
         image = EmbeddedImage.from_path(empty)
         self.assertFalse(image)
     finally:
         os.remove(empty)
示例#24
0
 def setUp(self):
     """Copy the base silent file to a temp name/location and load it"""
     config.init()
     fd, self.filename = mkstemp(suffix=self.ext, text=False)
     dst = os.fdopen(fd, 'w')
     src = open(self.base + self.ext, 'rb')
     copyfileobj(src, dst)
     dst.close()
     self.song = formats.MusicFile(self.filename)
    def test_with_file(self):
        fd, name = mkstemp(dir=self.root)
        os.close(fd)
        link = os.path.join(self.root, "foo")
        os.symlink(name, link)

        assert list(iter_paths(self.root)) == [name, name]
        assert list(iter_paths(self.root, exclude=[link])) == [name]
        assert list(iter_paths(self.root, exclude=[name])) == []
示例#26
0
def get_temp_copy(path):
    """Returns a copy of the file with the same extension"""

    from tests import mkstemp

    ext = os.path.splitext(path)[-1]
    fd, filename = mkstemp(suffix=ext)
    os.close(fd)
    shutil.copy(path, filename)
    return filename
示例#27
0
def _get_jpeg(size=5):
    from gi.repository import GdkPixbuf
    pb = GdkPixbuf.Pixbuf.new(
        GdkPixbuf.Colorspace.RGB, False, 8, size, size)
    fd, fn = mkstemp()
    pb.savev(fn, "jpeg", [], [])
    with os.fdopen(fd) as h:
        data = h.read()
    os.unlink(fn)
    return data
 def test_load_invalid(self):
     fd, filename = mkstemp()
     os.write(fd, b"nope")
     os.close(fd)
     try:
         library = self.Library()
         library.load(filename)
         assert len(library) == 0
     finally:
         os.unlink(filename)
示例#29
0
    def setUp(self):
        quodlibet.config.init()
        h, self.fname = mkstemp()
        os.close(h)
        with open(self.fname, "w") as f:
            f.write(self.memory)

        with open(self.fname + ".saved", "w") as f:
            f.write(self.saved)
        self.cbes = ComboBoxEntrySave(self.fname, count=2)
        self.cbes2 = ComboBoxEntrySave(self.fname, count=2)
示例#30
0
    def setUp(self):
        config.init()

        self.f = get_temp_copy(get_data_path('silence-44-s.ogg'))
        self.f2 = get_temp_copy(get_data_path('silence-44-s.mp3'))
        self.s = MusicFile(self.f)
        self.s2 = MusicFile(self.f2)

        fd, self.f3 = mkstemp(".mp3")
        os.write(fd, b"garbage")
        os.close(fd)
示例#31
0
    def test_save_load(self):
        fd, filename = mkstemp()
        os.close(fd)
        try:
            self.library.add(self.Frange(30))
            self.library.save(filename)

            library = self.Library()
            library.load(filename)
            for (k, v), (k2, v2) in zip(sorted(self.library.items()),
                                        sorted(library.items())):
                assert k == k2
                assert v.key == v2.key
        finally:
            os.unlink(filename)
 def test_parse_onesong_uri(self):
     h, name = mkstemp()
     os.close(h)
     target = os.path.join(DATA_DIR, "silence-44-s.ogg")
     from quodlibet.util.uri import URI
     target = URI.frompath(target)
     target = self.prefix + target
     f = file(name, "w")
     f.write(target)
     f.close()
     list = self.Parse(name)
     os.unlink(name)
     self.failUnlessEqual(len(list), 1)
     self.failUnlessEqual(list[0]("title"), "Silence")
     list.delete()
示例#33
0
def temp_filename(*args, **kwargs):
    """Creates an empty file and removes it when done.

        with temp_filename() as filename:
            with open(filename, 'w') as h:
                h.write("foo")
            do_stuff(filename)
    """

    from tests import mkstemp

    fd, filename = mkstemp(*args, **kwargs)
    os.close(fd)

    yield filename

    os.remove(filename)
    def create_plugin(self, name='', funcs=None):
        fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir)
        file = os.fdopen(fd, 'w')

        file.write("from quodlibet.plugins.events import EventPlugin\n")
        file.write("log = []\n")
        file.write("class %s(EventPlugin):\n" % name)
        indent = '    '
        file.write("%spass\n" % indent)

        if name:
            file.write("%sPLUGIN_ID = %r\n" % (indent, name))
            file.write("%sPLUGIN_NAME = %r\n" % (indent, name))

        for f in (funcs or []):
            file.write("%sdef %s(s, *args): log.append((%r, args))\n" %
                       (indent, f, f))
        file.flush()
        file.close()
示例#35
0
    def test_init_garbage_file(self):
        config.quit()

        garbage = b"\xf1=\xab\xac"

        fd, filename = mkstemp()
        os.close(fd)
        with open(filename, "wb") as f:
            f.write(garbage)

        config.init(filename)
        self.assertTrue(config.options("player"))

        invalid_filename = filename + ".not-valid"
        self.assertTrue(os.path.exists(invalid_filename))
        with open(invalid_filename, "rb") as f:
            self.assertEqual(f.read(), garbage)

        os.remove(filename)
        os.remove(invalid_filename)
    def test_save_all(self):
        data = JSONObjectDict.from_json(self.WibbleData, self.WIBBLE_JSON_STR)
        fd, filename = mkstemp(suffix=".json")
        os.close(fd)
        try:
            ret = data.save(filename)
            with open(filename, "rb") as f:
                jstr = f.read()
            # Check we also return the string as documented...
            self.failUnlessEqual(jstr, ret)
        finally:
            os.unlink(filename)

        # Check we have the right number of items
        self.failUnlessEqual(len(json.loads(jstr)), len(data))

        # Check them one by one (for convenience of debugging)
        parsed = JSONObjectDict.from_json(self.WibbleData, jstr)
        for o in data.values():
            self.failUnlessEqual(parsed[o.name], o)
示例#37
0
def temp_filename(*args, **kwargs):
    """Creates an empty file and removes it when done.

        with temp_filename() as filename:
            with open(filename, 'w') as h:
                h.write("foo")
            do_stuff(filename)
    """

    from tests import mkstemp

    fd, filename = mkstemp(*args, **kwargs)
    os.close(fd)

    yield filename

    try:
        os.remove(filename)
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise
示例#38
0
    def create_plugin(self,
                      id='',
                      name='',
                      desc='',
                      icon='',
                      funcs=None,
                      mod=False):
        fd, fn = mkstemp(suffix='.py', text=True, dir=self.tempdir)
        file = os.fdopen(fd, 'w')

        if mod:
            indent = ''
        else:
            file.write(
                "from quodlibet.plugins.playlist import PlaylistPlugin\n")
            file.write("class %s(PlaylistPlugin):\n" % name)
            indent = '    '
            file.write("%spass\n" % indent)

        if name:
            file.write("%sPLUGIN_ID = %r\n" % (indent, name))
        if name:
            file.write("%sPLUGIN_NAME = %r\n" % (indent, name))
        if desc:
            file.write("%sPLUGIN_DESC = %r\n" % (indent, desc))
        if icon:
            file.write("%sPLUGIN_ICON = %r\n" % (indent, icon))
        for f in (funcs or []):
            if f in ["__init__"]:
                file.write("%sdef %s(self, *args): super(%s, self).__init__("
                           "*args); raise Exception(\"as expected.\")\n" %
                           (indent, f, name))
            else:
                file.write("%sdef %s(*args): return args\n" % (indent, f))
        file.flush()
        file.close()
示例#39
0
    def test_validate(self):
        # strip translatable prefix from tags
        from xml.etree import ElementTree
        tree = ElementTree.parse(self.PATH)
        for x in tree.iter():
            if x.tag.startswith("_"):
                x.tag = x.tag[1:]
        fd, name = mkstemp(suffix=".appdata.xml")
        os.close(fd)

        with open(name, "wb") as temp:
            header = open(self.PATH, "rb").read().splitlines()[0]
            temp.write(header + b"\n")
            temp.write(ElementTree.tostring(tree.getroot(), encoding="utf-8"))

        # pass to desktop-file-validate
        try:
            subprocess.check_output(
                ["appstream-util", "validate", "--nonet", name],
                stderr=subprocess.STDOUT)
        except subprocess.CalledProcessError as e:
            raise Exception(e.output)
        finally:
            os.remove(name)
示例#40
0
 def setUp(self):
     TVCFile.setUp(self)
     h, self.filename = mkstemp(".flac")
     os.close(h)
     shutil.copy(os.path.join(DATA_DIR, 'empty.flac'), self.filename)
     self.song = FLACFile(self.filename)
示例#41
0
 def setUp(self):
     super(TOperonImageClear, self).setUp()
     fd, self.fcover = mkstemp(".wma")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'test-2.wma'), self.fcover)
     self.cover = MusicFile(self.fcover)
示例#42
0
 def __get_file(self):
     fd, filename = mkstemp(".flac")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'empty.flac'), filename)
     return filename
示例#43
0
 def setUp(self):
     TVCFile.setUp(self)
     h, self.filename = mkstemp(".ogg")
     os.close(h)
     shutil.copy(os.path.join(DATA_DIR, 'empty.opus'), self.filename)
     self.song = OggOpusFile(self.filename)
示例#44
0
 def setUp(self):
     config.init()
     fd, self.filename = mkstemp(".mp3")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mp3'), self.filename)
    def test_hidden_file(self):
        fd, name = mkstemp(dir=self.root, prefix=".")
        os.close(fd)

        assert list(iter_paths(self.root)) == []
示例#46
0
 def setUp(self):
     fd, self.f = mkstemp(".aac")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, self.NAME), self.f)
     self.song = AACFile(self.f)
 def test_one_file(self):
     fd, name = mkstemp(dir=self.root)
     os.close(fd)
     assert list(iter_paths(self.root)) == [name]
示例#48
0
class DummyDPM(DisplayPatternMixin):
    fd, _PATTERN_FN = mkstemp()
    os.close(fd)
示例#49
0
 def setUp(self):
     config.init()
     h, self.filename = mkstemp(".flac")
     os.close(h)
     shutil.copy(os.path.join(DATA_DIR, 'empty.flac'), self.filename)
示例#50
0
 def setUp(self):
     fd, self.f = mkstemp(".wv")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'coverart.wv'), self.f)
     self.s = WavpackFile(self.f)
示例#51
0
 def setUp(self):
     fd, self.f = mkstemp(".ape")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.ape'), self.f)
     self.s = MonkeysAudioFile(self.f)
示例#52
0
 def setUp(self):
     fd, self.f = mkstemp(".mpc")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'silence-44-s.mpc'), self.f)
     self.s = MPCFile(self.f)
示例#53
0
 def setUp(self):
     fd, self.filename = mkstemp()
     os.close(fd)
     config.init()
     self.wrap = SongWrapper(AudioFile(
         {"title": "woo", "~filename": self.filename}))
示例#54
0
 def setUp(self):
     fd, self.f = mkstemp(".m4a")
     os.close(fd)
     shutil.copy(os.path.join(DATA_DIR, 'test.m4a'), self.f)
     self.song = MP4File(self.f)
示例#55
0
 def setUp(self):
     config.init()
     fd, self.fn = mkstemp()
     os.close(fd)
     pb = GdkPixbuf.Pixbuf.new(GdkPixbuf.Colorspace.RGB, True, 8, 150, 10)
     pb.savev(self.fn, "png", [], [])