tests: close databases to avoid errors on Windows

Fixes #655 and makes progress on #670.
This commit is contained in:
Adrian Sampson 2014-04-12 15:00:17 -07:00
parent 237458fbb6
commit ed8002bed5
4 changed files with 35 additions and 1 deletions

View file

@ -122,7 +122,10 @@ class TestCase(unittest.TestCase):
def tearDown(self):
if os.path.isdir(self.temp_dir):
shutil.rmtree(self.temp_dir)
os.environ['HOME'] = self._old_home
if self._old_home is None:
del os.environ['HOME']
else:
os.environ['HOME'] = self._old_home
self.io.restore()
def assertExists(self, path):
@ -142,6 +145,9 @@ class LibTestCase(TestCase):
self.lib = beets.library.Library(':memory:')
self.i = item(self.lib)
def tearDown(self):
self.lib._connection().close()
super(LibTestCase, self).tearDown()

View file

@ -233,6 +233,7 @@ class ArtImporterTest(_common.TestCase):
self.task.set_choice(AlbumMatch(0, info, {}, set(), set()))
def tearDown(self):
self.lib._connection().close()
super(ArtImporterTest, self).tearDown()
fetchart.art_for_album = self.old_afa

View file

@ -40,10 +40,12 @@ class TestModel1(dbcore.Model):
def _template_funcs(self):
return {}
class TestDatabase1(dbcore.Database):
_models = (TestModel1,)
pass
class TestModel2(TestModel1):
_fields = {
'id': dbcore.types.Id(),
@ -51,10 +53,12 @@ class TestModel2(TestModel1):
'field_two': dbcore.types.Integer(),
}
class TestDatabase2(dbcore.Database):
_models = (TestModel2,)
pass
class TestModel3(TestModel1):
_fields = {
'id': dbcore.types.Id(),
@ -63,10 +67,12 @@ class TestModel3(TestModel1):
'field_three': dbcore.types.Integer(),
}
class TestDatabase3(dbcore.Database):
_models = (TestModel3,)
pass
class TestModel4(TestModel1):
_fields = {
'id': dbcore.types.Id(),
@ -76,10 +82,12 @@ class TestModel4(TestModel1):
'field_four': dbcore.types.Integer(),
}
class TestDatabase4(dbcore.Database):
_models = (TestModel4,)
pass
class AnotherTestModel(TestModel1):
_table = 'another'
_flex_table = 'anotherflex'
@ -88,6 +96,7 @@ class AnotherTestModel(TestModel1):
'foo': dbcore.types.Integer(),
}
class TestDatabaseTwoModels(dbcore.Database):
_models = (TestModel2, AnotherTestModel)
pass
@ -153,6 +162,10 @@ class ModelTest(_common.TestCase):
dbfile = os.path.join(self.temp_dir, 'temp.db')
self.db = TestDatabase1(dbfile)
def tearDown(self):
self.db._connection().close()
super(ModelTest, self).tearDown()
def test_add_model(self):
model = TestModel1()
model.add(self.db)

View file

@ -124,6 +124,9 @@ class ImportHelper(object):
('comp:true', os.path.join('compilations','$album', '$title')),
]
def _close_library(self):
self.lib._connection().close()
def _create_import_dir(self, count=3):
"""Creates a directory with media files to import.
Sets ``self.import_dir`` to the path of the directory. Also sets
@ -240,6 +243,10 @@ class NonAutotaggedImportTest(_common.TestCase, ImportHelper):
self._create_import_dir(2)
self._setup_import_session(autotag=False)
def tearDown(self):
self._close_library()
super(NonAutotaggedImportTest, self).tearDown()
def test_album_created_with_track_artist(self):
self.importer.run()
albums = self.lib.albums()
@ -337,6 +344,7 @@ class ImportSingletonTest(_common.TestCase, ImportHelper):
self.matcher = AutotagStub().install()
def tearDown(self):
self._close_library()
super(ImportSingletonTest, self).tearDown()
self.matcher.restore()
@ -424,6 +432,7 @@ class ImportTest(_common.TestCase, ImportHelper):
self.matcher.macthin = AutotagStub.GOOD
def tearDown(self):
self._close_library()
super(ImportTest, self).tearDown()
self.matcher.restore()
@ -507,6 +516,7 @@ class ImportTracksTest(_common.TestCase, ImportHelper):
self.matcher = AutotagStub().install()
def tearDown(self):
self._close_library()
super(ImportTracksTest, self).tearDown()
self.matcher.restore()
@ -541,6 +551,7 @@ class ImportCompilationTest(_common.TestCase, ImportHelper):
self.matcher = AutotagStub().install()
def tearDown(self):
self._close_library()
super(ImportCompilationTest, self).tearDown()
self.matcher.restore()
@ -620,6 +631,7 @@ class ImportExistingTest(_common.TestCase, ImportHelper):
self._setup_import_session(import_dir=self.libdir)
def tearDown(self):
self._close_library()
super(ImportExistingTest, self).tearDown()
self.matcher.restore()
@ -732,6 +744,7 @@ class GroupAlbumsImportTest(_common.TestCase, ImportHelper):
self.importer.add_choice(importer.action.ASIS)
def tearDown(self):
self._close_library()
super(GroupAlbumsImportTest, self).tearDown()
self.matcher.restore()
@ -799,6 +812,7 @@ class ChooseCandidateTest(_common.TestCase, ImportHelper):
self.matcher.matching = AutotagStub.BAD
def tearDown(self):
self._close_library()
super(ChooseCandidateTest, self).tearDown()
self.matcher.restore()