Revision: 3816
Author: jussi.ao.malinen
Date: Tue Jul 20 06:53:37 2010
Log: Reverted change 3815, except for changes to
atest/testresources/testlibs/libraryscope.py (to keep a failing acceptance
test)
Reverted because this fix causes more problems in Ride, Jython and libdoc
and also because it makes library initialization a two step process.
Original message from reverted change: "Fixed problem with libraries
getting initialized more than once (Issue 589,
ROBOT_LIBRARY_SCOPE = "GLOBAL" is ignored in RF 2.5)"
http://code.google.com/p/robotframework/source/detail?r=3816
Modified:
/trunk/src/robot/running/importer.py
/trunk/src/robot/running/testlibraries.py
/trunk/utest/running/test_handlers.py
/trunk/utest/running/test_testlibrary.py
=======================================
--- /trunk/src/robot/running/importer.py Fri Jul 16 04:09:52 2010
+++ /trunk/src/robot/running/importer.py Tue Jul 20 06:53:37 2010
@@ -50,7 +50,6 @@
LOGGER.info("Found test library '%s' with arguments %s from
cache"
% (name, utils.seq2str2(positional)))
return self._libraries[key]
- lib.create_handlers()
self._libraries[key] = lib
libtype = lib.__class__.__name__.replace('Library', '').lower()[1:]
LOGGER.info("Imported library '%s' with arguments %s (version %s, "
=======================================
--- /trunk/src/robot/running/testlibraries.py Fri Jul 16 04:09:52 2010
+++ /trunk/src/robot/running/testlibraries.py Tue Jul 20 06:53:37 2010
@@ -76,13 +76,9 @@
self._libcode = libcode
self.init = self._create_init_handler(libcode)
self.positional_args, self.named_args =
self.init.arguments.resolve(args, variables)
-
- def create_handlers(self):
- if self._libcode is None:
- return
- self._libinst = self.get_instance()
- self.handlers = self._create_handlers(self._libinst)
- self.init_scope_handling()
+ self._libinst = self.get_instance()
+ self.handlers = self._create_handlers(self._libinst)
+ self.init_scope_handling()
def start_suite(self):
pass
=======================================
--- /trunk/utest/running/test_handlers.py Fri Jul 16 04:09:52 2010
+++ /trunk/utest/running/test_handlers.py Tue Jul 20 06:53:37 2010
@@ -61,7 +61,6 @@
def test_getarginfo_getattr(self):
testlib = TestLibrary('classes.GetattrLibrary')
- testlib.create_handlers()
handlers = testlib.handlers.values()
assert_equals(len(handlers), 3)
for handler in handlers:
=======================================
--- /trunk/utest/running/test_testlibrary.py Fri Jul 16 04:09:52 2010
+++ /trunk/utest/running/test_testlibrary.py Tue Jul 20 06:53:37 2010
@@ -27,58 +27,53 @@
( "equals", ("1","2","failed") ), ]
java_keywords = [ ( "print", ("msg",) ) ]
-def load_lib(name, args=None):
- lib = TestLibrary(name, args)
- lib.create_handlers()
- return lib
-
class TestLibraryTypes(unittest.TestCase):
def test_python_library(self):
- lib = load_lib("BuiltIn")
+ lib = TestLibrary("BuiltIn")
assert_equals(lib.__class__, _ClassLibrary)
assert_equals(lib.positional_args, [])
def test_python_library_with_args(self):
- lib = load_lib("ParameterLibrary", ['my_host', '8080'])
+ lib = TestLibrary("ParameterLibrary", ['my_host', '8080'])
assert_equals(lib.__class__, _ClassLibrary)
assert_equals(lib.positional_args, ['my_host', '8080'])
def test_module_library(self):
- lib = load_lib("module_library")
+ lib = TestLibrary("module_library")
assert_equals(lib.__class__, _ModuleLibrary)
def test_module_library_with_args(self):
assert_raises(DataError, TestLibrary, "module_library", ['arg'] )
def test_dynamic_python_library(self):
- lib = load_lib("RunKeywordLibrary")
+ lib = TestLibrary("RunKeywordLibrary")
assert_equals(lib.__class__, _DynamicLibrary)
if utils.is_jython:
def test_java_library(self):
- lib = load_lib("ExampleJavaLibrary")
+ lib = TestLibrary("ExampleJavaLibrary")
assert_equals(lib.__class__, _ClassLibrary)
class TestImports(unittest.TestCase):
def test_import_python_class(self):
- lib = load_lib("BuiltIn")
+ lib = TestLibrary("BuiltIn")
self._verify_lib(lib, "BuiltIn", default_keywords)
def test_import_python_class_from_module(self):
- lib = load_lib("BuiltIn.BuiltIn")
+ lib = TestLibrary("BuiltIn.BuiltIn")
self._verify_lib(lib, "BuiltIn.BuiltIn", default_keywords)
def test_import_python_module(self):
- lib = load_lib("module_library")
+ lib = TestLibrary("module_library")
kws = ["passing", "two arguments from
class", "lambdakeyword", "argument"]
self._verify_lib(lib, "module_library", [ (kw, None) for kw in kws
])
def test_import_python_module_from_module(self):
- lib = load_lib("pythonmodule.library")
+ lib = TestLibrary("pythonmodule.library")
self._verify_lib(lib, "pythonmodule.library",
[("keyword from submodule", None)])
@@ -87,7 +82,7 @@
"ImportError: No module named %s\nPYTHONPATH:")
for name in 'nonexisting', 'nonexi.sting':
try:
- load_lib(name)
+ TestLibrary(name)
except DataError, err:
module = name.split('.')[0]
assert_true(str(err).startswith(exp % (name, module)), err)
@@ -107,48 +102,48 @@
TestLibrary, 'pythonmodule.some_object')
def test_import_with_unicode_name(self):
- self._verify_lib(load_lib(u"BuiltIn"), "BuiltIn", default_keywords)
- self._verify_lib(load_lib(u"BuiltIn.BuiltIn"), "BuiltIn.BuiltIn",
default_keywords)
-
self._verify_lib(load_lib(u"pythonmodule.library"), "pythonmodule.library",
+ self._verify_lib(TestLibrary(u"BuiltIn"), "BuiltIn",
default_keywords)
+
self._verify_lib(TestLibrary(u"BuiltIn.BuiltIn"), "BuiltIn.BuiltIn",
default_keywords)
+
self._verify_lib(TestLibrary(u"pythonmodule.library"), "pythonmodule.library",
[("keyword from submodule", None)])
def test_set_global_scope(self):
- assert_equals(load_lib('libraryscope.Global').scope, 'GLOBAL')
+ assert_equals(TestLibrary('libraryscope.Global').scope, 'GLOBAL')
def test_set_suite_scope(self):
- assert_equals(load_lib('libraryscope.Suite').scope, 'TESTSUITE')
+ assert_equals(TestLibrary('libraryscope.Suite').scope, 'TESTSUITE')
def test_set_test_scope(self):
- assert_equals(load_lib('libraryscope.Test').scope, 'TESTCASE')
+ assert_equals(TestLibrary('libraryscope.Test').scope, 'TESTCASE')
def test_set_invalid_scope(self):
for libname in ['libraryscope.InvalidValue',
'libraryscope.InvalidEmpty',
'libraryscope.InvalidMethod',
'libraryscope.InvalidNone']:
- lib = load_lib(libname)
+ lib = TestLibrary(libname)
assert_equals(lib.scope, 'TESTCASE')
if utils.is_jython:
def test_import_java(self):
- lib = load_lib("ExampleJavaLibrary")
+ lib = TestLibrary("ExampleJavaLibrary")
self._verify_lib(lib, "ExampleJavaLibrary", java_keywords)
def test_import_java_with_dots(self):
- lib = load_lib("javapkg.JavaPackageExample")
+ lib = TestLibrary("javapkg.JavaPackageExample")
self._verify_lib(lib, "javapkg.JavaPackageExample",
java_keywords)
def test_set_global_scope_java(self):
- lib = load_lib('javalibraryscope.Global')
+ lib = TestLibrary('javalibraryscope.Global')
assert_equals(lib.scope, 'GLOBAL')
def test_set_suite_scope_java(self):
- lib = load_lib('javalibraryscope.Suite')
+ lib = TestLibrary('javalibraryscope.Suite')
assert_equals(lib.scope, 'TESTSUITE')
def test_set_test_scope_java(self):
- lib = load_lib('javalibraryscope.Test')
+ lib = TestLibrary('javalibraryscope.Test')
assert_equals(lib.scope, 'TESTCASE')
def test_set_invalid_scope_java(self):
@@ -158,7 +153,7 @@
'javalibraryscope.InvalidPrivate',
'javalibraryscope.InvalidProtected',
'javalibraryscope.InvalidValue' ]:
- lib = load_lib(libname)
+ lib = TestLibrary(libname)
assert_equals(lib.scope, 'TESTCASE')
def _verify_lib(self, lib, libname, keywords):
@@ -189,7 +184,7 @@
self._test_init_handler('newstyleclasses.MetaClassLibrary')
def _test_init_handler(self, libname, args=None, min=0, max=0):
- lib = load_lib(libname, args)
+ lib = TestLibrary(libname, args)
assert_equals(lib.init.arguments._arg_limit_checker.minargs, min)
assert_equals(lib.init.arguments._arg_limit_checker.maxargs, max)
return lib
@@ -228,7 +223,7 @@
self._test_version('module_library', 'test')
def _test_version(self, name, version):
- lib = load_lib(name)
+ lib = TestLibrary(name)
assert_equals(lib.version, version)
if utils.is_jython:
@@ -243,7 +238,7 @@
class _TestScopes(unittest.TestCase):
def _get_lib_and_instance(self, name):
- lib = load_lib(name)
+ lib = TestLibrary(name)
if lib.scope == 'GLOBAL':
assert_not_none(lib._libinst)
else:
@@ -366,7 +361,7 @@
def test_get_handlers(self):
for lib in [ NameLibrary, DocLibrary, ArgInfoLibrary,
GetattrLibrary,
SynonymLibrary ]:
- testlib = load_lib('classes.%s' % lib.__name__)
+ testlib = TestLibrary('classes.%s' % lib.__name__)
handlers = testlib.handlers.values()
assert_equals(lib.handler_count, len(handlers), lib.__name__)
for handler in handlers:
@@ -374,7 +369,7 @@
assert_equals(handler._handler_name.count('skip'), 0)
def test_non_global_dynamic_handlers(self):
- lib = load_lib("RunKeywordLibrary")
+ lib = TestLibrary("RunKeywordLibrary")
assert_equals(len(lib.handlers), 2)
assert_true(lib.handlers.has_key('Run Keyword That Passes'))
assert_true(lib.handlers.has_key('Run Keyword That Fails'))
@@ -382,7 +377,7 @@
assert_none(lib.handlers['Run Keyword That Fails']._method)
def test_global_dynamic_handlers(self):
- lib = load_lib("RunKeywordLibrary.GlobalRunKeywordLibrary")
+ lib = TestLibrary("RunKeywordLibrary.GlobalRunKeywordLibrary")
assert_equals(len(lib.handlers), 2)
for name in 'Run Keyword That Passes', 'Run Keyword That Fails':
handler = lib.handlers[name]
@@ -391,7 +386,7 @@
assert_equals(handler._method.__name__, 'handler')
def test_synonym_handlers(self):
- testlib = load_lib('classes.SynonymLibrary')
+ testlib = TestLibrary('classes.SynonymLibrary')
names = [ 'handler', 'synonym_handler', 'another_synonym' ]
for handler in testlib.handlers.values():
# test 'handler_name' -- raises ValueError if it isn't
in 'names'
@@ -399,7 +394,7 @@
assert_equals(len(names), 0, 'handlers %s not created' % names,
False)
def test_global_handlers_are_created_only_once(self):
- lib = load_lib('classes.RecordingLibrary')
+ lib = TestLibrary('classes.RecordingLibrary')
calls_after_init = lib._libinst.calls_to_getattr
for _ in range(5):
lib.handlers['kw'].run(_FakeContext(), [])
@@ -413,7 +408,7 @@
MultipleSignatures,
NoHandlers,
Extended ]:
- testlib = load_lib(lib.__name__)
+ testlib = TestLibrary(lib.__name__)
handlers = testlib.handlers.values()
assert_equals(len(handlers), lib().handler_count,
lib.__name__)
for handler in handlers:
@@ -424,25 +419,25 @@
class TestDynamicLibrary(unittest.TestCase):
def test_get_keyword_doc_is_used_if_present(self):
- lib = load_lib('classes.ArgDocDynamicLibrary')
+ lib = TestLibrary('classes.ArgDocDynamicLibrary')
assert_equals(lib.handlers['No Arg'].doc, 'Keyword documentation
for No Arg')
def test_get_keyword_doc_and_args_are_ignored_if_not_callable(self):
- lib = load_lib('classes.InvalidAttributeDynamicLibrary')
+ lib = TestLibrary('classes.InvalidAttributeDynamicLibrary')
assert_equals(len(lib.handlers), 4)
assert_equals(lib.handlers['No Arg'].doc, '')
self._assert_handler_args(lib.handlers['No Arg'], 0, sys.maxint)
def test_handler_is_not_created_if_get_keyword_doc_fails(self):
- lib = load_lib('classes.InvalidGetDocDynamicLibrary')
+ lib = TestLibrary('classes.InvalidGetDocDynamicLibrary')
assert_equals(len(lib.handlers), 0)
def test_handler_is_not_created_if_get_keyword_args_fails(self):
- lib = load_lib('classes.InvalidGetArgsDynamicLibrary')
+ lib = TestLibrary('classes.InvalidGetArgsDynamicLibrary')
assert_equals(len(lib.handlers), 0)
def test_get_keyword_arguments_is_used_if_present(self):
- lib = load_lib('classes.ArgDocDynamicLibrary')
+ lib = TestLibrary('classes.ArgDocDynamicLibrary')
for name, exp in [ ('No Arg', ()) , ('One Arg', (1,1)),
('One or Two Args', (1, 2)),
('Many Args', (0, sys.maxint))]:
@@ -454,7 +449,7 @@
if utils.is_jython:
def test_dynamic_java_handlers(self):
- lib = load_lib('ArgDocDynamicJavaLibrary')
+ lib = TestLibrary('ArgDocDynamicJavaLibrary')
for name, min, max in [ ('Java No Arg', 0, 0), ('Java One
Arg', 1, 1),
('Java One or Two Args', 1, 2),
('Java Many Args', 0, sys.maxint) ]:
@@ -463,12 +458,12 @@
min, max)
def
test_get_keyword_doc_and_args_are_ignored_if_not_callable_in_java(self):
- lib = load_lib('InvalidAttributeArgDocDynamicJavaLibrary')
+ lib = TestLibrary('InvalidAttributeArgDocDynamicJavaLibrary')
assert_equals(len(lib.handlers), 1)
self._assert_handler_args(lib.handlers['keyword'], 0,
sys.maxint)
def
test_handler_is_not_created_if_get_keyword_doc_fails_in_java(self):
- lib = load_lib('InvalidSignatureArgDocDynamicJavaLibrary')
+ lib = TestLibrary('InvalidSignatureArgDocDynamicJavaLibrary')
assert_equals(len(lib.handlers), 0)
def _assert_java_handler(self, handler, doc, minargs, maxargs):