Revision: 4098
Author: pekka.klarck
Date: Wed Sep 22 15:56:29 2010
Log: tests and fix for OUTPUT in BuiltIn possibly being None if the lib is
used externally (issue 654)
http://code.google.com/p/robotframework/source/detail?r=4098
Added:
/trunk/atest/robot/standard_libraries/builtin/listener_using_builtin.py
/trunk/atest/robot/standard_libraries/builtin/used_in_custom_libs_and_listeners.txt
/trunk/atest/testdata/standard_libraries/builtin/UseBuiltIn.py
/trunk/atest/testdata/standard_libraries/builtin/used_in_custom_libs_and_listeners.txt
Modified:
/trunk/src/robot/libraries/BuiltIn.py
=======================================
--- /dev/null
+++ /trunk/atest/robot/standard_libraries/builtin/listener_using_builtin.py
Wed Sep 22 15:56:29 2010
@@ -0,0 +1,9 @@
+from robot.libraries.BuiltIn import BuiltIn
+
+BIN = BuiltIn()
+
+
+def start_keyword(*args):
+ if BIN.get_variables()['${TESTNAME}'] == 'Listener Using BuiltIn':
+ BIN.set_test_variable('${SET BY LISTENER}', 'quux')
+
=======================================
--- /dev/null
+++
/trunk/atest/robot/standard_libraries/builtin/used_in_custom_libs_and_listeners.txt
Wed Sep 22 15:56:29 2010
@@ -0,0 +1,14 @@
+*** Settings ***
+Suite Setup Run Tests --listener
${CURDIR}${/}listener_using_builtin.py
standard_libraries/builtin/used_in_custom_libs_and_listeners.txt
+Force Tags regression pybot jybot
+Resource atest_resource.txt
+
+*** Test Cases ***
+
+Keywords Using BuiltIn
+ ${tc} = Check Test Case ${TESTNAME}
+ Check Log Message ${tc.kws[0].msgs[0]} Log level changed from INFO
to DEBUG
+ Check Log Message ${tc.kws[0].msgs[1]} Hello, debug world! DEBUG
+
+Listener Using BuiltIn
+ Check Test Case ${TESTNAME}
=======================================
--- /dev/null
+++ /trunk/atest/testdata/standard_libraries/builtin/UseBuiltIn.py Wed Sep
22 15:56:29 2010
@@ -0,0 +1,15 @@
+from robot.libraries.BuiltIn import BuiltIn
+
+
+def log_debug_message():
+ b = BuiltIn()
+ b.set_log_level('DEBUG')
+ b.log('Hello, debug world!', 'DEBUG')
+
+def get_test_name():
+ return BuiltIn().get_variables()['${TEST NAME}']
+
+def set_secret_variable():
+ BuiltIn().set_test_variable('${SECRET}', '*****')
+
+
=======================================
--- /dev/null
+++
/trunk/atest/testdata/standard_libraries/builtin/used_in_custom_libs_and_listeners.txt
Wed Sep 22 15:56:29 2010
@@ -0,0 +1,16 @@
+*** Settings ***
+Library UseBuiltIn.py
+
+
+*** Test Cases ***
+
+Keywords Using BuiltIn
+ Log Debug Message
+ ${name} = Get Test Name
+ Should Be Equal ${name} ${TESTNAME}
+ Set Secret Variable
+ Should Be Equal ${secret} *****
+ Variable Should Not Exist ${SET BY LISTENER}
+
+Listener Using BuiltIn
+ Should Be Equal ${SET BY LISTENER} quux
=======================================
--- /trunk/src/robot/libraries/BuiltIn.py Tue Sep 7 11:43:15 2010
+++ /trunk/src/robot/libraries/BuiltIn.py Wed Sep 22 15:56:29 2010
@@ -16,7 +16,7 @@
import re
import time
-from robot.output import LOGGER, OUTPUT, Message
+from robot.output import LOGGER, Message
from robot.errors import DataError, ExecutionFailed, ExecutionFailures
from robot import utils
from robot.utils import asserts
@@ -773,7 +773,7 @@
if not isinstance(name, basestring):
raise DataError('Keyword name must be a string')
kw = Keyword(name, list(args))
- return kw.run(ExecutionContext(NAMESPACES.current, OUTPUT))
+ return kw.run(ExecutionContext(NAMESPACES.current, self._output))
def run_keywords(self, *names):
"""Executes all the given keywords in a sequence without arguments.
@@ -793,7 +793,7 @@
self.run_keyword(kw)
except ExecutionFailed, err:
errors.extend(err.get_errors())
- context = ExecutionContext(NAMESPACES.current, OUTPUT)
+ context = ExecutionContext(NAMESPACES.current,
self._output)
if not err.can_continue(context.teardown):
break
if errors:
@@ -1230,7 +1230,7 @@
The available levels: TRACE, DEBUG, INFO (default), WARN and NONE
(no
logging).
"""
- old = OUTPUT.set_log_level(level)
+ old = self._output.set_log_level(level)
self.log('Log level changed from %s to %s' % (old, level.upper()))
return old
@@ -1561,6 +1561,16 @@
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = get_version()
+ @property
+ def _output(self):
+ # OUTPUT is initially set to None and gets real value only when
actual
+ # execution starts. If BuiltIn is used externally before that,
OUTPUT
+ # gets None value. For more information see this bug report:
+ # http://code.google.com/p/robotframework/issues/detail?id=654
+ # TODO: Refactor running so that OUTPUT is available via context
+ from robot.output import OUTPUT
+ return OUTPUT
+
def _matches(self, string, pattern):
# Must use this instead of fnmatch when string may contain
newlines.
return utils.matches(string, pattern, caseless=False,
spaceless=False)