mirror of
https://github.com/beetbox/beets.git
synced 2026-02-12 18:31:48 +01:00
clean configuration for testing
This way, unit tests will never see a user's global beets configuration.
This commit is contained in:
parent
f606827cb9
commit
2c45251db9
4 changed files with 13 additions and 5 deletions
|
|
@ -20,4 +20,4 @@ from beets.util import confit
|
|||
|
||||
Library = beets.library.Library
|
||||
|
||||
config = confit.Configuration('beets', __name__)
|
||||
config = confit.Configuration('beets', __name__, False)
|
||||
|
|
|
|||
|
|
@ -607,10 +607,14 @@ class SubcommandsOptionParser(optparse.OptionParser):
|
|||
|
||||
# The root parser and its main function.
|
||||
|
||||
def _raw_main(args):
|
||||
def _raw_main(args, load_config=True):
|
||||
"""A helper function for `main` without top-level exception
|
||||
handling.
|
||||
"""
|
||||
# Load global configuration files.
|
||||
if load_config:
|
||||
config.read()
|
||||
|
||||
# Get the default subcommands.
|
||||
from beets.ui.commands import default_commands
|
||||
|
||||
|
|
|
|||
|
|
@ -88,10 +88,12 @@ class TestCase(unittest.TestCase):
|
|||
completes. Also provides some additional assertion methods.
|
||||
"""
|
||||
def setUp(self):
|
||||
self.old_sources = copy.deepcopy(beets.config.sources)
|
||||
# A "clean" source list including only the defaults.
|
||||
beets.config.sources = []
|
||||
beets.config.read(user=False, defaults=True)
|
||||
|
||||
def tearDown(self):
|
||||
beets.config.sources = self.old_sources
|
||||
pass
|
||||
|
||||
def assertExists(self, path):
|
||||
self.assertTrue(os.path.exists(path),
|
||||
|
|
|
|||
|
|
@ -443,9 +443,11 @@ class PrintTest(_common.TestCase):
|
|||
|
||||
class AutotagTest(_common.TestCase):
|
||||
def setUp(self):
|
||||
super(AutotagTest, self).setUp()
|
||||
self.io = _common.DummyIO()
|
||||
self.io.install()
|
||||
def tearDown(self):
|
||||
super(AutotagTest, self).tearDown()
|
||||
self.io.restore()
|
||||
|
||||
def _no_candidates_test(self, result):
|
||||
|
|
@ -506,7 +508,7 @@ class ConfigTest(_common.TestCase):
|
|||
if config_yaml:
|
||||
config_data = yaml.load(config_yaml, Loader=confit.Loader)
|
||||
config.set(config_data)
|
||||
ui._raw_main(args + ['test'])
|
||||
ui._raw_main(args + ['test'], False)
|
||||
|
||||
def test_paths_section_respected(self):
|
||||
def func(lib, opts, args):
|
||||
|
|
|
|||
Loading…
Reference in a new issue