diff --git a/test/_common.py b/test/_common.py index 2f230c304..ab73481c3 100644 --- a/test/_common.py +++ b/test/_common.py @@ -123,9 +123,30 @@ def import_session(lib=None, loghandler=None, paths=[], query=[], cli=False): return cls(lib, loghandler, paths, query) +class Assertions(object): + """A mixin with additional unit test assertions.""" + + def assertExists(self, path): # noqa + self.assertTrue(os.path.exists(path), + u'file does not exist: {!r}'.format(path)) + + def assertNotExists(self, path): # noqa + self.assertFalse(os.path.exists(path), + u'file exists: {!r}'.format((path))) + + def assert_equal_path(self, a, b): + """Check that two paths are equal.""" + # The common case. + if a == b: + return + + self.assertEqual(util.normpath(a), util.normpath(b), + u'paths are not equal: {!r} and {!r}'.format(a, b)) + + # A test harness for all beets tests. # Provides temporary, isolated configuration. -class TestCase(unittest.TestCase): +class TestCase(unittest.TestCase, Assertions): """A unittest.TestCase subclass that saves and restores beets' global configuration. This allows tests to make temporary modifications that will then be automatically removed when the test @@ -164,23 +185,6 @@ class TestCase(unittest.TestCase): beets.config.clear() beets.config._materialized = False - def assertExists(self, path): # noqa - self.assertTrue(os.path.exists(path), - u'file does not exist: {!r}'.format(path)) - - def assertNotExists(self, path): # noqa - self.assertFalse(os.path.exists(path), - u'file exists: {!r}'.format((path))) - - def assert_equal_path(self, a, b): - """Check that two paths are equal.""" - # The common case. - if a == b: - return - - self.assertEqual(util.normpath(a), util.normpath(b), - u'paths not equal: {!r} and {!r}'.format(a, b)) - class LibTestCase(TestCase): """A test case that includes an in-memory library object (`lib`) and diff --git a/test/test_ui.py b/test/test_ui.py index c8b6a99d3..ca3c6cbdf 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -635,7 +635,7 @@ class InputTest(_common.TestCase): @_common.slow_test() -class ConfigTest(unittest.TestCase, TestHelper): +class ConfigTest(unittest.TestCase, TestHelper, _common.Assertions): def setUp(self): self.setup_beets() @@ -821,10 +821,14 @@ class ConfigTest(unittest.TestCase, TestHelper): file.write('statefile: state') ui._raw_main(['--config', cli_config_path, 'test']) - self.assertEqual(config['library'].as_filename(), - os.path.join(self.user_config_dir, 'beets.db')) - self.assertEqual(config['statefile'].as_filename(), - os.path.join(self.user_config_dir, 'state')) + self.assert_equal_path( + config['library'].as_filename(), + os.path.join(self.user_config_dir, 'beets.db') + ) + self.assert_equal_path( + config['statefile'].as_filename(), + os.path.join(self.user_config_dir, 'state') + ) def test_cli_config_paths_resolve_relative_to_beetsdir(self): os.environ['BEETSDIR'] = self.beetsdir @@ -835,16 +839,16 @@ class ConfigTest(unittest.TestCase, TestHelper): file.write('statefile: state') ui._raw_main(['--config', cli_config_path, 'test']) - self.assertEqual(config['library'].as_filename(), - os.path.join(self.beetsdir, 'beets.db')) - self.assertEqual(config['statefile'].as_filename(), - os.path.join(self.beetsdir, 'state')) + self.assert_equal_path(config['library'].as_filename(), + os.path.join(self.beetsdir, 'beets.db')) + self.assert_equal_path(config['statefile'].as_filename(), + os.path.join(self.beetsdir, 'state')) def test_command_line_option_relative_to_working_dir(self): os.chdir(self.temp_dir) ui._raw_main(['--library', 'foo.db', 'test']) - self.assertEqual(config['library'].as_filename(), - os.path.join(os.getcwd(), 'foo.db')) + self.assert_equal_path(config['library'].as_filename(), + os.path.join(os.getcwd(), 'foo.db')) def test_cli_config_file_loads_plugin_commands(self): plugin_path = os.path.join(_common.RSRC, 'beetsplug')