diff --git a/test/test_art.py b/test/test_art.py
index e19c7d211..d4ca814a5 100644
--- a/test/test_art.py
+++ b/test/test_art.py
@@ -209,10 +209,10 @@ class AAOTest(UseThePlugin):
def test_aao_scraper_finds_image(self):
body = b"""
-
-
+
+
"""
self.mock_response(self.AAO_URL, body)
album = _common.Bag(asin=self.ASIN)
@@ -261,6 +261,8 @@ class GoogleImageTest(UseThePlugin):
self.assertEqual(list(result_url), [])
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class ArtImporterTest(UseThePlugin):
def setUp(self):
super(ArtImporterTest, self).setUp()
diff --git a/test/test_convert.py b/test/test_convert.py
index ab1fa2504..e6f75c0ad 100644
--- a/test/test_convert.py
+++ b/test/test_convert.py
@@ -64,6 +64,8 @@ class TestHelper(helper.TestHelper):
.format(path, tag))
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class ImportConvertTest(unittest.TestCase, TestHelper):
def setUp(self):
@@ -99,6 +101,8 @@ class ImportConvertTest(unittest.TestCase, TestHelper):
self.assertTrue(os.path.isfile(item.path))
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class ConvertCliTest(unittest.TestCase, TestHelper):
def setUp(self):
@@ -186,6 +190,8 @@ class ConvertCliTest(unittest.TestCase, TestHelper):
self.assertFalse(os.path.exists(converted))
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class NeverConvertLossyFilesTest(unittest.TestCase, TestHelper):
"""Test the effect of the `never_convert_lossy_files` option.
"""
diff --git a/test/test_dbcore.py b/test/test_dbcore.py
index a69ffedbe..00ef2f1fb 100644
--- a/test/test_dbcore.py
+++ b/test/test_dbcore.py
@@ -19,6 +19,7 @@ from __future__ import (division, absolute_import, print_function,
unicode_literals)
import os
+import shutil
import sqlite3
from test._common import unittest
@@ -116,15 +117,29 @@ class TestDatabaseTwoModels(dbcore.Database):
pass
+class TestModelWithGetters(dbcore.Model):
+
+ @classmethod
+ def _getters(cls):
+ return {'aComputedField': (lambda s: 'thing')}
+
+ def _template_funcs(self):
+ return {}
+
+
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class MigrationTest(unittest.TestCase):
"""Tests the ability to change the database schema between
versions.
"""
- def setUp(self):
- handle, self.libfile = mkstemp('db')
+
+ @classmethod
+ def setUpClass(cls):
+ handle, cls.orig_libfile = mkstemp('orig_db')
os.close(handle)
# Set up a database with the two-field schema.
- old_lib = TestDatabase2(self.libfile)
+ old_lib = TestDatabase2(cls.orig_libfile)
# Add an item to the old library.
old_lib._connection().execute(
@@ -133,6 +148,15 @@ class MigrationTest(unittest.TestCase):
old_lib._connection().commit()
del old_lib
+ @classmethod
+ def tearDownClass(cls):
+ os.remove(cls.orig_libfile)
+
+ def setUp(self):
+ handle, self.libfile = mkstemp('db')
+ os.close(handle)
+ shutil.copyfile(self.orig_libfile, self.libfile)
+
def tearDown(self):
os.remove(self.libfile)
@@ -274,6 +298,40 @@ class ModelTest(unittest.TestCase):
model2.load()
self.assertNotIn('flex_field', model2)
+ def test_check_db_fails(self):
+ with self.assertRaisesRegexp(ValueError, 'no database'):
+ dbcore.Model()._check_db()
+ with self.assertRaisesRegexp(ValueError, 'no id'):
+ TestModel1(self.db)._check_db()
+
+ dbcore.Model(self.db)._check_db(need_id=False)
+
+ def test_missing_field(self):
+ with self.assertRaises(AttributeError):
+ TestModel1(self.db).nonExistingKey
+
+ def test_computed_field(self):
+ model = TestModelWithGetters()
+ self.assertEqual(model.aComputedField, 'thing')
+ with self.assertRaisesRegexp(KeyError, 'computed field .+ deleted'):
+ del model.aComputedField
+
+ def test_items(self):
+ model = TestModel1(self.db)
+ model.id = 5
+ self.assertEqual({('id', 5), ('field_one', None)},
+ set(model.items()))
+
+ def test_delete_internal_field(self):
+ model = dbcore.Model()
+ del model._db
+ with self.assertRaises(AttributeError):
+ model._db
+
+ def test_parse_nonstring(self):
+ with self.assertRaisesRegexp(TypeError, "must be a string"):
+ dbcore.Model._parse(None, 42)
+
class FormatTest(unittest.TestCase):
def test_format_fixed_field(self):
@@ -588,6 +646,15 @@ class ResultsIteratorTest(unittest.TestCase):
objs = self.db._fetch(TestModel1)
self.assertEqual(len(objs), 2)
+ def test_out_of_range(self):
+ objs = self.db._fetch(TestModel1)
+ with self.assertRaises(IndexError):
+ objs[100]
+
+ def test_no_results(self):
+ self.assertIsNone(self.db._fetch(
+ TestModel1, dbcore.query.FalseQuery()).get())
+
def suite():
return unittest.TestLoader().loadTestsFromName(__name__)
diff --git a/test/test_edit.py b/test/test_edit.py
index 522437eaa..34bad25a7 100644
--- a/test/test_edit.py
+++ b/test/test_edit.py
@@ -15,6 +15,7 @@
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import codecs
+import os
from mock import patch
from test._common import unittest
@@ -62,6 +63,8 @@ class ModifyFileMocker(object):
f.write(contents)
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class EditCommandTest(unittest.TestCase, TestHelper):
""" Black box tests for `beetsplug.edit`. Command line interaction is
simulated using `test.helper.control_stdin()`, and yaml editing via an
diff --git a/test/test_importer.py b/test/test_importer.py
index b9f75f7ef..27dcd5a12 100644
--- a/test/test_importer.py
+++ b/test/test_importer.py
@@ -236,6 +236,8 @@ class ImportHelper(TestHelper):
self.assertEqual(len(os.listdir(self.libdir)), 0)
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class NonAutotaggedImportTest(_common.TestCase, ImportHelper):
def setUp(self):
self.setup_beets(disk=True)
diff --git a/test/test_logging.py b/test/test_logging.py
index 81df95a78..8517f0a3f 100644
--- a/test/test_logging.py
+++ b/test/test_logging.py
@@ -5,6 +5,7 @@ from __future__ import (division, absolute_import, print_function,
unicode_literals)
import sys
+import os
import threading
import logging as log
from StringIO import StringIO
@@ -163,6 +164,8 @@ class LoggingLevelTest(unittest.TestCase, helper.TestHelper):
self.assertIn('dummy: debug import_stage', logs)
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class ConcurrentEventsTest(TestCase, helper.TestHelper):
"""Similar to LoggingLevelTest but lower-level and focused on multiple
events interaction. Since this is a bit heavy we don't do it in
diff --git a/test/test_ui.py b/test/test_ui.py
index b32a4c452..08097b3f2 100644
--- a/test/test_ui.py
+++ b/test/test_ui.py
@@ -594,6 +594,8 @@ class InputTest(_common.TestCase):
self.assertEqual(album, u'\xc2me')
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class ConfigTest(unittest.TestCase, TestHelper):
def setUp(self):
self.setup_beets()
@@ -1035,6 +1037,8 @@ class PathFormatTest(_common.TestCase):
self.assertEqual(pf[1:], default_formats)
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class PluginTest(_common.TestCase):
def test_plugin_command_from_pluginpath(self):
config['pluginpath'] = [os.path.join(_common.RSRC, 'beetsplug')]
@@ -1042,6 +1046,8 @@ class PluginTest(_common.TestCase):
ui._raw_main(['test'])
+@unittest.skipIf('SKIP_SLOW_TESTS' in os.environ,
+ 'Skipping because test is slow')
class CompletionTest(_common.TestCase):
def test_completion(self):
# Load plugin commands