From 2e8800504c4a7bbd6a1f76c316dde8839a4f5ab5 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Sat, 6 Mar 2010 13:29:21 +0100 Subject: [PATCH] Fix handling of keyword arguments for baker and added tests. --- patoolib/baker.py | 2 +- tests/test_baker.py | 48 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/test_baker.py diff --git a/patoolib/baker.py b/patoolib/baker.py index 3f3d548..ce9b8a7 100644 --- a/patoolib/baker.py +++ b/patoolib/baker.py @@ -510,7 +510,7 @@ class Baker(object): # Rearrange the arguments into the order Python expects newargs = [] - newkwargs = {} + newkwargs = dict(kwargs) for name in cmd.argnames: if args and cmd.keywords.get(name) is None: # This argument is required or optional and we have a bare arg diff --git a/tests/test_baker.py b/tests/test_baker.py new file mode 100644 index 0000000..39395c6 --- /dev/null +++ b/tests/test_baker.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 2010 Bastian Kleineidam +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +import unittest +from patoolib import baker + + +class TestBaker (unittest.TestCase): + + def test_func_args (self): + @baker.command + def func(a, b, c): + return (a, b, c) + res = baker.run(argv=[__file__, 'func', '1', '2', '3']) + self.assertEqual(res, ('1', '2', '3')) + + def test_func_noargs (self): + @baker.command + def func(): + return 42 + res = baker.run(argv=[__file__, 'func']) + self.assertEqual(res, 42) + + def test_func_kwargs (self): + @baker.command + def func(arg1, *args, **kwargs): + return arg1 + res = baker.run(argv=[__file__, 'func', 'argvalue1']) + self.assertEqual(res, 'argvalue1') + + def test_func_kwargs_params (self): + @baker.command(params={"verbose": "Be verbose"}) + def func(*args, **kwargs): + return kwargs['verbose'] + res = baker.run(argv=[__file__, 'func', '--verbose']) + self.assertEqual(res, True)