示例#1
0
    def test_music_file(self):
        path = os.path.join(DATA_DIR, 'silence-44-s.mp3')
        self.assertTrue(formats.MusicFile(path))

        # non existing
        with capture_output() as (stdout, stderr):
            song = formats.MusicFile(os.path.join(DATA_DIR, "nope.mp3"))
            self.assertFalse(song)
            self.assertTrue("Error" in stderr.getvalue())

        # unknown extension
        with capture_output() as (stdout, stderr):
            song = formats.MusicFile(os.path.join(DATA_DIR, "nope.xxx"))
            self.assertFalse(song)
            self.assertTrue("extension" in stderr.getvalue())
    def test_add_filename(self):
        config.init()
        try:
            filename = self.__get_file()
            ret = self.library.add_filename(filename)
            self.failUnless(ret)
            self.failUnlessEqual(1, len(self.library))
            self.failUnlessEqual(len(self.added), 1)
            ret = self.library.add_filename(filename)
            self.failUnless(ret)
            self.failUnlessEqual(len(self.added), 1)
            os.unlink(filename)

            filename = self.__get_file()
            ret = self.library.add_filename(filename, add=False)
            self.failUnless(ret)
            self.failIf(ret in self.library)
            self.failUnlessEqual(len(self.added), 1)
            self.library.add([ret])
            self.failUnless(ret in self.library)
            self.failUnlessEqual(len(self.added), 2)
            self.failUnlessEqual(2, len(self.library))
            os.unlink(filename)

            with capture_output():
                ret = self.library.add_filename("")
            self.failIf(ret)
            self.failUnlessEqual(len(self.added), 2)
            self.failUnlessEqual(2, len(self.library))

        finally:
            config.quit()
示例#3
0
 def test_misc(self):
     with capture_output():
         self.__send("play-file /dev/null")
     self.__send("dump-playlist")
     self.__send("dump-queue")
     self.__send("enqueue /dev/null")
     self.__send("enqueue-files /dev/null")
     self.__send("filter album=test")
     self.__send("query '/foobar/'")
     self.__send("focus")
     self.__send("hide-window")
     self.__send("dump-browsers")
     self.__send("open-browser SearchBar")
     from quodlibet.qltk.browser import LibraryBrowser
     for window in Gtk.Window.list_toplevels():
         if isinstance(window, LibraryBrowser):
             window.destroy()
     self.__send("order shuffle")
     self.__send("properties")
     self.__send("queue 1")
     self.__send("quit")
     self.__send("random album")
     self.__send("refresh")
     self.__send("repeat 0")
     self.__send("set-browser 1")
     self.__send("set-rating 0.5")
     self.__send("show-window")
     self.__send("song-list 1")
     self.__send("status")
     self.__send("toggle-window")
     self.__send("unqueue /dev/null")
示例#4
0
 def test_exec_hook(self):
     with capture_output():
         try:
             raise Exception
         except Exception:
             ExceptionDialog.from_except(*sys.exc_info())
             ExceptionDialog.instance.destroy()
    def test_add_filename(self):
        config.init()
        try:
            filename = self.__get_file()
            ret = self.library.add_filename(filename)
            self.failUnless(ret)
            self.failUnlessEqual(1, len(self.library))
            self.failUnlessEqual(len(self.added), 1)
            ret = self.library.add_filename(filename)
            self.failUnless(ret)
            self.failUnlessEqual(len(self.added), 1)
            os.unlink(filename)

            filename = self.__get_file()
            ret = self.library.add_filename(filename, add=False)
            self.failUnless(ret)
            self.failIf(ret in self.library)
            self.failUnlessEqual(len(self.added), 1)
            self.library.add([ret])
            self.failUnless(ret in self.library)
            self.failUnlessEqual(len(self.added), 2)
            self.failUnlessEqual(2, len(self.library))
            os.unlink(filename)

            with capture_output():
                ret = self.library.add_filename("")
            self.failIf(ret)
            self.failUnlessEqual(len(self.added), 2)
            self.failUnlessEqual(2, len(self.library))

        finally:
            config.quit()
 def test_exec_hook(self):
     with capture_output():
         try:
             raise Exception
         except Exception:
             ExceptionDialog.from_except(*sys.exc_info())
             ExceptionDialog.instance.destroy()
示例#7
0
def call(args=None):
    with capture_output() as (out, err):
        try:
            return_code = operon_main(["operon.py"] + args)
        except SystemExit as e:
            return_code = e.code

    return (return_code, out.getvalue(), err.getvalue())
