From bb36b38d527bebb9598ec5db1445736fa662e646 Mon Sep 17 00:00:00 2001 From: spl0k Date: Sat, 11 May 2019 17:13:58 +0200 Subject: [PATCH] Updated tests --- tests/api/test_transcoding.py | 4 ++-- tests/base/test_scanner.py | 44 ++++++++++++++--------------------- tests/issue101.py | 13 +++++------ tests/issue129.py | 4 ++-- tests/issue133.py | 5 ++-- tests/issue139.py | 5 ++-- 6 files changed, 32 insertions(+), 43 deletions(-) diff --git a/tests/api/test_transcoding.py b/tests/api/test_transcoding.py index e1adc4a..0608070 100644 --- a/tests/api/test_transcoding.py +++ b/tests/api/test_transcoding.py @@ -26,8 +26,8 @@ class TranscodingTestCase(ApiTestBase): with db_session: folder = FolderManager.add('Folder', 'tests/assets/folder') scanner = Scanner() - scanner.scan(folder) - scanner.finish() + scanner.queue_folder('Folder') + scanner.run() self.trackid = Track.get().id diff --git a/tests/base/test_scanner.py b/tests/base/test_scanner.py index e3f8ad1..1c34804 100644 --- a/tests/base/test_scanner.py +++ b/tests/base/test_scanner.py @@ -30,11 +30,9 @@ class ScannerTestCase(unittest.TestCase): self.assertIsNotNone(folder) self.folderid = folder.id - self.scanner = Scanner() - self.scanner.scan(folder) + self.__scan() def tearDown(self): - self.scanner.finish() db.release_database() @contextmanager @@ -45,30 +43,27 @@ class ScannerTestCase(unittest.TestCase): tf.write(f.read()) yield tf + def __scan(self, force = False): + self.scanner = Scanner(force) + self.scanner.queue_folder('folder') + self.scanner.run() + @db_session def test_scan(self): self.assertEqual(db.Track.select().count(), 1) - self.assertRaises(TypeError, self.scanner.scan, None) - self.assertRaises(TypeError, self.scanner.scan, 'string') - - @db_session - def test_progress(self): - def progress(processed): - self.assertIsInstance(processed, int) - - self.scanner.scan(db.Folder[self.folderid], progress) + self.assertRaises(TypeError, self.scanner.queue_folder, None) + self.assertRaises(TypeError, self.scanner.queue_folder, db.Folder[self.folderid]) @db_session def test_rescan(self): - self.scanner.scan(db.Folder[self.folderid]) + self.__scan() commit() self.assertEqual(db.Track.select().count(), 1) @db_session def test_force_rescan(self): - self.scanner = Scanner(True) - self.scanner.scan(db.Folder[self.folderid]) + self.__scan(True) commit() self.assertEqual(db.Track.select().count(), 1) @@ -93,7 +88,7 @@ class ScannerTestCase(unittest.TestCase): self.assertEqual(db.Track.select().count(), 1) self.scanner.remove_file(track.path) - self.scanner.finish() + self.scanner.prune() commit() self.assertEqual(db.Track.select().count(), 0) self.assertEqual(db.Album.select().count(), 0) @@ -118,7 +113,7 @@ class ScannerTestCase(unittest.TestCase): self.assertRaises(Exception, self.scanner.move_file, track.path, '/some/inexistent/path') with self.__temporary_track_copy() as tf: - self.scanner.scan(db.Folder[self.folderid]) + self.__scan() commit() self.assertEqual(db.Track.select().count(), 2) self.scanner.move_file(tf.name, track.path) @@ -135,10 +130,9 @@ class ScannerTestCase(unittest.TestCase): @db_session def test_rescan_corrupt_file(self): track = db.Track.select().first() - self.scanner = Scanner(True) with self.__temporary_track_copy() as tf: - self.scanner.scan(db.Folder[self.folderid]) + self.__scan() commit() self.assertEqual(db.Track.select().count(), 2) @@ -146,7 +140,7 @@ class ScannerTestCase(unittest.TestCase): tf.write(b'\x00' * 4096) tf.truncate() - self.scanner.scan(db.Folder[self.folderid]) + self.__scan(True) commit() self.assertEqual(db.Track.select().count(), 1) @@ -155,21 +149,20 @@ class ScannerTestCase(unittest.TestCase): track = db.Track.select().first() with self.__temporary_track_copy() as tf: - self.scanner.scan(db.Folder[self.folderid]) + self.__scan() commit() self.assertEqual(db.Track.select().count(), 2) - self.scanner.scan(db.Folder[self.folderid]) + self.__scan() commit() self.assertEqual(db.Track.select().count(), 1) @db_session def test_scan_tag_change(self): - self.scanner = Scanner(True) folder = db.Folder[self.folderid] with self.__temporary_track_copy() as tf: - self.scanner.scan(folder) + self.__scan() commit() copy = db.Track.get(path = tf.name) self.assertEqual(copy.artist.name, 'Some artist') @@ -180,8 +173,7 @@ class ScannerTestCase(unittest.TestCase): tags['album'] = 'Crappy album' tags.save() - self.scanner.scan(folder) - self.scanner.finish() + self.__scan(True) self.assertEqual(copy.artist.name, 'Renamed artist') self.assertEqual(copy.album.name, 'Crappy album') self.assertIsNotNone(db.Artist.get(name = 'Some artist')) diff --git a/tests/issue101.py b/tests/issue101.py index 92580f5..f176f63 100644 --- a/tests/issue101.py +++ b/tests/issue101.py @@ -37,18 +37,17 @@ class Issue101TestCase(unittest.TestCase): subdir = tempfile.mkdtemp(dir = subdir) shutil.copyfile('tests/assets/folder/silence.mp3', os.path.join(subdir, 'silence.mp3')) - scanner = Scanner() with db_session: - folder = Folder.select(lambda f: f.root).first() - scanner.scan(folder) - scanner.finish() + scanner = Scanner() + scanner.queue_folder('folder') + scanner.run() shutil.rmtree(firstsubdir) with db_session: - folder = Folder.select(lambda f: f.root).first() - scanner.scan(folder) - scanner.finish() + scanner = Scanner() + scanner.queue_folder('folder') + scanner.run() if __name__ == '__main__': diff --git a/tests/issue129.py b/tests/issue129.py index b57c57b..86879a6 100644 --- a/tests/issue129.py +++ b/tests/issue129.py @@ -25,8 +25,8 @@ class Issue129TestCase(TestBase): with db_session: folder = FolderManager.add('folder', os.path.abspath('tests/assets/folder')) scanner = Scanner() - scanner.scan(folder) - scanner.finish() + scanner.queue_folder('folder') + scanner.run() self.trackid = Track.select().first().id self.userid = User.get(name = 'alice').id diff --git a/tests/issue133.py b/tests/issue133.py index 79903f3..a79e5c5 100644 --- a/tests/issue133.py +++ b/tests/issue133.py @@ -33,9 +33,8 @@ class Issue133TestCase(unittest.TestCase): @db_session def test_issue133(self): scanner = Scanner() - folder = Folder.select(lambda f: f.root).first() - scanner.scan(folder) - scanner.finish() + scanner.queue_folder('folder') + scanner.run() del scanner track = Track.select().first() diff --git a/tests/issue139.py b/tests/issue139.py index 55a93c0..3e36a73 100644 --- a/tests/issue139.py +++ b/tests/issue139.py @@ -32,9 +32,8 @@ class Issue139TestCase(unittest.TestCase): @db_session def do_scan(self): scanner = Scanner() - folder = Folder.select(lambda f: f.root).first() - scanner.scan(folder) - scanner.finish() + scanner.queue_folder('folder') + scanner.run() del scanner def test_null_genre(self):