Merge pull request #1796 from JesseWeinstein/add_tests

More test improvements
This commit is contained in:
Adrian Sampson 2016-01-10 16:24:00 -08:00
commit d4e11f0af9
3 changed files with 72 additions and 29 deletions

View file

@ -36,6 +36,7 @@ class FtInTitlePluginFunctional(unittest.TestCase, TestHelper):
def _ft_add_item(self, path, artist, title, aartist):
return self.add_item(path=path,
artist=artist,
artist_sort=artist,
title=title,
albumartist=aartist)
@ -51,6 +52,14 @@ class FtInTitlePluginFunctional(unittest.TestCase, TestHelper):
self.assertEqual(item['artist'], u'Alice')
self.assertEqual(item['title'], u'Song 1')
def test_functional_not_found(self):
item = self._ft_add_item('/', u'Alice ft Bob', u'Song 1', u'George')
self.run_command('ftintitle', '-d')
item.load()
# item should be unchanged
self.assertEqual(item['artist'], u'Alice ft Bob')
self.assertEqual(item['title'], u'Song 1')
def test_functional_custom_format(self):
self._ft_set_config('feat. {0}')
item = self._ft_add_item('/', u'Alice ft Bob', u'Song 1', u'Alice')
@ -126,6 +135,11 @@ class FtInTitlePluginTest(unittest.TestCase):
'album_artist': 'Bob',
'feat_part': 'Alice'
},
{
'artist': 'Alice ft. Carol',
'album_artist': 'Bob',
'feat_part': None
},
]
for test_case in test_cases:

View file

@ -5,6 +5,9 @@
from __future__ import (division, absolute_import, print_function,
unicode_literals)
import os
from mock import patch, Mock
from test._common import unittest
from test.helper import TestHelper
from beetsplug.permissions import (check_permissions,
@ -26,45 +29,45 @@ class PermissionsPluginTest(unittest.TestCase, TestHelper):
self.unload_plugins()
def test_permissions_on_album_imported(self):
self.importer = self.create_importer()
self.importer.run()
item = self.lib.items().get()
file_perm = self.config['permissions']['file'].get()
file_perm = convert_perm(file_perm)
dir_perm = self.config['permissions']['dir'].get()
dir_perm = convert_perm(dir_perm)
music_dirs = dirs_in_library(self.lib.directory, item.path)
self.assertTrue(check_permissions(item.path, file_perm))
self.assertFalse(check_permissions(item.path, convert_perm(644)))
for path in music_dirs:
self.assertTrue(check_permissions(path, dir_perm))
self.assertFalse(check_permissions(path, convert_perm(644)))
self.do_thing(True)
def test_permissions_on_item_imported(self):
self.config['import']['singletons'] = True
self.do_thing(True)
@patch("os.chmod", Mock())
def test_failing_to_set_permissions(self):
self.do_thing(False)
def do_thing(self, expectSuccess):
def get_stat(v):
return os.stat(
os.path.join(self.temp_dir, 'import', *v)).st_mode & 0o777
self.importer = self.create_importer()
typs = ['file', 'dir']
self.exp_perms = {
True: {k: convert_perm(self.config['permissions'][k].get())
for k in typs},
False: {k: get_stat(v)
for (k, v) in zip(typs, (('album 0', 'track 0.mp3'), ()))}}
self.importer.run()
item = self.lib.items().get()
file_perm = self.config['permissions']['file'].get()
file_perm = convert_perm(file_perm)
self.assertPerms(item.path, 'file', expectSuccess)
dir_perm = self.config['permissions']['dir'].get()
dir_perm = convert_perm(dir_perm)
for path in dirs_in_library(self.lib.directory, item.path):
self.assertPerms(path, 'dir', expectSuccess)
music_dirs = dirs_in_library(self.lib.directory, item.path)
def assertPerms(self, path, typ, expectSuccess):
for x in [(True, self.exp_perms[expectSuccess][typ], '!='),
(False, self.exp_perms[not expectSuccess][typ], '==')]:
self.assertEqual(x[0], check_permissions(path, x[1]),
msg='{} : {} {} {}'.format(
path, oct(os.stat(path).st_mode), x[2], oct(x[1])))
self.assertTrue(check_permissions(item.path, file_perm))
self.assertFalse(check_permissions(item.path, convert_perm(644)))
for path in music_dirs:
self.assertTrue(check_permissions(path, dir_perm))
self.assertFalse(check_permissions(path, convert_perm(644)))
def test_convert_perm_from_string(self):
self.assertEqual(convert_perm('10'), 8)
def suite():

View file

@ -1129,6 +1129,32 @@ class CommonOptionsParserCliTest(unittest.TestCase, TestHelper):
'--format-album', '$albumartist', 'ls', '-a')
self.assertEqual(l, 'the album artist\n')
def test_help(self):
l = self.run_with_output('help')
self.assertIn('Usage:', l)
l = self.run_with_output('help', 'list')
self.assertIn('Usage:', l)
with self.assertRaises(ui.UserError):
self.run_command('help', 'this.is.not.a.real.command')
def test_stats(self):
l = self.run_with_output('stats')
self.assertIn('Approximate total size:', l)
# # Need to have more realistic library setup for this to work
# l = self.run_with_output('stats', '-e')
# self.assertIn('Total size:', l)
def test_version(self):
l = self.run_with_output('version')
self.assertIn('no plugins loaded', l)
# # Need to have plugin loaded
# l = self.run_with_output('version')
# self.assertIn('plugins: ', l)
class CommonOptionsParserTest(unittest.TestCase, TestHelper):
def setUp(self):