Esempio n. 1
0
    def test_commented(self):
        opt = configdata.Option(name='opt',
                                typ=configtypes.Int(),
                                default='def',
                                backends=[usertypes.Backend.QtWebEngine],
                                raw_backends=None,
                                description='Hello World')
        options = [(None, opt, 'val')]
        bindings = {
            'normal': {
                ',x': 'message-info normal'
            },
            'caret': {
                ',y': 'message-info caret'
            }
        }

        writer = configfiles.ConfigPyWriter(options, bindings, commented=True)
        lines = list(writer._gen_lines())

        assert "## Autogenerated config.py" in lines
        assert "# config.load_autoconfig()" in lines
        assert "# c.opt = 'val'" in lines
        assert "## Bindings for normal mode" in lines
        assert "# config.bind(',x', 'message-info normal')" in lines
        caret_bind = ("# config.bind(',y', 'message-info caret', "
                      "mode='caret')")
        assert caret_bind in lines
Esempio n. 2
0
def opt():
    return configdata.Option(name='example.option',
                             typ=configtypes.String(),
                             default='default value',
                             backends=None,
                             raw_backends=None,
                             description=None,
                             supports_pattern=True)
Esempio n. 3
0
    def test_valid_values(self):
        opt1 = configdata.Option(name='opt1',
                                 typ=configtypes.BoolAsk(),
                                 default='ask',
                                 backends=[usertypes.Backend.QtWebEngine],
                                 raw_backends=None,
                                 description='Hello World')
        opt2 = configdata.Option(name='opt2',
                                 typ=configtypes.ColorSystem(),
                                 default='rgb',
                                 backends=[usertypes.Backend.QtWebEngine],
                                 raw_backends=None,
                                 description='All colors are beautiful!')

        options = [(None, opt1, 'ask'), (None, opt2, 'rgb')]

        writer = configfiles.ConfigPyWriter(options,
                                            bindings={},
                                            commented=False)
        text = '\n'.join(writer._gen_lines())

        expected = textwrap.dedent("""
            # Hello World
            # Type: BoolAsk
            # Valid values:
            #   - true
            #   - false
            #   - ask
            c.opt1 = 'ask'

            # All colors are beautiful!
            # Type: ColorSystem
            # Valid values:
            #   - rgb: Interpolate in the RGB color system.
            #   - hsv: Interpolate in the HSV color system.
            #   - hsl: Interpolate in the HSL color system.
            #   - none: Don't show a gradient.
            c.opt2 = 'rgb'
        """)
        assert expected in text
Esempio n. 4
0
 def test_pattern(self):
     opt = configdata.Option(name='opt',
                             typ=configtypes.BoolAsk(),
                             default='ask',
                             backends=[usertypes.Backend.QtWebEngine],
                             raw_backends=None,
                             description='Hello World')
     options = [
         (urlmatch.UrlPattern('https://www.example.com/'), opt, 'ask'),
     ]
     writer = configfiles.ConfigPyWriter(options=options,
                                         bindings={},
                                         commented=False)
     text = '\n'.join(writer._gen_lines())
     expected = "config.set('opt', 'ask', 'https://www.example.com/')"
     assert expected in text
Esempio n. 5
0
    def test_output(self):
        desc = ("This is an option description.\n\n"
                "Nullam eu ante vel est convallis dignissim. Fusce suscipit, "
                "wisi nec facilisis facilisis, est dui fermentum leo, quis "
                "tempor ligula erat quis odio.")
        opt = configdata.Option(name='opt',
                                typ=configtypes.Int(),
                                default='def',
                                backends=[usertypes.Backend.QtWebEngine],
                                raw_backends=None,
                                description=desc)
        options = [(None, opt, 'val')]
        bindings = {
            'normal': {
                ',x': 'message-info normal'
            },
            'caret': {
                ',y': 'message-info caret'
            }
        }

        writer = configfiles.ConfigPyWriter(options, bindings, commented=False)
        text = '\n'.join(writer._gen_lines())

        assert text == textwrap.dedent("""
            # Autogenerated config.py
            # Documentation:
            #   glimpse://help/configuring.html
            #   glimpse://help/settings.html

            # Uncomment this to still load settings configured via autoconfig.yml
            # config.load_autoconfig()

            # This is an option description.  Nullam eu ante vel est convallis
            # dignissim. Fusce suscipit, wisi nec facilisis facilisis, est dui
            # fermentum leo, quis tempor ligula erat quis odio.
            # Type: Int
            c.opt = 'val'

            # Bindings for normal mode
            config.bind(',x', 'message-info normal')

            # Bindings for caret mode
            config.bind(',y', 'message-info caret', mode='caret')
        """).lstrip()
Esempio n. 6
0
def configdata_stub(config_stub, monkeypatch, configdata_init):
    """Patch the configdata module to provide fake data."""
    monkeypatch.setattr(configdata, 'DATA', collections.OrderedDict([
        ('aliases', configdata.Option(
            name='aliases',
            description='Aliases for commands.',
            typ=configtypes.Dict(
                keytype=configtypes.String(),
                valtype=configtypes.Command(),
            ),
            default={'q': 'quit'},
            backends=[usertypes.Backend.QtWebKit,
                      usertypes.Backend.QtWebEngine],
            raw_backends=None)),
        ('bindings.default', configdata.Option(
            name='bindings.default',
            description='Default keybindings',
            typ=configtypes.Dict(
                keytype=configtypes.String(),
                valtype=configtypes.Dict(
                    keytype=configtypes.Key(),
                    valtype=configtypes.Command(),
                ),
            ),
            default={
                'normal': collections.OrderedDict([
                    ('<Ctrl+q>', 'quit'),
                    ('d', 'tab-close'),
                ])
            },
            backends=[],
            raw_backends=None,
            no_autoconfig=True)),
        ('bindings.commands', configdata.Option(
            name='bindings.commands',
            description='Default keybindings',
            typ=configtypes.Dict(
                keytype=configtypes.String(),
                valtype=configtypes.Dict(
                    keytype=configtypes.Key(),
                    valtype=configtypes.Command(),
                ),
            ),
            default={
                'normal': collections.OrderedDict([
                    ('<Ctrl+q>', 'quit'),
                    ('ZQ', 'quit'),
                    ('I', 'invalid'),
                    ('d', 'scroll down'),
                ])
            },
            backends=[],
            raw_backends=None)),
        ('content.javascript.enabled', configdata.Option(
            name='content.javascript.enabled',
            description='Enable/Disable JavaScript',
            typ=configtypes.Bool(),
            default=True,
            backends=[],
            raw_backends=None)),
        ('completion.open_categories', configdata.Option(
            name='completion.open_categories',
            description=('Which categories to show (in which order) in the '
                         ':open completion.'),
            typ=configtypes.FlagList(),
            default=["searchengines", "quickmarks", "bookmarks", "history"],
            backends=[],
            raw_backends=None)),
        ('url.searchengines', configdata.Option(
            name='url.searchengines',
            description='searchengines list',
            typ=configtypes.Dict(
                keytype=configtypes.String(),
                valtype=configtypes.String(),
            ),
            default={"DEFAULT": "https://duckduckgo.com/?q={}", "google": "https://google.com/?q={}"},
            backends=[],
            raw_backends=None)),
    ]))
    config_stub._init_values()