mirror of
https://github.com/beetbox/beets.git
synced 2026-01-04 06:53:27 +01:00
Pythonic names for test helpers
This commit is contained in:
parent
3549f9785c
commit
7639267f8f
4 changed files with 25 additions and 25 deletions
|
|
@ -32,10 +32,10 @@ import _common
|
|||
|
||||
|
||||
@contextmanager
|
||||
def controlStdin(input=None):
|
||||
def control_stdin(input=None):
|
||||
"""Sends ``input`` to stdin.
|
||||
|
||||
>>> with controlStdin('yes'):
|
||||
>>> with control_stdin('yes'):
|
||||
... input()
|
||||
'yes'
|
||||
"""
|
||||
|
|
@ -49,10 +49,10 @@ def controlStdin(input=None):
|
|||
|
||||
|
||||
@contextmanager
|
||||
def captureStdout():
|
||||
def capture_stdout():
|
||||
"""Save stdout in a StringIO.
|
||||
|
||||
>>> with captureStdout() as output:
|
||||
>>> with capture_stdout() as output:
|
||||
... print('spam')
|
||||
...
|
||||
>>> output.getvalue()
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ from beets import config
|
|||
|
||||
import _common
|
||||
from _common import unittest
|
||||
from helper import TestHelper, captureStdout
|
||||
from helper import TestHelper, capture_stdout
|
||||
|
||||
|
||||
class ConfigCommandTest(unittest.TestCase, TestHelper):
|
||||
|
|
@ -36,13 +36,13 @@ class ConfigCommandTest(unittest.TestCase, TestHelper):
|
|||
rmtree(self.temp_dir)
|
||||
|
||||
def test_show_user_config(self):
|
||||
with captureStdout() as output:
|
||||
with capture_stdout() as output:
|
||||
self.run_command('config')
|
||||
output = yaml.load(output.getvalue())
|
||||
self.assertEqual(output['option'], 'value')
|
||||
|
||||
def test_show_user_config_with_defaults(self):
|
||||
with captureStdout() as output:
|
||||
with capture_stdout() as output:
|
||||
self.run_command('config', '-d')
|
||||
output = yaml.load(output.getvalue())
|
||||
self.assertEqual(output['option'], 'value')
|
||||
|
|
@ -50,21 +50,21 @@ class ConfigCommandTest(unittest.TestCase, TestHelper):
|
|||
self.assertEqual(output['import']['timid'], False)
|
||||
|
||||
def test_show_user_config_with_cli(self):
|
||||
with captureStdout() as output:
|
||||
with capture_stdout() as output:
|
||||
self.run_command('--config', self.cli_config_path, 'config')
|
||||
output = yaml.load(output.getvalue())
|
||||
self.assertEqual(output['library'], 'lib')
|
||||
self.assertEqual(output['option'], 'cli overwrite')
|
||||
|
||||
def test_config_paths(self):
|
||||
with captureStdout() as output:
|
||||
with capture_stdout() as output:
|
||||
self.run_command('config', '-p')
|
||||
paths = output.getvalue().split('\n')
|
||||
self.assertEqual(len(paths), 2)
|
||||
self.assertEqual(paths[0], self.config_path)
|
||||
|
||||
def test_config_paths_with_cli(self):
|
||||
with captureStdout() as output:
|
||||
with capture_stdout() as output:
|
||||
self.run_command('--config', self.cli_config_path, 'config', '-p')
|
||||
paths = output.getvalue().split('\n')
|
||||
self.assertEqual(len(paths), 3)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
import os.path
|
||||
from _common import unittest
|
||||
from helper import TestHelper, controlStdin
|
||||
from helper import TestHelper, control_stdin
|
||||
|
||||
class ImportConvertTest(unittest.TestCase, TestHelper):
|
||||
|
||||
|
|
@ -76,7 +76,7 @@ class ConvertCliTest(unittest.TestCase, TestHelper):
|
|||
self.unload_plugins()
|
||||
|
||||
def test_convert(self):
|
||||
with controlStdin('y'):
|
||||
with control_stdin('y'):
|
||||
self.run_command('convert', self.item.path)
|
||||
converted = os.path.join(self.convert_dest, 'converted.mp3')
|
||||
self.assertTrue(os.path.isfile(converted))
|
||||
|
|
@ -84,7 +84,7 @@ class ConvertCliTest(unittest.TestCase, TestHelper):
|
|||
def test_convert_keep_new(self):
|
||||
self.assertEqual(os.path.splitext(self.item.path)[1], '.ogg')
|
||||
|
||||
with controlStdin('y'):
|
||||
with control_stdin('y'):
|
||||
self.run_command('convert', '--keep-new', self.item.path)
|
||||
|
||||
self.item.load()
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import subprocess
|
|||
|
||||
import _common
|
||||
from _common import unittest
|
||||
from helper import captureStdout
|
||||
from helper import capture_stdout
|
||||
|
||||
from beets import library
|
||||
from beets import ui
|
||||
|
|
@ -47,7 +47,7 @@ class ListTest(unittest.TestCase):
|
|||
commands.list_items(self.lib, query, album, fmt)
|
||||
|
||||
def test_list_outputs_item(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list()
|
||||
self.assertIn(u'the title', stdout.getvalue())
|
||||
|
||||
|
|
@ -56,56 +56,56 @@ class ListTest(unittest.TestCase):
|
|||
self.item.store()
|
||||
self.lib._connection().commit()
|
||||
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list([u'na\xefve'])
|
||||
out = stdout.getvalue()
|
||||
self.assertTrue(u'na\xefve' in out.decode(stdout.encoding))
|
||||
|
||||
def test_list_item_path(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(fmt='$path')
|
||||
self.assertEqual(stdout.getvalue().strip(), u'xxx/yyy')
|
||||
|
||||
def test_list_album_outputs_something(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(album=True)
|
||||
self.assertGreater(len(stdout.getvalue()), 0)
|
||||
|
||||
def test_list_album_path(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(album=True, fmt='$path')
|
||||
self.assertEqual(stdout.getvalue().strip(), u'xxx')
|
||||
|
||||
def test_list_album_omits_title(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(album=True)
|
||||
self.assertNotIn(u'the title', stdout.getvalue())
|
||||
|
||||
def test_list_uses_track_artist(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list()
|
||||
self.assertIn(u'the artist', stdout.getvalue())
|
||||
self.assertNotIn(u'the album artist', stdout.getvalue())
|
||||
|
||||
def test_list_album_uses_album_artist(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(album=True)
|
||||
self.assertNotIn(u'the artist', stdout.getvalue())
|
||||
self.assertIn(u'the album artist', stdout.getvalue())
|
||||
|
||||
def test_list_item_format_artist(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(fmt='$artist')
|
||||
self.assertIn(u'the artist', stdout.getvalue())
|
||||
|
||||
def test_list_item_format_multiple(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(fmt='$artist - $album - $year')
|
||||
self.assertEqual(u'the artist - the album - 0001',
|
||||
stdout.getvalue().strip())
|
||||
|
||||
def test_list_album_format(self):
|
||||
with captureStdout() as stdout:
|
||||
with capture_stdout() as stdout:
|
||||
self._run_list(album=True, fmt='$genre')
|
||||
self.assertIn(u'the genre', stdout.getvalue())
|
||||
self.assertNotIn(u'the album', stdout.getvalue())
|
||||
|
|
|
|||
Loading…
Reference in a new issue