Example #1
0
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)
Example #2
0
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)
Example #3
0
    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
Example #4
0
    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')
Example #5
0
 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)
Example #6
0
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%)'),
            ('"b@r"', 'b@r', 'b@r (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])
Example #7
0
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)
Example #8
0
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)
Example #9
0
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])
Example #10
0
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])
Example #11
0
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])
Example #12
0
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')
Example #13
0
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 float 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)
Example #14
0
    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')
Example #15
0
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)
Example #16
0
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)
Example #17
0
    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
Example #18
0
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])
Example #19
0
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()
Example #20
0
    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')
Example #21
0
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%)"), ('"b@r"', "b@r", "b@r (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()
Example #22
0
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()
Example #23
0
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)
Example #24
0
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])
Example #25
0
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)
Example #26
0
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])
Example #27
0
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)
Example #28
0
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)
Example #29
0
 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)
Example #30
0
    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')
Example #31
0
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%)'),
            ('"b@r"', 'b@r', 'b@r (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])
Example #32
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (), (ProgressBar,),
         (), ((Config, dict),)
     )
     self.uzbl = self.event_manager.add()
Example #33
0
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)
Example #34
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Cookies,))
     self.uzbl = self.event_manager.add()
     self.other = self.event_manager.add()
Example #35
0
class ProgressBarTest(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManagerMock((), (ProgressBar, ), (),
                                              ((Config, dict), ))
        self.uzbl = self.event_manager.add()

    def test_percent_done(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%c'

        p.update_progress()
        inout = (
            (9, '9%'),
            (99, '99%'),
            (100, '100%'),
            #(101, '100%') # TODO
        )

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)

    def test_done_char(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%d'

        p.update_progress()
        inout = ((9, '='), (50, '===='), (99, '========'), (100, '========'),
                 (101, '========'))

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)

    def test_pending_char(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%p'
        c['progress.pending'] = '-'

        p.update_progress()
        inout = ((9, '-------'), (50, '----'), (99, ''), (100, ''), (101, ''))

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)

    def test_percent_pending(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%t'

        p.update_progress()
        inout = (
            (9, '91%'),
            (50, '50%'),
            (99, '1%'),
            (100, '0%'),
            #(101, '0%')  # TODO
        )

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)
Example #36
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Config,))
     self.uzbl = self.event_manager.add()
Example #37
0
 def setUp(self):
     self.event_manager = EventManagerMock((SharedHistory,), ())
     self.uzbl = self.event_manager.add()
     self.other = self.event_manager.add()
Example #38
0
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))
        self.assertEqual('', next(h))  # this clears the keycmd
Example #39
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (KeyCmd, ), (),
                                           ((Config, dict), ))
     self.uzbl = self.event_manager.add()
Example #40
0
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)
Example #41
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Cookies, ),
                                           plugin_config=config)
     self.uzbl = self.event_manager.add()
     self.other = self.event_manager.add()
Example #42
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Downloads, Config))
     self.uzbl = self.event_manager.add()
Example #43
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Cookies,),
                                           plugin_config=config)
     self.uzbl = self.event_manager.add()
     self.other = self.event_manager.add()
Example #44
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Downloads, Config))
     self.uzbl = self.event_manager.add()
Example #45
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (),
         (OnEventPlugin, ),
     )
     self.uzbl = self.event_manager.add()
Example #46
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Config, BindPlugin))
     self.uzbl = self.event_manager.add()
Example #47
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (), (OnSetPlugin, ModePlugin),
         (), ((Config, dict),)
     )
     self.uzbl = self.event_manager.add()
Example #48
0
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)
Example #49
0
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))
        self.assertEqual('', next(h))  # this clears the keycmd
Example #50
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (Cookies, ))
     self.uzbl = self.event_manager.add()
     self.other = self.event_manager.add()
Example #51
0
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')
Example #52
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (ProgressBar, ), (),
                                           ((Config, dict), ))
     self.uzbl = self.event_manager.add()
Example #53
0
class ProgressBarTest(unittest.TestCase):
    def setUp(self):
        self.event_manager = EventManagerMock(
            (), (ProgressBar,),
            (), ((Config, dict),)
        )
        self.uzbl = self.event_manager.add()

    def test_percent_done(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%c'

        p.update_progress()
        inout = (
            (9,   '9%'),
            (99,  '99%'),
            (100, '100%'),
            #(101, '100%') # TODO
        )

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)

    def test_done_char(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%d'

        p.update_progress()
        inout = (
            (9,   '='),
            (50,  '===='),
            (99,  '========'),
            (100, '========'),
            (101, '========')
        )

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)

    def test_pending_char(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%p'
        c['progress.pending'] = '-'

        p.update_progress()
        inout = (
            (9,   '-------'),
            (50,  '----'),
            (99,  ''),
            (100, ''),
            (101, '')
        )

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)

    def test_percent_pending(self):
        uzbl = self.uzbl
        p, c = ProgressBar[uzbl], Config[uzbl]
        c['progress.format'] = '%t'

        p.update_progress()
        inout = (
            (9,   '91%'),
            (50,  '50%'),
            (99,  '1%'),
            (100, '0%'),
            #(101, '0%')  # TODO
        )

        for i, o in inout:
            p.update_progress(i)
            self.assertEqual(c['progress.output'], o)
Example #54
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (), (OnEventPlugin,),
     )
     self.uzbl = self.event_manager.add()
Example #55
0
 def setUp(self):
     self.event_manager = EventManagerMock((), (CompletionPlugin, ), (),
                                           ((Config, dict), (KeyCmd, None)))
     self.uzbl = self.event_manager.add()
Example #56
0
 def setUp(self):
     self.event_manager = EventManagerMock((SharedHistory, ), ())
     self.uzbl = self.event_manager.add()
     self.other = self.event_manager.add()
Example #57
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (), (CompletionPlugin,),
         (), ((Config, dict), (KeyCmd, None))
     )
     self.uzbl = self.event_manager.add()
Example #58
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (), (KeyCmd,),
         (), ((Config, dict),)
     )
     self.uzbl = self.event_manager.add()
Example #59
0
 def setUp(self):
     self.event_manager = EventManagerMock(
         (), (OnSetPlugin, ModePlugin),
         (), ((Config, dict),)
     )
     self.uzbl = self.event_manager.add()