本文整理汇总了Python中test.helper.control_stdin函数的典型用法代码示例。如果您正苦于以下问题:Python control_stdin函数的具体用法?Python control_stdin怎么用?Python control_stdin使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了control_stdin函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_plugin_callback
def test_plugin_callback(self):
"""Test that plugin callbacks are being called upon user choice."""
class DummyPlugin(plugins.BeetsPlugin):
def __init__(self):
super(DummyPlugin, self).__init__()
self.register_listener('before_choose_candidate',
self.return_choices)
def return_choices(self, session, task):
return [ui.commands.PromptChoice('f', u'Foo', self.foo)]
def foo(self, session, task):
pass
self.register_plugin(DummyPlugin)
# Default options + extra choices by the plugin ('Foo', 'Bar')
opts = (u'Apply', u'More candidates', u'Skip', u'Use as-is',
u'as Tracks', u'Group albums', u'Enter search',
u'enter Id', u'aBort') + (u'Foo',)
# DummyPlugin.foo() should be called once
with patch.object(DummyPlugin, 'foo', autospec=True) as mock_foo:
with helper.control_stdin('\n'.join(['f', 's'])):
self.importer.run()
self.assertEqual(mock_foo.call_count, 1)
# input_options should be called twice, as foo() returns None
self.assertEqual(self.mock_input_options.call_count, 2)
self.mock_input_options.assert_called_with(opts, default='a',
require=ANY)
开发者ID:Gondlar,项目名称:beets,代码行数:30,代码来源:test_plugins.py
示例2: test_transcode_from_lossy
def test_transcode_from_lossy(self):
self.config['convert']['never_convert_lossy_files'] = False
[item] = self.add_item_fixtures(ext='ogg')
with control_stdin('y'):
self.run_command('convert', item.path)
converted = os.path.join(self.convert_dest, 'converted.mp3')
self.assertFileTag(converted, 'mp3')
开发者ID:lucaspanjer,项目名称:beets,代码行数:7,代码来源:test_convert.py
示例3: test_plugin_callback_return
def test_plugin_callback_return(self):
"""Test that plugin callbacks that return a value exit the loop."""
class DummyPlugin(plugins.BeetsPlugin):
def __init__(self):
super(DummyPlugin, self).__init__()
self.register_listener('before_choose_candidate',
self.return_choices)
def return_choices(self, session, task):
return [ui.commands.PromptChoice('f', u'Foo', self.foo)]
def foo(self, session, task):
return action.SKIP
self.register_plugin(DummyPlugin)
# Default options + extra choices by the plugin ('Foo', 'Bar')
opts = (u'Apply', u'More candidates', u'Skip', u'Use as-is',
u'as Tracks', u'Group albums', u'Enter search',
u'enter Id', u'aBort') + (u'Foo',)
# DummyPlugin.foo() should be called once
with helper.control_stdin('f\n'):
self.importer.run()
# input_options should be called once, as foo() returns SKIP
self.mock_input_options.assert_called_once_with(opts, default='a',
require=ANY)
开发者ID:Gondlar,项目名称:beets,代码行数:27,代码来源:test_plugins.py
示例4: test_subcommand_update_database_false
def test_subcommand_update_database_false(self):
item = self.add_item_fixture(
year=2016,
day=13,
month=3,
comments=u'test comment'
)
item.write()
item_id = item.id
self.config['zero']['fields'] = ['comments']
self.config['zero']['update_database'] = False
self.config['zero']['auto'] = False
self.load_plugins('zero')
with control_stdin('y'):
self.run_command('zero')
mf = MediaFile(syspath(item.path))
item = self.lib.get_item(item_id)
self.assertEqual(item['year'], 2016)
self.assertEqual(mf.year, 2016)
self.assertEqual(item['comments'], u'test comment')
self.assertEqual(mf.comments, None)
开发者ID:JDLH,项目名称:beets,代码行数:25,代码来源:test_zero.py
示例5: run_mocked_command
def run_mocked_command(self, modify_file_args={}, stdin=[], args=[]):
"""Run the edit command, with mocked stdin and yaml writing, and
passing `args` to `run_command`."""
m = ModifyFileMocker(**modify_file_args)
with patch('beetsplug.edit.edit', side_effect=m.action):
with control_stdin('\n'.join(stdin)):
self.run_command('edit', *args)
开发者ID:lucaspanjer,项目名称:beets,代码行数:7,代码来源:test_edit.py
示例6: test_convert_keep_new
def test_convert_keep_new(self):
self.assertEqual(os.path.splitext(self.item.path)[1], ".ogg")
with control_stdin("y"):
self.run_command("convert", "--keep-new", self.item.path)
self.item.load()
self.assertEqual(os.path.splitext(self.item.path)[1], ".mp3")
开发者ID:JesseWeinstein,项目名称:beets,代码行数:8,代码来源:test_convert.py
示例7: test_warning_threshold
def test_warning_threshold(self):
self.config['play']['warning_threshold'] = 1
self.add_item(title='another NiceTitle')
with control_stdin("a"):
self.run_command(u'play', u'nice')
self.open_mock.assert_not_called()
开发者ID:RyanScottLewis,项目名称:beets,代码行数:8,代码来源:test_play.py
示例8: run_mocked_interpreter
def run_mocked_interpreter(self, modify_file_args={}, stdin=[]):
"""Run the edit command during an import session, with mocked stdin and
yaml writing.
"""
m = ModifyFileMocker(**modify_file_args)
with patch('beetsplug.edit.edit', side_effect=m.action):
with control_stdin('\n'.join(stdin)):
self.importer.run()
开发者ID:JDLH,项目名称:beets,代码行数:8,代码来源:test_edit.py
示例9: test_warning_threshold_backwards_compat
def test_warning_threshold_backwards_compat(self, open_mock):
self.config["play"]["warning_treshold"] = 1
self.add_item(title=u"another NiceTitle")
with control_stdin("a"):
self.run_command(u"play", u"nice")
open_mock.assert_not_called()
开发者ID:beetbox,项目名称:beets,代码行数:8,代码来源:test_play.py
示例10: test_print_tracks_output_as_tracks
def test_print_tracks_output_as_tracks(self):
"""Test the output of the "print tracks" choice, as singletons."""
self.matcher.matching = AutotagStub.BAD
with capture_stdout() as output:
with control_stdin("\n".join(["t", "s", "p", "s"])):
# as Tracks; Skip; Print tracks; Skip
self.importer.run()
# Manually build the string for comparing the output.
tracklist = u"Print tracks? " u"02. Tag Title 2 - Tag Artist (0:01)"
self.assertIn(tracklist, output.getvalue())
开发者ID:angelsanz,项目名称:beets,代码行数:12,代码来源:test_mbsubmit.py
示例11: test_embed_album_art
def test_embed_album_art(self):
self.config["convert"]["embed"] = True
image_path = os.path.join(_common.RSRC, "image-2x3.jpg")
self.album.artpath = image_path
self.album.store()
with open(os.path.join(image_path)) as f:
image_data = f.read()
with control_stdin("y"):
self.run_command("convert", self.item.path)
converted = os.path.join(self.convert_dest, "converted.mp3")
mediafile = MediaFile(converted)
self.assertEqual(mediafile.images[0].data, image_data)
开发者ID:JesseWeinstein,项目名称:beets,代码行数:13,代码来源:test_convert.py
示例12: test_skip_warning_threshold_bypass
def test_skip_warning_threshold_bypass(self, open_mock):
self.config['play']['warning_threshold'] = 1
self.other_item = self.add_item(title='another NiceTitle')
expected_playlist = u'{0}\n{1}'.format(
self.item.path.decode('utf-8'),
self.other_item.path.decode('utf-8'))
with control_stdin("a"):
self.run_and_assert(
open_mock,
[u'-y', u'NiceTitle'],
expected_playlist=expected_playlist)
开发者ID:Kraymer,项目名称:beets,代码行数:13,代码来源:test_play.py
示例13: test_print_tracks_output
def test_print_tracks_output(self):
"""Test the output of the "print tracks" choice."""
self.matcher.matching = AutotagStub.BAD
with capture_stdout() as output:
with control_stdin('\n'.join(['p', 's'])):
# Print tracks; Skip
self.importer.run()
# Manually build the string for comparing the output.
tracklist = ('Print tracks? '
'01. Tag Title 1 - Tag Artist (0:01)\n'
'02. Tag Title 2 - Tag Artist (0:01)')
self.assertIn(tracklist, output.getvalue())
开发者ID:ali-graham,项目名称:beets,代码行数:14,代码来源:test_mbsubmit.py
示例14: test_no_fields
def test_no_fields(self):
item = self.add_item_fixture(year=2016)
item.write()
mediafile = MediaFile(syspath(item.path))
self.assertEqual(mediafile.year, 2016)
item_id = item.id
self.load_plugins('zero')
with control_stdin('y'):
self.run_command('zero')
item = self.lib.get_item(item_id)
self.assertEqual(item['year'], 2016)
self.assertEqual(mediafile.year, 2016)
开发者ID:JDLH,项目名称:beets,代码行数:16,代码来源:test_zero.py
示例15: test_whitelist_and_blacklist
def test_whitelist_and_blacklist(self):
item = self.add_item_fixture(year=2016)
item.write()
mf = MediaFile(syspath(item.path))
self.assertEqual(mf.year, 2016)
item_id = item.id
self.config['zero']['fields'] = [u'year']
self.config['zero']['keep_fields'] = [u'comments']
self.load_plugins('zero')
with control_stdin('y'):
self.run_command('zero')
item = self.lib.get_item(item_id)
self.assertEqual(item['year'], 2016)
self.assertEqual(mf.year, 2016)
开发者ID:JDLH,项目名称:beets,代码行数:18,代码来源:test_zero.py
示例16: test_transcode_from_lossy_prevented
def test_transcode_from_lossy_prevented(self):
[item] = self.add_item_fixtures(ext='ogg')
with control_stdin('y'):
self.run_command('convert', item.path)
converted = os.path.join(self.convert_dest, 'converted.ogg')
self.assertNoFileTag(converted, 'mp3')
开发者ID:lucaspanjer,项目名称:beets,代码行数:6,代码来源:test_convert.py
示例17: test_format_option
def test_format_option(self):
with control_stdin('y'):
self.run_command('convert', '--format', 'opus', self.item.path)
converted = os.path.join(self.convert_dest, 'converted.ops')
self.assertFileTag(converted, 'opus')
开发者ID:lucaspanjer,项目名称:beets,代码行数:5,代码来源:test_convert.py
示例18: test_rejecet_confirmation
def test_rejecet_confirmation(self):
with control_stdin('n'):
self.run_command('convert', self.item.path)
converted = os.path.join(self.convert_dest, 'converted.mp3')
self.assertFalse(os.path.isfile(converted))
开发者ID:lucaspanjer,项目名称:beets,代码行数:5,代码来源:test_convert.py
示例19: test_convert
def test_convert(self):
with control_stdin('y'):
self.run_command('convert', self.item.path)
converted = os.path.join(self.convert_dest, 'converted.mp3')
self.assertFileTag(converted, 'mp3')
开发者ID:lucaspanjer,项目名称:beets,代码行数:5,代码来源:test_convert.py
示例20: modify_inp
def modify_inp(self, inp, *args):
with control_stdin(inp):
self.run_command('modify', *args)
开发者ID:shamangeorge,项目名称:beets,代码行数:3,代码来源:test_ui.py
注:本文中的test.helper.control_stdin函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论