mirror of
https://github.com/beetbox/beets.git
synced 2026-01-30 12:02:41 +01:00
Merge pull request #1807 from JesseWeinstein/add_tests
Add & modify tests
This commit is contained in:
commit
0e0691bf77
7 changed files with 96 additions and 7 deletions
|
|
@ -209,10 +209,10 @@ class AAOTest(UseThePlugin):
|
|||
def test_aao_scraper_finds_image(self):
|
||||
body = b"""
|
||||
<br />
|
||||
<a href="TARGET_URL" title="View larger image"
|
||||
class="thickbox" style="color: #7E9DA2; text-decoration:none;">
|
||||
<img src="http://www.albumart.org/images/zoom-icon.jpg"
|
||||
alt="View larger image" width="17" height="15" border="0"/></a>
|
||||
<a href=\"TARGET_URL\" title=\"View larger image\"
|
||||
class=\"thickbox\" style=\"color: #7E9DA2; text-decoration:none;\">
|
||||
<img src=\"http://www.albumart.org/images/zoom-icon.jpg\"
|
||||
alt=\"View larger image\" width=\"17\" height=\"15\" border=\"0\"/></a>
|
||||
"""
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -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__)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue