mirror of
https://github.com/beetbox/beets.git
synced 2025-12-30 04:22:40 +01:00
tests for multiple paths feature; legacy path_format overrides
This commit is contained in:
parent
20fe707a09
commit
eb1a6c8ae3
4 changed files with 73 additions and 5 deletions
|
|
@ -398,14 +398,17 @@ class SubcommandsOptionParser(optparse.OptionParser):
|
|||
|
||||
# The root parser and its main function.
|
||||
|
||||
def main():
|
||||
def main(args=None, configfh=None):
|
||||
"""Run the main command-line interface for beets."""
|
||||
# Get the default subcommands.
|
||||
from beets.ui.commands import default_commands
|
||||
|
||||
# Read defaults from config file.
|
||||
config = ConfigParser.SafeConfigParser()
|
||||
config.read(CONFIG_FILE)
|
||||
if configfh:
|
||||
config.readfp(configfh)
|
||||
else:
|
||||
config.read(CONFIG_FILE)
|
||||
|
||||
# Add plugin paths.
|
||||
plugpaths = config_val(config, 'beets', 'pluginpath', '')
|
||||
|
|
@ -432,18 +435,24 @@ def main():
|
|||
help='print debugging information')
|
||||
|
||||
# Parse the command-line!
|
||||
options, subcommand, suboptions, subargs = parser.parse_args()
|
||||
options, subcommand, suboptions, subargs = parser.parse_args(args)
|
||||
|
||||
# Open library file.
|
||||
libpath = options.libpath or \
|
||||
config_val(config, 'beets', 'library', DEFAULT_LIBRARY)
|
||||
directory = options.directory or \
|
||||
config_val(config, 'beets', 'directory', DEFAULT_DIRECTORY)
|
||||
legacy_path_format = config_val(config, 'beets', 'path_format', None)
|
||||
if options.path_format:
|
||||
# If given, -p overrides all path format settings
|
||||
path_formats = {'default': options.path_format}
|
||||
else:
|
||||
path_formats = DEFAULT_PATH_FORMATS
|
||||
if legacy_path_format:
|
||||
# Old path formats override the default values.
|
||||
path_formats = {'default': legacy_path_format}
|
||||
else:
|
||||
# If no legacy path format, use the defaults instead.
|
||||
path_formats = DEFAULT_PATH_FORMATS
|
||||
if config.has_section('paths'):
|
||||
path_formats.update(config.items('paths'))
|
||||
art_filename = \
|
||||
|
|
|
|||
|
|
@ -489,6 +489,19 @@ class AlbumInfoTest(unittest.TestCase):
|
|||
i = self.lib.items().next()
|
||||
self.assertEqual(i.album, 'myNewAlbum')
|
||||
|
||||
def test_albuminfo_change_albumartist_changes_items(self):
|
||||
ai = self.lib.get_album(self.i)
|
||||
ai.albumartist = 'myNewArtist'
|
||||
i = self.lib.items().next()
|
||||
self.assertEqual(i.albumartist, 'myNewArtist')
|
||||
self.assertNotEqual(i.artist, 'myNewArtist')
|
||||
|
||||
def test_albuminfo_change_artist_does_not_change_items(self):
|
||||
ai = self.lib.get_album(self.i)
|
||||
ai.artist = 'myNewArtist'
|
||||
i = self.lib.items().next()
|
||||
self.assertNotEqual(i.artist, 'myNewArtist')
|
||||
|
||||
def test_albuminfo_remove_removes_items(self):
|
||||
item_id = self.i.id
|
||||
self.lib.get_album(self.i).remove()
|
||||
|
|
|
|||
|
|
@ -86,11 +86,15 @@ class MBReleaseDictTest(unittest.TestCase):
|
|||
d = mb.release_dict(release)
|
||||
self.assertEqual(d['album'], 'ALBUM TITLE')
|
||||
self.assertEqual(d['album_id'], 'ALBUM ID')
|
||||
self.assertEqual(d['albumtype'], 'album')
|
||||
self.assertEqual(d['artist'], 'ARTIST NAME')
|
||||
self.assertEqual(d['artist_id'], 'ARTIST ID')
|
||||
self.assertEqual(d['year'], 1984)
|
||||
|
||||
def test_parse_release_type(self):
|
||||
release = self._make_release('1984')
|
||||
d = mb.release_dict(release)
|
||||
self.assertEqual(d['albumtype'], 'album')
|
||||
|
||||
def test_parse_release_full_date(self):
|
||||
release = self._make_release('1987-03-31')
|
||||
d = mb.release_dict(release)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@
|
|||
import unittest
|
||||
import sys
|
||||
import os
|
||||
import textwrap
|
||||
from StringIO import StringIO
|
||||
import _common
|
||||
sys.path.append('..')
|
||||
from beets import library
|
||||
|
|
@ -147,6 +149,46 @@ class InputTest(unittest.TestCase):
|
|||
self.assertEqual(artist, u'\xc2me')
|
||||
self.assertEqual(album, u'\xc2me')
|
||||
|
||||
class ConfigTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.test_cmd = ui.Subcommand('test', help='test')
|
||||
commands.default_commands.append(self.test_cmd)
|
||||
def tearDown(self):
|
||||
commands.default_commands.pop()
|
||||
def _run_main(self, args, config, func):
|
||||
self.test_cmd.func = func
|
||||
ui.main(args + ['test'], StringIO(config))
|
||||
|
||||
def test_paths_section_respected(self):
|
||||
def func(lib, config, opts, args):
|
||||
self.assertEqual(lib.path_formats['x'], 'y')
|
||||
self._run_main([], textwrap.dedent("""
|
||||
[paths]
|
||||
x=y"""), func)
|
||||
|
||||
def test_default_paths_preserved(self):
|
||||
def func(lib, config, opts, args):
|
||||
self.assertEqual(lib.path_formats['default'],
|
||||
ui.DEFAULT_PATH_FORMATS['default'])
|
||||
self._run_main([], textwrap.dedent("""
|
||||
[paths]
|
||||
x=y"""), func)
|
||||
|
||||
def test_default_paths_overriden_by_legacy_path_format(self):
|
||||
def func(lib, config, opts, args):
|
||||
self.assertEqual(lib.path_formats['default'], 'x')
|
||||
self.assertEqual(len(lib.path_formats), 1)
|
||||
self._run_main([], textwrap.dedent("""
|
||||
[beets]
|
||||
path_format=x"""), func)
|
||||
|
||||
def test_paths_section_overriden_by_cli_switch(self):
|
||||
def func(lib, config, opts, args):
|
||||
self.assertEqual(lib.path_formats['default'], 'z')
|
||||
self.assertEqual(len(lib.path_formats), 1)
|
||||
self._run_main(['-p', 'z'], textwrap.dedent("""
|
||||
[paths]
|
||||
x=y"""), func)
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue