Revision: c3d49e66ec0d
Branch:   default
Author:   Robot Framework Developers (robotframew...@gmail.com)
Date:     Thu Sep 12 13:22:29 2013 UTC
Log:      Fixed validating kwargs in --dryrun mode.

Update issue 1511
Status: Done
Owner: pekka.klarck
It turned out that kwargs weren't handled at all in dry-run mode. This caused
false positives in cases like in this issue, but it also caused false
negatives in some cases.

Luckily fixing the problem wasn't too complicated, because it was possible to use the same code for resolving/validating arguments in dry-run than in normal
run. In the end more code was removed than added.
http://code.google.com/p/robotframework/source/detail?r=c3d49e66ec0d

Added:
 /atest/robot/cli/dryrun/kwargs.txt
 /atest/testdata/cli/dryrun/Library.py
 /atest/testdata/cli/dryrun/kwargs.txt
Modified:
 /src/robot/running/arguments/argumentresolver.py
 /src/robot/running/arguments/argumentvalidator.py
 /src/robot/running/handlers.py
 /src/robot/running/userkeyword.py

=======================================
--- /dev/null
+++ /atest/robot/cli/dryrun/kwargs.txt  Thu Sep 12 13:22:29 2013 UTC
@@ -0,0 +1,17 @@
+*** Settings ***
+Suite Setup      Run Tests    --dryrun    cli/dryrun/kwargs.txt
+Force Tags       regression    pybot    jybot
+Resource         atest_resource.txt
+
+*** Test Cases ***
+Positional and kwargs
+    Check Test Case    ${TESTNAME}
+
+Varargs and kwargs
+    Check Test Case    ${TESTNAME}
+
+Kwargs
+    Check Test Case    ${TESTNAME}
+
+Invalid kwargs
+    Check Test Case    ${TESTNAME}
=======================================
--- /dev/null
+++ /atest/testdata/cli/dryrun/Library.py       Thu Sep 12 13:22:29 2013 UTC
@@ -0,0 +1,10 @@
+def positional_and_kwargs(positional, **kwargs):
+    pass
+
+
+def varargs_and_kwargs(*varargs, **kwargs):
+    pass
+
+
+def kwargs(**kwargs):
+    pass
=======================================
--- /dev/null
+++ /atest/testdata/cli/dryrun/kwargs.txt       Thu Sep 12 13:22:29 2013 UTC
@@ -0,0 +1,27 @@
+*** Settings ***
+Library    Library.py
+
+*** Test Cases ***
+Positional and kwargs
+ [Documentation] FAIL Keyword 'Library.Positional And Kwargs' expected 1 non-keyword argument, got 0.
+    Positional and kwargs    arg
+    Positional and kwargs    arg    a=1    b=2
+    Positional and kwargs    a=1
+
+Varargs and kwargs
+    Varargs and kwargs
+    Varargs and kwargs    a
+    Varargs and kwargs    a    b    c
+    Varargs and kwargs    a=1
+    Varargs and kwargs    a=1    b=2    c=3
+    Varargs and kwargs    a    b    c=3    d=4
+
+Kwargs
+    Kwargs
+    Kwargs    a=1
+    Kwargs    a=1    b=2    c=3
+    Kwargs    @{EMPTY}
+
+Invalid kwargs
+ [Documentation] FAIL Keyword 'Library.Varargs And Kwargs' got positional argument after named arguments.
+    Varargs and kwargs    a=1    @{EMPTY}    invalid
=======================================
--- /src/robot/running/arguments/argumentresolver.py Thu Jun 6 14:00:44 2013 UTC +++ /src/robot/running/arguments/argumentresolver.py Thu Sep 12 13:22:29 2013 UTC
@@ -30,7 +30,8 @@
         positional, named = self._named_resolver.resolve(arguments)
positional, named = self._variable_replacer.replace(positional, named,
                                                             variables)
-        self._argument_validator.validate(positional, named)
+        self._argument_validator.validate(positional, named,
+                                          dryrun=not variables)
         return positional, named


@@ -98,7 +99,7 @@
         self._resolve_until = resolve_until

     def replace(self, positional, named, variables=None):
-        # `variables` is None when using Libdoc
+        # `variables` is None in dry-run mode and when using Libdoc
         if variables:
positional = variables.replace_list(positional, self._resolve_until)
             named = dict((name, variables.replace_scalar(value))
=======================================
--- /src/robot/running/arguments/argumentvalidator.py Thu Jun 6 14:00:44 2013 UTC +++ /src/robot/running/arguments/argumentvalidator.py Thu Sep 12 13:22:29 2013 UTC
@@ -22,15 +22,13 @@
     def __init__(self, argspec):
         self._argspec = argspec

-    def validate(self, positional, named):
+    def validate(self, positional, named, dryrun=False):
+        if dryrun and any(is_list_var(arg) for arg in positional):
+            return
         self._validate_limits(positional, named, self._argspec)
         self._validate_no_multiple_values(positional, named, self._argspec)
self._validate_no_mandatory_missing(positional, named, self._argspec)

-    def validate_dry_run(self, arguments):
-        if not any(is_list_var(arg) for arg in arguments):
-            self._validate_limits(arguments, {}, self._argspec)
-
     def _validate_limits(self, positional, named, spec):
count = len(positional) + sum(1 for n in named if n in spec.positional)
         if not spec.minargs <= count <= spec.maxargs:
=======================================
--- /src/robot/running/handlers.py      Sun Jun  9 16:58:08 2013 UTC
+++ /src/robot/running/handlers.py      Thu Sep 12 13:22:29 2013 UTC
@@ -20,7 +20,7 @@

 from .arguments import (PythonArgumentParser, JavaArgumentParser,
                         DynamicArgumentParser, ArgumentResolver,
- ArgumentValidator, ArgumentMapper, JavaArgumentCoercer)
+                        ArgumentMapper, JavaArgumentCoercer)
 from .keywords import Keywords, Keyword
 from .outputcapture import OutputCapturer
 from .runkwregister import RUN_KW_REGISTER
@@ -83,7 +83,7 @@
             return self._get_global_handler(method, name)
         return None

-    def resolve_arguments(self, args, variables):
+    def resolve_arguments(self, args, variables=None):
         return self._argument_resolver.resolve(args, variables)

     @property
@@ -113,7 +113,7 @@
     def _dry_run(self, context, args):
         if self.longname == 'BuiltIn.Import Library':
             return self._run(context, args)
-        ArgumentValidator(self.arguments).validate_dry_run(args)
+        self.resolve_arguments(args)
         return None

     def _run(self, context, args):
=======================================
--- /src/robot/running/userkeyword.py   Sun Jun  9 19:50:22 2013 UTC
+++ /src/robot/running/userkeyword.py   Thu Sep 12 13:22:29 2013 UTC
@@ -24,12 +24,12 @@
 from robot.output import LOGGER
 from robot import utils

+from .arguments import (ArgumentMapper, ArgumentResolver,
+                        UserKeywordArgumentParser)
 from .baselibrary import BaseLibrary
-from .usererrorhandler import UserErrorHandler
 from .keywords import Keywords, Keyword
 from .timeouts import KeywordTimeout
-from .arguments import (ArgumentValidator, UserKeywordArgumentParser,
-                        ArgumentResolver, ArgumentMapper)
+from .usererrorhandler import UserErrorHandler


 class UserLibrary(BaseLibrary):
@@ -147,15 +147,11 @@
         return self._normal_run(context, arguments)

     def _dry_run(self, context, arguments):
-        arguments = self._resolve_dry_run_args(arguments)
+        arguments = self._resolve_arguments(arguments)
         error, return_ = self._execute(context, arguments)
         if error:
             raise error
-
-    def _resolve_dry_run_args(self, arguments):
-        ArgumentValidator(self.arguments).validate_dry_run(arguments)
-        missing_args = len(self.arguments.positional) - len(arguments)
-        return tuple(arguments) + (None,) * missing_args
+        return None

     def _normal_run(self, context, arguments):
         arguments = self._resolve_arguments(arguments, context.variables)
@@ -168,7 +164,7 @@
             raise error
         return return_value

-    def _resolve_arguments(self, arguments, variables):
+    def _resolve_arguments(self, arguments, variables=None):
         resolver = ArgumentResolver(self.arguments)
         mapper = ArgumentMapper(self.arguments)
         positional, named = resolver.resolve(arguments, variables)

--

--- You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to robotframework-commit+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to