From 3e5ef375c88fde4dba9166d3d069f23f4c379993 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Fri, 14 Dec 2012 15:23:47 -0800 Subject: [PATCH] confit-ify remaining tests except for ConfigTest --- beets/util/confit.py | 2 +- beets/util/functemplate.py | 3 ++ test/test_ui.py | 85 +++++++++++--------------------------- 3 files changed, 28 insertions(+), 62 deletions(-) diff --git a/beets/util/confit.py b/beets/util/confit.py index b26fae4b1..a5fd40026 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -293,7 +293,7 @@ class ConfigView(object): out = [] for item in it: - if isinstance(item, list) and len(item) == 2: + if isinstance(item, (list, tuple)) and len(item) == 2: out.append(tuple(item)) elif isinstance(item, dict) and len(item) == 1: out.append(iter_first(item.items())) diff --git a/beets/util/functemplate.py b/beets/util/functemplate.py index 94cdf6c15..bd9c963e1 100644 --- a/beets/util/functemplate.py +++ b/beets/util/functemplate.py @@ -496,6 +496,9 @@ class Template(object): self.original = template self.compiled = self.translate() + def __eq__(self, other): + return self.original == other.original + def interpret(self, values={}, functions={}): """Like `substitute`, but forces the interpreter (rather than the compiled version) to be used. The interpreter includes diff --git a/test/test_ui.py b/test/test_ui.py index d4c1175bf..43206fba5 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -48,7 +48,7 @@ class ListTest(unittest.TestCase): self.io.restore() def _run_list(self, query='', album=False, path=False, fmt=None): - commands.list_items(self.lib, query, album, fmt, None) + commands.list_items(self.lib, query, album, fmt) def test_list_outputs_item(self): self._run_list() @@ -134,14 +134,14 @@ class RemoveTest(unittest.TestCase): def test_remove_items_no_delete(self): self.io.addinput('y') - commands.remove_items(self.lib, '', False, False, None) + commands.remove_items(self.lib, '', False, False) items = self.lib.items() self.assertEqual(len(list(items)), 0) self.assertTrue(os.path.exists(self.i.path)) def test_remove_items_with_delete(self): self.io.addinput('y') - commands.remove_items(self.lib, '', False, True, None) + commands.remove_items(self.lib, '', False, True) items = self.lib.items() self.assertEqual(len(list(items)), 0) self.assertFalse(os.path.exists(self.i.path)) @@ -167,7 +167,7 @@ class ModifyTest(unittest.TestCase): def _modify(self, mods, query=(), write=False, move=False, album=False): self.io.addinput('y') commands.modify_items(self.lib, mods, query, - write, move, album, True, True, None) + write, move, album, True) def test_modify_item_dbdata(self): self._modify(["title=newTitle"]) @@ -469,10 +469,11 @@ class AutotagTest(unittest.TestCase): class ImportTest(unittest.TestCase): def test_quiet_timid_disallowed(self): - self.assertRaises(ui.UserError, commands.import_files, - None, [], False, False, False, False, None, - False, False, False, True, False, None, False, True, - None, False, [], False) + with _common.temp_config(): + config['import']['quiet'] = True + config['import']['timid'] = True + self.assertRaises(ui.UserError, commands.import_files, None, [], + None) class InputTest(unittest.TestCase): def setUp(self): @@ -511,9 +512,10 @@ class ConfigTest(unittest.TestCase): x=y"""), func) def test_default_paths_preserved(self): + default_formats = ui.get_path_formats() def func(lib, opts, args): self.assertEqual(lib.path_formats[1:], - ui.DEFAULT_PATH_FORMATS) + default_formats) self._run_main([], textwrap.dedent(""" [paths] x=y"""), func) @@ -667,11 +669,13 @@ class ShowChangeTest(unittest.TestCase): items = items or self.items info = info or self.info mapping = dict(zip(items, info.tracks)) - commands.show_change( - cur_artist, - cur_album, - autotag.AlbumMatch(0.1, info, mapping, set(), set()), - ) + with _common.temp_config(): + config['color'] = False + commands.show_change( + cur_artist, + cur_album, + autotag.AlbumMatch(0.1, info, mapping, set(), set()), + ) return self.io.getoutput().lower() def test_null_change(self): @@ -711,58 +715,17 @@ class ShowChangeTest(unittest.TestCase): self.assertTrue(u'caf\xe9.mp3 -> the title' in msg or u'caf.mp3 ->' in msg) -class DefaultPathTest(unittest.TestCase): - def setUp(self): - self.old_home = os.environ.get('HOME') - self.old_appdata = os.environ.get('APPDATA') - os.environ['HOME'] = 'xhome' - os.environ['APPDATA'] = 'xappdata' - def tearDown(self): - if self.old_home is None: - del os.environ['HOME'] - else: - os.environ['HOME'] = self.old_home - if self.old_appdata is None: - del os.environ['APPDATA'] - else: - os.environ['APPDATA'] = self.old_appdata - - def test_unix_paths_in_home(self): - import posixpath - config, lib, libdir = ui.default_paths(posixpath) - self.assertEqual(config, 'xhome/.beetsconfig') - self.assertEqual(lib, 'xhome/.beetsmusic.blb') - self.assertEqual(libdir, 'xhome/Music') - - def test_windows_paths_in_home_and_appdata(self): - import ntpath - config, lib, libdir = ui.default_paths(ntpath) - self.assertEqual(config, 'xappdata\\beetsconfig.ini') - self.assertEqual(lib, 'xappdata\\beetsmusic.blb') - self.assertEqual(libdir, 'xhome\\Music') - class PathFormatTest(unittest.TestCase): - def _config(self, text): - cp = ConfigParser.SafeConfigParser() - cp.readfp(StringIO(text)) - return cp - - def _paths_for(self, text): - return ui._get_path_formats(self._config("[paths]\n%s" % - textwrap.dedent(text))) - - def test_default_paths(self): - pf = self._paths_for("") - self.assertEqual(pf, ui.DEFAULT_PATH_FORMATS) - def test_custom_paths_prepend(self): - pf = self._paths_for(""" - foo: bar - """) + default_formats = ui.get_path_formats() + + with _common.temp_config(): + config['paths'] = [('foo', 'bar')] + pf = ui.get_path_formats() key, tmpl = pf[0] self.assertEqual(key, 'foo') self.assertEqual(tmpl.original, 'bar') - self.assertEqual(pf[1:], ui.DEFAULT_PATH_FORMATS) + self.assertEqual(pf[1:], default_formats) def suite(): return unittest.TestLoader().loadTestsFromName(__name__)