1# This program is free software; you can redistribute it and/or modify 2# it under the terms of the GNU General Public License as published by 3# the Free Software Foundation; either version 2 of the License, or 4# (at your option) any later version. 5 6import os 7 8from quodlibet import app 9from tests import TestCase, destroy_fake_app, init_fake_app 10 11from senf import mkstemp 12 13from quodlibet.player.nullbe import NullPlayer 14from quodlibet.qltk.info import SongInfo 15from quodlibet.library import SongLibrary 16 17 18SOME_PATTERN = "foo\n[big]<title>[/big] - <artist>" 19 20 21class FakePatternEdit(object): 22 @property 23 def text(self): 24 return SOME_PATTERN 25 26 27class TSongInfo(TestCase): 28 29 def setUp(self): 30 init_fake_app() 31 fd, self.filename = mkstemp() 32 os.close(fd) 33 self.info = SongInfo(SongLibrary(), NullPlayer(), self.filename) 34 35 def test_save(self): 36 fake_edit = FakePatternEdit() 37 self.info._on_set_pattern(None, fake_edit, app.player) 38 with open(self.filename, "r") as f: 39 contents = f.read() 40 self.failUnlessEqual(contents, SOME_PATTERN + "\n") 41 42 def tearDown(self): 43 destroy_fake_app() 44 self.info.destroy() 45 os.unlink(self.filename) 46