From 61416da0a724bb4e3f9751ead2f85c790a018f75 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Tue, 19 Aug 2014 12:27:35 -0700 Subject: [PATCH] Better isolation for ConfigTest --- test/helper.py | 3 ++- test/test_ui.py | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/test/helper.py b/test/helper.py index 709e4e165..bfbd378d0 100644 --- a/test/helper.py +++ b/test/helper.py @@ -155,7 +155,8 @@ class TestHelper(object): def teardown_beets(self): del self.lib._connections - del os.environ['BEETSDIR'] + if 'BEETSDIR' in os.environ: + del os.environ['BEETSDIR'] self.remove_temp_dir() self.config.clear() beets.config.read(user=False, defaults=True) diff --git a/test/test_ui.py b/test/test_ui.py index e1190b621..45b7cfece 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -22,14 +22,13 @@ import platform import _common from _common import unittest -from helper import capture_stdout, has_program +from helper import capture_stdout, has_program, TestHelper from beets import library from beets import ui from beets.ui import commands from beets import autotag from beets.autotag.match import distance -from beets import importer from beets.mediafile import MediaFile from beets import config from beets import plugins @@ -502,9 +501,16 @@ class InputTest(_common.TestCase): self.assertEqual(album, u'\xc2me') -class ConfigTest(_common.TestCase): +class ConfigTest(unittest.TestCase, TestHelper): def setUp(self): - super(ConfigTest, self).setUp() + self.setup_beets() + + # Don't use the BEETSDIR from `helper`. Instead, we point the home + # directory there. Some tests will set `BEETSDIR` themselves. + del os.environ['BEETSDIR'] + self._old_home = os.environ.get('HOME') + os.environ['HOME'] = self.temp_dir + self._orig_cwd = os.getcwd() self.test_cmd = self._make_test_cmd() commands.default_commands.append(self.test_cmd) @@ -530,13 +536,9 @@ class ConfigTest(_common.TestCase): def tearDown(self): commands.default_commands.pop() - if 'BEETSDIR' in os.environ: - del os.environ['BEETSDIR'] - if os.getcwd != self._orig_cwd: - os.chdir(self._orig_cwd) - if hasattr(self.test_cmd, 'lib'): - self.test_cmd.lib._connection().close() - super(ConfigTest, self).tearDown() + os.chdir(self._orig_cwd) + os.environ['HOME'] = self._old_home + self.teardown_beets() def _make_test_cmd(self): test_cmd = ui.Subcommand('test', help='test') @@ -551,10 +553,8 @@ class ConfigTest(_common.TestCase): def _reset_config(self): # Config should read files again on demand - config.sources = [] + config.clear() config._materialized = False - config._lazy_suffix = [] - config._lazy_prefix = [] def write_config_file(self): return open(self.user_config_path, 'w')