Exemplo n.º 1
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
Exemplo n.º 2
0
class TFSInterface(TestCase):
    def setUp(self):
        self.p = NullPlayer()
        self.dir = mkdtemp()
        self.filename = os.path.join(self.dir, "foo")
        self.fs = FSInterface(self.filename, self.p)

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

    def do(self):
        while Gtk.events_pending():
            Gtk.main_iteration()

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

    def test_start(self):
        self.p.emit('song_started', AudioFile({"woo": "bar", "~#length": 10}))
        self.do()
        with open(self.filename, "rb") as h:
            self.failUnless(b"woo=bar\n" in h.read())

    def test_song_ended(self):
        self.p.emit('song-started', AudioFile({"woo": "bar", "~#length": 10}))
        self.do()
        self.p.emit('song-ended', {}, False)
        self.do()
        self.failIf(os.path.exists(self.filename))

    def test_elapsed(self):
        self.p.seek(123456)
        self.p.emit('song-started', AudioFile({"~#length": 10}))
        self.do()
        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