本文整理匯總了Python中emtest.EventManagerMock.add方法的典型用法代碼示例。如果您正苦於以下問題:Python EventManagerMock.add方法的具體用法?Python EventManagerMock.add怎麽用?Python EventManagerMock.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類emtest.EventManagerMock
的用法示例。
在下文中一共展示了EventManagerMock.add方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: SharedHistoryTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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: KeyCmdTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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)
示例3: BindPluginTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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])
示例4: CookieFilterTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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: DownloadsTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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()
示例7: PrivateCookieTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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()
示例8: OnEventTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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])
示例9: ModeParseTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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)
示例10: TestAdd
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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)
示例11: DownloadsTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
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])
示例12: ConfigTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
class ConfigTest(unittest.TestCase):
def setUp(self):
self.event_manager = EventManagerMock((), (Config,))
self.uzbl = self.event_manager.add()
def test_set(self):
cases = (
(True, '1'),
(False, '0'),
("test", "test"),
(5, '5')
)
c = Config[self.uzbl]
for input, expected in cases:
c.set('foo', input)
self.uzbl.send.assert_called_once_with(
'set foo ' + expected)
self.uzbl.send.reset_mock()
def test_set_invalid(self):
cases = (
("foo\nbar", AssertionError), # Better Exception type
("bad'key", AssertionError)
)
c = Config[self.uzbl]
for input, exception in cases:
self.assertRaises(exception, c.set, input)
def test_parse(self):
cases = (
('foo str value', 'foo', 'value'),
('foo str "ba ba"', 'foo', 'ba ba'),
('foo double 5', 'foo', 5.0)
)
c = Config[self.uzbl]
for input, ekey, evalue in cases:
c.parse_set_event(input)
self.assertIn(ekey, c)
self.assertEqual(c[ekey], evalue)
self.uzbl.event.assert_called_once_with(
'CONFIG_CHANGED', ekey, evalue)
self.uzbl.event.reset_mock()
def test_parse_null(self):
cases = (
('foo str', 'foo'),
('foo str ""', 'foo'),
#('foo int', 'foo') # Not sure if this input is valid
)
c = Config[self.uzbl]
for input, ekey in cases:
c.update({'foo': '-'})
c.parse_set_event(input)
self.assertNotIn(ekey, c)
self.uzbl.event.assert_called_once_with(
'CONFIG_CHANGED', ekey, '')
self.uzbl.event.reset_mock()
def test_parse_invalid(self):
cases = (
('foo bar', AssertionError), # TypeError?
('foo bad^key', AssertionError),
('', Exception),
('foo int z', ValueError)
)
c = Config[self.uzbl]
for input, exception in cases:
self.assertRaises(exception, c.parse_set_event, input)
self.assertEqual(len(list(c.keys())), 0)
示例13: TestCompletion
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
class TestCompletion(unittest.TestCase):
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')
def test_incomplete_keyword(self):
k, c = KeyCmd[self.uzbl], CompletionPlugin[self.uzbl]
k.keylet.keycmd = 'sp'
k.keylet.cursor = len(k.keylet.keycmd)
r = c.get_incomplete_keyword()
self.assertEqual(r, 'sp')
def test_incomplete_keyword_var(self):
k, c = KeyCmd[self.uzbl], CompletionPlugin[self.uzbl]
k.keylet.keycmd = 'set @sp'
k.keylet.cursor = len(k.keylet.keycmd)
r = c.get_incomplete_keyword()
self.assertEqual(r, '@sp')
def test_incomplete_keyword_var_noat(self):
k, c = KeyCmd[self.uzbl], CompletionPlugin[self.uzbl]
k.keylet.keycmd = 'set Some'
k.keylet.cursor = len(k.keylet.keycmd)
r = c.get_incomplete_keyword()
self.assertEqual(r, '@Some')
def test_stop_completion(self):
config, c = Config[self.uzbl], CompletionPlugin[self.uzbl]
c.completion.level = 99
config['completion_list'] = 'test'
c.stop_completion()
self.assertNotIn('completion_list', config)
self.assertEqual(c.completion.level, 0)
def test_completion(self):
k, c = KeyCmd[self.uzbl], CompletionPlugin[self.uzbl]
config = Config[self.uzbl]
comp = (
('sp', 'spam '),
('e', 'egg '),
('set @sp', 'set @spam '),
)
for i, o in comp:
k.keylet.keycmd = i
k.keylet.cursor = len(k.keylet.keycmd)
c.start_completion()
self.assertEqual(k.keylet.keycmd, o)
c.start_completion()
self.assertNotIn('completion_list', config)
def test_completion_list(self):
k, c = KeyCmd[self.uzbl], CompletionPlugin[self.uzbl]
config = Config[self.uzbl]
comp = (
('b', 'ba', '[ba] bar, baz'),
)
for i, o, l in comp:
k.keylet.keycmd = i
k.keylet.cursor = len(k.keylet.keycmd)
c.start_completion()
self.assertEqual(k.keylet.keycmd, o)
c.start_completion()
self.assertEqual(config['completion_list'], l)
示例14: HistoryTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
class HistoryTest(unittest.TestCase):
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)
def test_step(self):
h = History[self.uzbl]
self.assertEqual('', next(h))
self.assertEqual('', next(h))
self.assertEqual('foo', h.prev())
self.assertEqual('bar', h.prev())
self.assertEqual('foo', next(h))
self.assertEqual('bar', h.prev())
self.assertEqual('doop', h.prev())
self.assertEqual('woop', h.prev())
self.assertTrue(len(h.prev()) > 0)
self.assertTrue(len(h.prev()) > 0)
self.assertEqual('woop', next(h))
def test_step_prompt(self):
h = History[self.uzbl]
h.change_prompt('git')
self.assertEqual('', next(h))
self.assertEqual('', next(h))
self.assertEqual('egg', h.prev())
self.assertEqual('spam', h.prev())
self.assertTrue(len(h.prev()) > 0)
self.assertTrue(len(h.prev()) > 0)
self.assertEqual('spam', next(h))
def test_change_prompt(self):
h = History[self.uzbl]
self.assertEqual('foo', h.prev())
self.assertEqual('bar', h.prev())
h.change_prompt('git')
self.assertEqual('egg', h.prev())
self.assertEqual('spam', h.prev())
def test_exec(self):
modstate = set()
keylet = Keylet()
keylet.set_keycmd('foo')
History[self.uzbl].keycmd_exec(modstate, keylet)
s = SharedHistory[self.uzbl]
self.assertEqual(s.getline('', -1), 'foo')
def test_exec_from_history(self):
h = History[self.uzbl]
self.assertEqual('foo', h.prev())
self.assertEqual('bar', h.prev())
self.assertEqual('doop', h.prev())
modstate = set()
keylet = Keylet()
keylet.set_keycmd('doop')
h.keycmd_exec(modstate, keylet)
self.assertEqual('doop', h.prev())
self.assertEqual('foo', h.prev())
self.assertEqual('bar', h.prev())
# do we really want this one here ?
self.assertEqual('doop', h.prev())
self.assertEqual('woop', h.prev())
def test_search(self):
h = History[self.uzbl]
h.search('oop')
self.assertEqual('doop', h.prev())
self.assertEqual('woop', h.prev())
self.assertTrue(len(h.prev()) > 0)
self.assertEqual('woop', next(h))
self.assertEqual('doop', next(h))
# this reset the search
self.assertEqual('', next(h))
self.assertEqual('foo', h.prev())
def test_temp(self):
kl = KeyCmd[self.uzbl].keylet
kl.set_keycmd('uzbl')
h = History[self.uzbl]
h.change_prompt('foo')
# Why is the preserve current logic in this method?
h.history_prev(None)
self.assertTrue(len(h.prev()) > 0)
self.assertEqual('foo', next(h))
self.assertEqual('uzbl', next(h))
#.........這裏部分代碼省略.........
示例15: ModeTest
# 需要導入模塊: from emtest import EventManagerMock [as 別名]
# 或者: from emtest.EventManagerMock import add [as 別名]
class ModeTest(unittest.TestCase):
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')
def test_mode_sets_vars(self):
mode, config = ModePlugin[self.uzbl], Config[self.uzbl]
mode.mode_updated(None, 'mode1')
self.assertIn('foo', config)
self.assertIn('bar', config)
self.assertIn('baz', config)
self.assertEqual(config['foo'], 'xxx')
self.assertEqual(config['bar'], 'spam spam')
self.assertEqual(config['baz'], 'foo="baz"')
def test_mode_overwrite_vars(self):
mode, config = ModePlugin[self.uzbl], Config[self.uzbl]
config['mode'] = 'mode1'
mode.mode_updated(None, 'mode1')
config['mode'] = 'mode2'
mode.mode_updated(None, 'mode2')
self.assertIn('foo', config)
self.assertIn('bar', config)
self.assertIn('baz', config)
self.assertIn('spam', config)
self.assertEqual(config['foo'], 'XXX')
self.assertEqual(config['bar'], 'spam spam')
self.assertEqual(config['baz'], 'foo="baz"')
self.assertEqual(config['spam'], 'spam')
def test_default_mode(self):
''' Setting to mode to nothing should enter the default mode'''
mode, config = ModePlugin[self.uzbl], Config[self.uzbl]
config['foo'] = 'nthth'
config['mode'] = ''
mode.mode_updated(None, '')
self.assertEqual(config['mode'], 'mode0')
mode.mode_updated(None, config['mode'])
self.assertEqual(config['mode'], 'mode0')
self.assertEqual(config['foo'], 'default')