diff options
author | Florian Bruhin <me@the-compiler.org> | 2018-11-30 12:45:01 +0100 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2018-11-30 12:45:01 +0100 |
commit | 569bb0fa0989ae3a87d7725d2a19c9d746bf42d8 (patch) | |
tree | f3461b05bc4e55db218ea9c3710907b17a51e5f3 /tests/unit/api | |
parent | d549d4d5e2aff841150095b18681a75a10b36bbd (diff) | |
download | qutebrowser-569bb0fa0989ae3a87d7725d2a19c9d746bf42d8.tar.gz qutebrowser-569bb0fa0989ae3a87d7725d2a19c9d746bf42d8.zip |
Add cmdutils.Value instead of using count=True/win_id=True
Diffstat (limited to 'tests/unit/api')
-rw-r--r-- | tests/unit/api/test_cmdutils.py | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/tests/unit/api/test_cmdutils.py b/tests/unit/api/test_cmdutils.py index f2318ab46..5e1389c80 100644 --- a/tests/unit/api/test_cmdutils.py +++ b/tests/unit/api/test_cmdutils.py @@ -190,23 +190,39 @@ class TestRegister: def test_win_id(self): @cmdutils.register() - @cmdutils.argument('win_id', win_id=True) + @cmdutils.argument('win_id', value=cmdutils.Value.win_id) def fun(win_id): """Blah.""" assert objects.commands['fun']._get_call_args(42) == ([42], {}) def test_count(self): @cmdutils.register() - @cmdutils.argument('count', count=True) + @cmdutils.argument('count', value=cmdutils.Value.count) def fun(count=0): """Blah.""" assert objects.commands['fun']._get_call_args(42) == ([0], {}) + def test_fill_self(self): + with pytest.raises(TypeError, match="fun: Can't fill 'self' with " + "value!"): + @cmdutils.register(instance='foobar') + @cmdutils.argument('self', value=cmdutils.Value.count) + def fun(self): + """Blah.""" + + def test_fill_invalid(self): + with pytest.raises(TypeError, match="fun: Invalid value='foo' for " + "argument 'arg'!"): + @cmdutils.register() + @cmdutils.argument('arg', value='foo') + def fun(arg): + """Blah.""" + def test_count_without_default(self): with pytest.raises(TypeError, match="fun: handler has count parameter " "without default!"): @cmdutils.register() - @cmdutils.argument('count', count=True) + @cmdutils.argument('count', value=cmdutils.Value.count) def fun(count): """Blah.""" @@ -344,6 +360,17 @@ class TestArgument: } assert fun.qute_args == expected + def test_arginfo_boolean(self): + @cmdutils.argument('special1', value=cmdutils.Value.count) + @cmdutils.argument('special2', value=cmdutils.Value.win_id) + @cmdutils.argument('normal') + def fun(special1, special2, normal): + """Blah.""" + + assert fun.qute_args['special1'].value + assert fun.qute_args['special2'].value + assert not fun.qute_args['normal'].value + def test_wrong_order(self): """When @cmdutils.argument is used above (after) @register, fail.""" with pytest.raises(ValueError, match=r"@cmdutils.argument got called " @@ -353,13 +380,6 @@ class TestArgument: def fun(bar): """Blah.""" - def test_count_and_win_id_same_arg(self): - with pytest.raises(TypeError, - match="Argument marked as both count/win_id!"): - @cmdutils.argument('arg', count=True, win_id=True) - def fun(arg=0): - """Blah.""" - def test_no_docstring(self, caplog): with caplog.at_level(logging.WARNING): @cmdutils.register() |