示例#8
0
def call(args=None):
    with capture_output() as (out, err):
        try:
            return_code = operon_main(["operon.py"] + args)
        except SystemExit as e:
            return_code = e.code

    return (return_code, out.getvalue(), err.getvalue())
 def test_from_invalid_json(self):
     # Invalid JSON
     with capture_output():
         jd = JSONObjectDict.from_json(JSONObject, '{"foo":{}')
         self.failIf(jd)
         # Valid but unexpected Command field
         self.failIf(JSONObjectDict.from_json(JSONObject,
             '{"bar":{"name":"bar", "invalid":"foo"}'))
 def test_from_invalid_json(self):
     # Invalid JSON
     with capture_output():
         jd = JSONObjectDict.from_json(JSONObject, '{"foo":{}')
         self.failIf(jd)
         # Valid but unexpected Command field
         self.failIf(
             JSONObjectDict.from_json(
                 JSONObject, '{"bar":{"name":"bar", "invalid":"foo"}'))
示例#11
0
def call(args=None):
    path = os.path.join(os.path.dirname(quodlibet.__path__[0]), "operon.py")
    mod = imp.load_source("operon", path)

    with capture_output() as (out, err):
        try:
            return_code = mod.run(["operon.py"] + args)
        except SystemExit, e:
            return_code = e.code
示例#12
0
def call_safely(func, *args, **kwargs):
    """
    Calls a function with arbitrary args,
    returning a tuple (return code, stdout, stderr).

    `ret_code` is a string sometimes here.

    Safe for QL-style SystemExits.
    """
    with capture_output() as (out, err):
        try:
            ret_code = func(*args, **kwargs)
        except SystemExit as e:
            ret_code = e.code
    return ret_code, out.getvalue(), err.getvalue()
示例#13
0
def call_safely(func, *args, **kwargs):
    """
    Calls a function with arbitrary args,
    returning a tuple (return code, stdout, stderr).

    `ret_code` is a string sometimes here.

    Safe for QL-style SystemExits.
    """
    with capture_output() as (out, err):
        try:
            ret_code = func(*args, **kwargs)
        except SystemExit as e:
            ret_code = e.code
    return ret_code, out.getvalue(), err.getvalue()
示例#14
0
    def test_getter_exception(self):
        class C(GObject.Object):
            @GObject.Property(type=int)
            def prop(self):
                raise ValueError('something bad happend')

        o = C()

        # silence exception printed to stderr
        with capture_output():
            with self.assertRaisesRegex(ValueError, 'something bad happend'):
                o.prop

            with self.assertRaisesRegex(ValueError, 'something bad happend'):
                o.get_property('prop')

            with self.assertRaisesRegex(ValueError, 'something bad happend'):
                o.props.prop
示例#15
0
    def test_getter_exception(self):
        class C(GObject.Object):
            @GObject.Property(type=int)
            def prop(self):
                raise ValueError('something bad happend')

        o = C()

        # silence exception printed to stderr
        with capture_output():
            with self.assertRaisesRegex(ValueError, 'something bad happend'):
                o.prop

            with self.assertRaisesRegex(ValueError, 'something bad happend'):
                o.get_property('prop')

            with self.assertRaisesRegex(ValueError, 'something bad happend'):
                o.props.prop
示例#16
0
    def test_init_garbage_file(self):
        config.quit()

        garbage = "\xf1=\xab\xac"

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

        with capture_output() as (stdout, stderr):
            config.init(filename)
        self.assertTrue(stderr.getvalue())
        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)
示例#17
0
    def test_init_garbage_file(self):
        config.quit()

        garbage = "\xf1=\xab\xac"

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

        with capture_output() as (stdout, stderr):
            config.init(filename)
        self.assertTrue(stderr.getvalue())
        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)
示例#18
0
def call(args=None):
    with capture_output() as (out, err):
        try:
            return_code = operon_main(["operon.py"] + args)
        except SystemExit, e:
            return_code = e.code
示例#19
0
def call(args=None):
    with capture_output() as (out, err):
        try:
            return_code = operon_main(["operon.py"] + args)
        except SystemExit, e:
            return_code = e.code
示例#20
0
 def test_process_arguments_errors_on_invalid_opt(self):
     with self.assertRaises(SystemExit):
         with capture_output():
             cli.process_arguments(["myprog", "--wrong-thing"])
示例#21
0
 def test_process_no_arguments_works(self):
     with capture_output() as (out, err):
         cli.process_arguments(["myprog"])
         self.assertFalse(out.getvalue())
         self.assertFalse(err.getvalue())
示例#22
0
 def test_process_no_arguments_works(self):
     with capture_output() as (out, err):
         cli.process_arguments(["myprog"])
         self.assertFalse(out.getvalue())
         self.assertFalse(err.getvalue())
示例#23
0
 def test_process_arguments_errors_on_invalid_opt(self):
     with self.assertRaises(SystemExit):
         with capture_output():
             cli.process_arguments(["myprog", "--wrong-thing"])