Commit Graph

103 Commits

Author SHA1 Message Date
Florian Bruhin
445d287955 Revert "Fix choices validation with unannotated args"
This reverts commit 12061b8bb1.
2016-08-23 23:34:02 +02:00
Florian Bruhin
12061b8bb1 Fix choices validation with unannotated args
Something like:

    @cmdutils.argument('foo', choices=['one', 'two'])
    def func(foo):
        # ...

didn't actually validate the foo argument, since the inferred type of
the argument is None, and that skipped all conversion (and thus
validation).

Fixes #1871
See #1885
2016-08-23 22:01:21 +02:00
Florian Bruhin
df3733af54 tests: Use pytest.fixture instead of yield_fixture
See #1877
2016-08-22 07:40:24 +02:00
Florian Bruhin
a24391d40d Fix lint 2016-08-10 09:20:30 +02:00
Florian Bruhin
f0133624bf Add some tests for -OO logging 2016-08-10 09:05:04 +02:00
Ryan Roden-Corrent
c792ffda67 Remove Command.completion.
Command completion types are now identified by ArgInfo, so just use
that directly and cut out the middle-man. This shouldn't change any
completion behavior.

Adds a test for get_pos_arg_info to test_cmdutils.

Modifies test_completer to test the use of get_pos_arg_info. Instead of
using FakeCommand, real Command objects are used, to validate that the
Completer works with the real Command interface. This also cleans out
some test cases that were testing things already covered by other cases.
2016-08-06 11:59:04 -04:00
Florian Bruhin
4541f19195 Fix crash when doing :<space><enter>
Introduced in #1577.
Fixes #1773.
2016-08-05 15:42:03 +02:00
Marshall Lochbaum
c19e1947f8 Remove tests for cmdutils.arg_or_count (fixes #1735 with previous commits) 2016-08-02 12:02:40 -04:00
Florian Bruhin
9ff006746f Handle empty command in CommandRunner.parse_all
Sicne we now call self._get_alias there, we also need to make sure it's
not an empty string before that.

Introduced in #1577. Fixes #1690.
2016-07-27 11:19:01 +02:00
Florian Bruhin
2649418c0b Fix lint 2016-07-10 17:04:26 +02:00
Florian Bruhin
d2ece6b542 Move Backend enum to usertypes
Otherwise we have a cyclic import
2016-07-10 17:04:26 +02:00
Florian Bruhin
34e39bed4e Add a test for cmd instance with wrong backend 2016-07-10 17:04:25 +02:00
Florian Bruhin
7859df74c4 Add tests for Command.run 2016-07-10 17:04:25 +02:00
Florian Bruhin
2136d00aa2 tests: Add a fake_args fixture 2016-07-10 17:04:25 +02:00
Florian Bruhin
17466b4f26 Fix some lint 2016-07-07 18:32:52 +02:00
Florian Bruhin
21b282ce29 Get rid of _DummyUserscriptRunner
This simplifies the code a bit and only provides
userscript.run_async (and not the UserscriptRunner class) as entrypoint.
2016-07-07 18:32:52 +02:00
Florian Bruhin
a6307497c0 Rewrite userscripts to work with async dumping 2016-07-07 18:32:52 +02:00
Michał Góral
9b394e4111 Use config_stub instead of monkeypatching config.get() 2016-06-13 19:39:00 +02:00
Michał Góral
4b883c089e Fixed linters. 2016-06-12 23:04:14 +02:00
Michał Góral
370c8a8b07 Created tests for reading aliases. 2016-06-12 22:31:10 +02:00
Michał Góral
7ee99ba043 Moved searching for aliases to CommandRunner.parse_all()
This addresses issue with having alias for multiple commands splitted by ';;'.

See: The-Compiler/qutebrowser#956.
2016-06-12 21:09:10 +02:00
Florian Bruhin
520572321a Add unittests for partial command parsing 2016-06-06 16:18:49 +02:00
Florian Bruhin
e4d84b0bfc Simplify argparser.type_check
If the value isn't param.default, it will always be a string or a flag, as
type_conv never gets called when the function is called from Python.
2016-05-18 07:16:17 +02:00
Florian Bruhin
a83bf9c3ee Simplify argparser.type_conv
Since we're not using those functions as argparse callbacks anymore, we
can write a normal function instead of factories, which simplifies
things a lot.
2016-05-18 06:55:27 +02:00
Florian Bruhin
6ed9b6b13f Make sure typing.Union[str, int] gets handled
str always needs to be the last element checked as otherwise it'd always
win.
2016-05-18 06:55:17 +02:00
Florian Bruhin
a0d0b6464f Use typing.py-like annotations for command args
This means:

- An annotation like (int, str) is now typing.Union[int, str].
- utils.typing got expanded so it acts like the real typing.py, with
  issubclass() working properly with typing.Union and __union_params__
  being set.
- A literal string doesn't exist anymore as annotation, instead
  @cmdutils.argument now has a 'choices' argument which can be used like
  @cmdutils.argument('arg', choices=['val1', 'val2']).
- Argument validating/converting is now entirely handled by
  argparser.type_conv instead of relying on python's argparse, i.e.
  type/choices is now not passed to argparse anymore.
2016-05-18 06:55:17 +02:00
Florian Bruhin
9694374673 Add test for cmd arg types 2016-05-18 06:55:17 +02:00
Florian Bruhin
c33f0c3512 Use @cmdutils.argument for completions 2016-05-18 06:55:17 +02:00
Florian Bruhin
3ab40bbc23 Clear globals correctly for all cmdutils tests
TestArgument didn't clear the globals as the fixture was inside
TestRegister.

This means test_run_vulture failed in funny ways because run_vulture.py
generated a whitelist containing "<locals>" for commands:

    tests/unit/scripts/test_run_vulture.py:55: in run
        return run_vulture.run([str(e.basename) for e in files])
    scripts/dev/run_vulture.py:146: in run
        vult.scavenge(files + [whitelist_file.name])
    .tox/py35/lib/python3.5/site-packages/vulture.py:107: in scavenge
        self.scan(module_string)
    .tox/py35/lib/python3.5/site-packages/vulture.py:75: in scan
        node = ast.parse(node_string, filename=self.file)
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    source = 'qutebrowser.browser.commands.CommandDispatcher.buffer\nqutebrowser.misc.savemanager.SaveManager.save_command\nqutebro...iidoc.UsageFormatter._get_default_metavar_for_positional\nscripts.dev.src2asciidoc.UsageFormatter._metavar_formatter\n'
    filename = '/tmp/tmp_ein2umn', mode = 'exec'

        def parse(source, filename='<unknown>', mode='exec'):
            """
            Parse the source into an AST node.
            Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
            """
    >       return compile(source, filename, mode, PyCF_ONLY_AST)
    E         File "/tmp/tmp_ein2umn", line 16
    E           test_cmdutils.TestArgument.test_wrong_order.<locals>.fun
    E                                                       ^
    E       SyntaxError: invalid syntax
2016-05-18 06:55:17 +02:00
Florian Bruhin
c14db202d6 Use @cmdutils.argument to hide arguments 2016-05-18 06:55:17 +02:00
Florian Bruhin
2370793f38 Make win_id/count mutually exclusive for ArgInfo 2016-05-18 06:55:17 +02:00
Florian Bruhin
35135c4b0d Use @cmdutils.argument for win_id/count 2016-05-18 06:55:17 +02:00
Florian Bruhin
04367851c3 Refactor how cmdutils.ArgInfo works
It's now a real class, and some other aspects about how it's handled
were cleaned up as well.
2016-05-18 06:55:17 +02:00
Florian Bruhin
9eeaeb95c3 Make sure @cmdutils.argument after @register fails 2016-05-18 06:55:17 +02:00
Florian Bruhin
3c586f34ff Add a @cmdutils.argument decorator
For now the only available keyword argument is 'flag' which customizes
the flag an argument will get.

See #637.
2016-05-18 06:55:17 +02:00
Florian Bruhin
36da07c73b Fix lint 2016-05-10 07:56:54 +02:00
Florian Bruhin
5eff35ba30 cmdutils.register: annotation -> arg for flags
Instead of using a 'flag' key in the annotation dict, we now use a flags
argument to @cmdutils.register which is a {argument: flag} dict.

See #637.
2016-05-10 07:35:41 +02:00
Florian Bruhin
49fb981e7f Add test for completion count in cmdutils.register 2016-05-10 07:12:50 +02:00
Florian Bruhin
9ca5acd546 Add tests for flags with @cmdutils.register 2016-05-10 07:00:10 +02:00
Florian Bruhin
b17ecd1376 Add tests for cmdutils.register/star_args_optional 2016-05-10 06:41:42 +02:00
Florian Bruhin
526441bcae Fix new flake8 lint.
For some reason these issues weren't shown with pytest-pep8/flakes.
2016-01-22 17:33:58 +01:00
Florian Bruhin
1fb34331e5 tests: Default to raising=True for qtbot.
- qtbot.waitSignal with raising=True is the default this way, so we remove the
  raising=True.
- qtbot.waitSignal with raising=False stay untouched
- Some qtbot.waitSignal without raising had one added (because we don't want it
  to raise)
- Some qtbot.waitSignal without raising actually should've raised, which they
  do now.
2016-01-08 09:49:06 +01:00
Florian Bruhin
a5f2ac5f03 Adjust copyright years. 2016-01-04 07:12:39 +01:00
Florian Bruhin
81e1c72588 pylint: unneeded-suppression -> useless-suppression 2015-12-21 10:02:43 +01:00
Florian Bruhin
9101046fe5 tests: Adjust error message comparison for Windows. 2015-12-21 09:51:25 +01:00
Florian Bruhin
95e67bba7b Suppress pylint no-member for os.mkfifo. 2015-12-21 09:47:20 +01:00
Florian Bruhin
4b770f4f35 tests: Try to work around race condition. 2015-12-21 08:55:55 +01:00
Florian Bruhin
59c8e5c3d1 Add some tests for commands.userscripts. 2015-12-21 08:45:46 +01:00
Florian Bruhin
eeab4d41ba Make it possible to pass a count via command name.
This is only used for tests so far and not intended for general usage (and thus
undocumented).
2015-11-15 19:55:01 +01:00
Florian Bruhin
8b40603562 Revert "Fix argparser test after win_registry change."
This reverts commit 70243d6e2f.
2015-08-24 08:05:34 +02:00
Florian Bruhin
70243d6e2f Fix argparser test after win_registry change.
The last focused window was now window 1 - so we better make this explicit.
2015-08-23 22:37:27 +02:00
Florian Bruhin
7ee4d2f2c9 100% test coverage for commands.argparser. 2015-08-20 07:14:25 +02:00
Florian Bruhin
2c5269acd6 Reorganize tests directory. 2015-08-18 20:19:02 +02:00