本文整理汇总了Python中emtest.EventManagerMock类的典型用法代码示例。如果您正苦于以下问题:Python EventManagerMock类的具体用法?Python EventManagerMock怎么用?Python EventManagerMock使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EventManagerMock类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SharedHistoryTest
class SharedHistoryTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock((SharedHistory,), ())
self.uzbl = self.event_manager.add()
self.other = self.event_manager.add()
def test_instance(self):
a = SharedHistory[self.uzbl]
b = SharedHistory[self.other]
self.assertIs(a, b)
def test_add_and_get(self):
s = SharedHistory[self.uzbl]
s.addline('foo', 'bar')
s.addline('foo', 'baz')
s.addline('foo', 'bap')
self.assertEqual(s.get_line_number('foo'), 3)
self.assertEqual(s.get_line_number('other'), 0)
self.assertEqual(s.getline('foo', 0), 'bar')
self.assertEqual(s.getline('foo', 1), 'baz')
self.assertEqual(s.getline('foo', 2), 'bap')
self.assertEqual(s.getline('foo', -1), 'bap')
def test_empty_line_number(self):
s = SharedHistory[self.uzbl]
s.addline('foo', 'bar')
self.assertEqual(s.get_line_number(''), 0)
self.assertEqual(s.get_line_number('other'), 0)
def test_get_missing_prompt(self):
s = SharedHistory[self.uzbl]
s.addline('foo', 'bar')
self.assertRaises(IndexError, s.getline, 'bar', 0)
示例2: BindPluginTest
class BindPluginTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock((), (Config, BindPlugin))
self.uzbl = self.event_manager.add()
def test_add_bind(self):
b = BindPlugin[self.uzbl]
modes = 'global'
glob = 'test'
handler = justafunction
b.mode_bind(modes, glob, handler)
binds = b.bindlet.get_binds()
self.assertEqual(len(binds), 1)
self.assertIs(binds[0].function, justafunction)
def test_parse_bind(self):
b = BindPlugin[self.uzbl]
modes = 'global'
glob = 'test'
handler = 'handler'
b.parse_mode_bind('%s %s = %s' % (modes, glob, handler))
binds = b.bindlet.get_binds()
self.assertEqual(len(binds), 1)
self.assertEqual(binds[0].commands, [handler])
示例3: KeyCmdTest
class KeyCmdTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock(
(), (KeyCmd,),
(), ((Config, dict),)
)
self.uzbl = self.event_manager.add()
def test_press_key(self):
c, k = Config[self.uzbl], KeyCmd[self.uzbl]
k.key_press(('', 'a'))
self.assertEqual(c.get('modcmd', ''), '')
keycmd = getkeycmd(c['keycmd'])
self.assertEqual(keycmd, 'a')
def test_press_keys(self):
c, k = Config[self.uzbl], KeyCmd[self.uzbl]
string = 'uzbl'
for char in string:
k.key_press(('', char))
self.assertEqual(c.get('modcmd', ''), '')
keycmd = getkeycmd(c['keycmd'])
self.assertEqual(keycmd, string)
def test_press_unicode_keys(self):
c, k = Config[self.uzbl], KeyCmd[self.uzbl]
string = u'\u5927\u962a\u5e02'
for char in string:
k.key_press(('', char))
self.assertEqual(c.get('modcmd', ''), '')
keycmd = getkeycmd(c['keycmd'])
self.assertEqual(keycmd, string)
示例4: CookieFilterTest
class CookieFilterTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock((), (Cookies,),
plugin_config=config)
self.uzbl = self.event_manager.add()
self.other = self.event_manager.add()
def test_add_cookie(self):
c = Cookies[self.uzbl]
c.add_cookie(cookies[0])
self.other.send.assert_called_once_with(
'cookie add ' + cookies[0])
def test_whitelist_block(self):
c = Cookies[self.uzbl]
c.whitelist_cookie(r'domain "nyan\.cat$"')
c.add_cookie(cookies[1])
self.uzbl.send.assert_called_once_with(
'cookie delete ' + cookies[1])
def test_whitelist_accept(self):
c = Cookies[self.uzbl]
c.whitelist_cookie(r'domain "nyan\.cat$"')
c.add_cookie(cookies[0])
self.other.send.assert_called_once_with(
'cookie add ' + cookies[0])
def test_blacklist_block(self):
c = Cookies[self.uzbl]
c.blacklist_cookie(r'domain "twitter\.com$"')
c.add_cookie(cookies[1])
self.uzbl.send.assert_called_once_with(
'cookie delete ' + cookies[1])
def test_blacklist_accept(self):
c = Cookies[self.uzbl]
c.blacklist_cookie(r'domain "twitter\.com$"')
c.add_cookie(cookies[0])
self.other.send.assert_called_once_with(
'cookie add ' + cookies[0])
def test_filter_numeric(self):
c = Cookies[self.uzbl]
c.blacklist_cookie(r'0 "twitter\.com$"')
c.add_cookie(cookies[1])
self.uzbl.send.assert_called_once_with(
'cookie delete ' + cookies[1])
示例5: OnEventTest
class OnEventTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock(
(), (OnEventPlugin,),
)
self.uzbl = self.event_manager.add()
def test_command(self):
oe = OnEventPlugin[self.uzbl]
event, command = 'FOO', 'test test'
oe.parse_on_event('FOO test test')
oe.event_handler('', on_event=event)
self.uzbl.send.assert_called_once_with(command)
def test_command_with_quotes(self):
oe = OnEventPlugin[self.uzbl]
event, command = 'FOO', 'test "string with spaces"'
oe.parse_on_event('FOO test "string with spaces"')
oe.event_handler('', on_event=event)
self.uzbl.send.assert_called_once_with(command)
def test_matching_pattern(self):
oe = OnEventPlugin[self.uzbl]
event, command = 'FOO', "test test"
oe.parse_on_event('FOO [ BAR ] test test')
oe.event_handler('BAR else', on_event=event)
self.uzbl.send.assert_called_once_with(command)
def test_non_matching_pattern(self):
oe = OnEventPlugin[self.uzbl]
event, pattern, command = 'FOO', ['BAR'], 'test test'
oe.on_event(event, pattern, command)
oe.event_handler('FOO else', on_event=event)
self.assertFalse(self.uzbl.send.called)
def test_parse(self):
oe = OnEventPlugin[self.uzbl]
event, command = 'FOO', "test 'test'"
oe.parse_on_event((event, command))
self.assertIn(event, oe.events)
def test_parse_pattern(self):
oe = OnEventPlugin[self.uzbl]
event, pattern = 'FOO', 'BAR'
oe.parse_on_event('FOO [ BAR ] test test')
self.assertIn(event, oe.events)
commands = oe.events[event]
self.assertIn((('test', 'test'), [pattern]), commands)
示例6: setUp
def setUp(self):
self.event_manager = EventManagerMock(
(), (Cookies,),
(), ((Config, dict),),
config
)
self.priv = self.event_manager.add()
self.uzbl_a = self.event_manager.add()
self.uzbl_b = self.event_manager.add()
Config[self.priv]['enable_private'] = 1
示例7: setUp
def setUp(self):
self.event_manager = EventManagerMock(
(), (KeyCmd, CompletionPlugin),
(), ((Config, dict),)
)
self.uzbl = self.event_manager.add()
c = CompletionPlugin[self.uzbl]
c.listformatter = DummyFormatter()
c.add_builtins('["spam", "egg", "bar", "baz"]')
c.add_config_key('spam', 'SPAM')
c.add_config_key('Something', 'Else')
示例8: DownloadsTest
class DownloadsTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock((), (Downloads, Config))
self.uzbl = self.event_manager.add()
def test_start(self):
cases = (("foo", "foo", "foo (0%)"), ('"[email protected]"', "[email protected]", "[email protected] (0%"))
d = Downloads[self.uzbl]
for input, key, section in cases:
d.download_started(input)
self.assertIn(key, d.active_downloads)
self.assertEqual(d.active_downloads[key], 0)
self.uzbl.send.assert_called_once()
self.assertIn(section, self.uzbl.send.call_args[0][0])
self.uzbl.reset_mock()
示例9: PrivateCookieTest
class PrivateCookieTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock(
(), (Cookies,),
(), ((Config, dict),),
config
)
self.priv = self.event_manager.add()
self.uzbl_a = self.event_manager.add()
self.uzbl_b = self.event_manager.add()
Config[self.priv]['enable_private'] = 1
def test_does_not_send_from_private_uzbl(self):
c = Cookies[self.priv]
c.add_cookie(cookies[0])
self.uzbl_a.send.assert_not_called()
self.uzbl_b.send.assert_not_called()
def test_does_not_send_to_private_uzbl(self):
c = Cookies[self.uzbl_a]
c.add_cookie(cookies[0])
self.priv.send.assert_not_called()
示例10: OnEventTest
class OnEventTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock(
(), (OnEventPlugin,),
)
self.uzbl = self.event_manager.add()
def test_command(self):
oe = OnEventPlugin[self.uzbl]
event, command = 'FOO', 'test test'
oe.on_event(event, [], command)
oe.event_handler('', on_event=event)
self.uzbl.send.assert_called_once_with(command)
def test_matching_pattern(self):
oe = OnEventPlugin[self.uzbl]
event, pattern, command = 'FOO', ['BAR'], 'test test'
oe.on_event(event, pattern, command)
oe.event_handler('BAR else', on_event=event)
self.uzbl.send.assert_called_once_with(command)
def test_non_matching_pattern(self):
oe = OnEventPlugin[self.uzbl]
event, pattern, command = 'FOO', ['BAR'], 'test test'
oe.on_event(event, pattern, command)
oe.event_handler('FOO else', on_event=event)
self.assertFalse(self.uzbl.send.called)
def test_parse(self):
oe = OnEventPlugin[self.uzbl]
event, command = 'FOO', 'test test'
oe.parse_on_event((event, command))
self.assertIn(event, oe.events)
def test_parse_pattern(self):
oe = OnEventPlugin[self.uzbl]
event, pattern, command = 'FOO', 'BAR', 'test test'
oe.parse_on_event((event, '[', pattern, ']', command))
self.assertIn(event, oe.events)
commands = oe.events[event]
self.assertIn(command, commands)
self.assertEqual(commands[command], [pattern])
示例11: ModeParseTest
class ModeParseTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock(
(), (OnSetPlugin, ModePlugin),
(), ((Config, dict),)
)
self.uzbl = self.event_manager.add()
def test_parse_config(self):
uzbl = self.uzbl
m = ModePlugin[uzbl]
mode, key, value = 'foo', 'x', 'y'
m.parse_mode_config((mode, key, '=', value))
self.assertIn(mode, m.mode_config)
self.assertIn(key, m.mode_config[mode])
self.assertEqual(m.mode_config[mode][key], value)
示例12: TestAdd
class TestAdd(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock(
(), (CompletionPlugin,),
(), ((Config, dict), (KeyCmd, None))
)
self.uzbl = self.event_manager.add()
def test_builtins(self):
c = CompletionPlugin[self.uzbl]
c.add_builtins('["spam", "egg"]')
self.assertIn('spam', c.completion)
self.assertIn('egg', c.completion)
def test_config(self):
c = CompletionPlugin[self.uzbl]
c.add_config_key('spam', 'SPAM')
self.assertIn('@spam', c.completion)
示例13: setUp
def setUp(self):
self.event_manager = EventManagerMock(
(SharedHistory,),
(OnSetPlugin, KeyCmd, Config, History)
)
self.uzbl = self.event_manager.add()
self.other = self.event_manager.add()
s = SharedHistory[self.uzbl]
data = (
('', 'woop'),
('', 'doop'),
('', 'bar'),
('', 'foo'),
('git', 'spam'),
('git', 'egg'),
('foo', 'foo')
)
for prompt, input in data:
s.addline(prompt, input)
示例14: setUp
def setUp(self):
self.event_manager = EventManagerMock(
(), (OnSetPlugin, ModePlugin),
(), ((Config, dict),)
)
self.uzbl = self.event_manager.add()
mode = ModePlugin[self.uzbl]
config = Config[self.uzbl]
mode.parse_mode_config(('mode0', 'foo', '=', 'default'))
mode.parse_mode_config(('mode1', 'foo', '=', 'xxx'))
mode.parse_mode_config('mode1 bar = "spam spam"')
mode.parse_mode_config('mode1 baz = foo="baz"')
mode.parse_mode_config(('mode2', 'foo', '=', 'XXX'))
mode.parse_mode_config(('mode2', 'spam', '=', 'spam'))
config['default_mode'] = 'mode0'
mode.default_mode_updated(None, 'mode0')
示例15: DownloadsTest
class DownloadsTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock((), (Downloads, Config))
self.uzbl = self.event_manager.add()
def test_start(self):
cases = (
('foo', 'foo', 'foo (0%)'),
('"[email protected]"', '[email protected]', '[email protected] (0%'),
)
d = Downloads[self.uzbl]
for input, key, section in cases:
d.download_started(input)
self.assertIn(key, d.active_downloads)
self.assertEqual(d.active_downloads[key], 0)
self.assertIn(section, self.uzbl.send.call_args[0][0])
self.uzbl.reset_mock()
def test_clear_downloads(self):
d = Downloads[self.uzbl]
d.download_started('foo')
d.download_complete('foo')
self.assertEqual(2, len(self.uzbl.send.call_args_list))
self.assertEqual("set downloads ", self.uzbl.send.call_args_list[1][0][0])