Revision: 3240
Author: janne.t.harkonen
Date: Fri May  7 15:00:30 2010
Log: fixed tests
http://code.google.com/p/robotframework/source/detail?r=3240

Modified:
 /trunk/utest/running/test_keywords.py
 /trunk/utest/running/test_testlibrary.py

=======================================
--- /trunk/utest/running/test_keywords.py       Fri May  7 05:25:59 2010
+++ /trunk/utest/running/test_keywords.py       Fri May  7 15:00:30 2010
@@ -58,6 +58,7 @@
         self.output = OutputStub()
         self.error = error
         self.variables = self.namespace.variables
+        self.dry_run = False

     def get_handler(self, kwname):
         return MockHandler('Mocked.'+kwname, error=self.error)
=======================================
--- /trunk/utest/running/test_testlibrary.py    Fri May  7 05:25:59 2010
+++ /trunk/utest/running/test_testlibrary.py    Fri May  7 15:00:30 2010
@@ -1,6 +1,6 @@
 import unittest
 import sys
-
+
 from robot.running.testlibraries import TestLibrary, _ClassLibrary, \
         _ModuleLibrary, _DynamicLibrary
 from robot.utils.asserts import *
@@ -29,56 +29,56 @@


 class TestLibraryTypes(unittest.TestCase):
-
+
     def test_python_library(self):
         lib = TestLibrary("BuiltIn")
         assert_equals(lib.__class__, _ClassLibrary)
         assert_equals(lib.positional_args, [])
-
+
     def test_python_library_with_args(self):
         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 = 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 = TestLibrary("RunKeywordLibrary")
         assert_equals(lib.__class__, _DynamicLibrary)
-
+
     if utils.is_jython:
         def test_java_library(self):
             lib = TestLibrary("ExampleJavaLibrary")
             assert_equals(lib.__class__, _ClassLibrary)
-
+

 class TestImports(unittest.TestCase):
-
+
     def test_import_python_class(self):
         lib = TestLibrary("BuiltIn")
         self._verify_lib(lib, "BuiltIn", default_keywords)
-
+
     def test_import_python_class_from_module(self):
         lib = TestLibrary("BuiltIn.BuiltIn")
         self._verify_lib(lib, "BuiltIn.BuiltIn", default_keywords)
-
+
     def test_import_python_module(self):
         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 = TestLibrary("pythonmodule.library")
-        self._verify_lib(lib, "pythonmodule.library",
+        self._verify_lib(lib, "pythonmodule.library",
                          [("keyword from submodule", None)])
-
+
     def test_import_non_existing_module(self):
-        exp = ("Importing test library '%s' failed: "
+        exp = ("Importing test library '%s' failed: "
                "ImportError: No module named %s\nPYTHONPATH:")
         for name in 'nonexisting', 'nonexi.sting':
             try:
@@ -88,52 +88,52 @@
                 assert_true(str(err).startswith(exp % (name, module)), err)
             else:
                 raise AssertionError("DataError not raised")
-
+
     def test_import_non_existing_class_from_existing_module(self):
msg = "Test library module 'pythonmodule' does not contain 'NonExisting'"
-        assert_raises_with_msg(DataError, msg,
+        assert_raises_with_msg(DataError, msg,
                                TestLibrary, 'pythonmodule.NonExisting')
-
+
     def test_import_invalid_type(self):
msg = "Imported test library is not a class or module, got '%s' instead"
-        assert_raises_with_msg(DataError, msg % 'StringType',
+        assert_raises_with_msg(DataError, msg % 'StringType',
                                TestLibrary, 'pythonmodule.some_string')
-        assert_raises_with_msg(DataError, msg % 'InstanceType',
+        assert_raises_with_msg(DataError, msg % 'InstanceType',
                                TestLibrary, 'pythonmodule.some_object')

     def test_import_with_unicode_name(self):
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", + self._verify_lib(TestLibrary(u"pythonmodule.library"), "pythonmodule.library",
                          [("keyword from submodule", None)])
-
+
     def test_set_global_scope(self):
         assert_equals(TestLibrary('libraryscope.Global').scope, 'GLOBAL')
-
-    def test_set_suite_scope(self):
+
+    def test_set_suite_scope(self):
         assert_equals(TestLibrary('libraryscope.Suite').scope, 'TESTSUITE')

-    def test_set_test_scope(self):
+    def test_set_test_scope(self):
         assert_equals(TestLibrary('libraryscope.Test').scope, 'TESTCASE')
-
+
     def test_set_invalid_scope(self):
-        for libname in ['libraryscope.InvalidValue',
+        for libname in ['libraryscope.InvalidValue',
                         'libraryscope.InvalidEmpty',
-                        'libraryscope.InvalidMethod',
+                        'libraryscope.InvalidMethod',
                         'libraryscope.InvalidNone']:
             lib = TestLibrary(libname)
             assert_equals(lib.scope, 'TESTCASE')
-
+
     if utils.is_jython:
-
+
         def test_import_java(self):
             lib = TestLibrary("ExampleJavaLibrary")
             self._verify_lib(lib, "ExampleJavaLibrary", java_keywords)
-
+
         def test_import_java_with_dots(self):
             lib = TestLibrary("javapkg.JavaPackageExample")
self._verify_lib(lib, "javapkg.JavaPackageExample", java_keywords)
-
+
         def test_set_global_scope_java(self):
             lib = TestLibrary('javalibraryscope.Global')
             assert_equals(lib.scope, 'GLOBAL')
@@ -141,102 +141,102 @@
         def test_set_suite_scope_java(self):
             lib = TestLibrary('javalibraryscope.Suite')
             assert_equals(lib.scope, 'TESTSUITE')
-
+
         def test_set_test_scope_java(self):
             lib = TestLibrary('javalibraryscope.Test')
             assert_equals(lib.scope, 'TESTCASE')
-
+
         def test_set_invalid_scope_java(self):
-            for libname in [ 'javalibraryscope.InvalidEmpty',
-                             'javalibraryscope.InvalidMethod',
-                             'javalibraryscope.InvalidNull',
+            for libname in [ 'javalibraryscope.InvalidEmpty',
+                             'javalibraryscope.InvalidMethod',
+                             'javalibraryscope.InvalidNull',
                              'javalibraryscope.InvalidPrivate',
                              'javalibraryscope.InvalidProtected',
                              'javalibraryscope.InvalidValue' ]:
                 lib = TestLibrary(libname)
                 assert_equals(lib.scope, 'TESTCASE')
-
+
     def _verify_lib(self, lib, libname, keywords):
         assert_equals(libname, lib.name)
         for name, _ in keywords:
             handler = lib.get_handler(name)
             exp = "%s.%s" % (libname, name)
-            assert_equals(utils.normalize(handler.longname),
+            assert_equals(utils.normalize(handler.longname),
                           utils.normalize(exp))


 class TestLibraryInit(unittest.TestCase):
-
+
     def test_python_library_without_init(self):
         self._test_init_handler('ExampleLibrary')
-
+
     def test_python_library_with_init(self):
         self._test_init_handler('ParameterLibrary', ['foo'], 0, 2)
-
+
     def test_new_style_class_without_init(self):
         self._test_init_handler('newstyleclasses.NewStyleClassLibrary')
-
+
     def test_new_style_class_with_init(self):
lib = self._test_init_handler('newstyleclasses.NewStyleClassArgsLibrary', ['value'], 1, 1)
         assert_equals(len(lib.handlers), 1)
-
+
     def test_library_with_metaclass(self):
         self._test_init_handler('newstyleclasses.MetaClassLibrary')
-
+
     def _test_init_handler(self, libname, args=None, min=0, max=0):
         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
-
+
     if utils.is_jython:
-
+
         def test_java_library_without_constructor(self):
             self._test_init_handler('ExampleJavaLibrary', None, 0, 0)
-
+
         def test_java_library_with_constructor(self):
self._test_init_handler('JavaVarArgsConstructor', ['arg1', 'arg2'], 1, 3)
-
+
         def test_extended_java_lib_with_no_init_and_no_constructor(self):
self._test_init_handler('extendingjava.ExtendJavaLib', None, 0, 0)
-
+
         def test_extended_java_lib_with_no_init_and_contructor(self):
self._test_init_handler('extendingjava.ExtendJavaLibWithConstructor', ['arg'], 1, 3)
-
+
         def test_extended_java_lib_with_init_and_no_constructor(self):
self._test_init_handler('extendingjava.ExtendJavaLibWithInit', [1,2,3], 0, sys.maxint)
-
+
         def test_extended_java_lib_with_init_and_constructor(self):
self._test_init_handler('extendingjava.ExtendJavaLibWithInitAndConstructor', ['arg'], 0, sys.maxint)
-
-
+
+
 class TestVersion(unittest.TestCase):
-
+
     def test_version_of_python_libarary(self):
         self._test_version('classes.VersionLibrary', '0.1')
         self._test_version('classes.VersionObjectLibrary', 'ver')
-
+
     def test_version_with_no_version_info_defined(self):
         self._test_version('classes.NameLibrary', '<unknown>')
-
+
     def test_version_of_module_library(self):
         self._test_version('module_library', 'test')

     def _test_version(self, name, version):
         lib = TestLibrary(name)
         assert_equals(lib.version, version)
-
+
     if utils.is_jython:
-
+
         def test_version_of_java_library(self):
             self._test_version('JavaVersionLibrary', '1.0')
-
+
         def test_version_of_java_library_with_no_version_defined(self):
             self._test_version('ExampleJavaLibrary', '<unknown>')
-
+

 class _TestScopes(unittest.TestCase):
-
+
     def _get_lib_and_instance(self, name):
         lib = TestLibrary(name)
         if lib.scope == 'GLOBAL':
@@ -244,7 +244,7 @@
         else:
             assert_none(lib._libinst)
         return lib, lib._libinst
-
+
     def _start_new_suite(self):
         self.lib.start_suite()
         assert_none(self.lib._libinst)
@@ -258,20 +258,20 @@
         if prev_inst is not None:
             assert_true(self.lib.get_instance() is prev_inst)

-
+
 class GlobalScope(_TestScopes):

     def test_global_scope(self):
         lib, instance = self._get_lib_and_instance('BuiltIn')
- for mname in ['start_suite', 'start_suite', 'start_test', 'end_test',
-                      'start_test', 'end_test', 'end_suite', 'start_suite',
+ for mname in ['start_suite', 'start_suite', 'start_test', 'end_test',
+                      'start_test', 'end_test', 'end_suite', 'start_suite',
                       'start_test', 'end_test', 'end_suite', 'end_suite']:
             getattr(lib, mname)()
             assert_true(instance is lib._libinst)
-
-
+
+
 class TestSuiteScope(_TestScopes):
-
+
     def setUp(self):
self.lib, self.instance = self._get_lib_and_instance("libraryscope.Suite")
         self.lib.start_suite()
@@ -281,7 +281,7 @@
         inst = self.lib.get_instance()
         assert_not_none(inst)
         assert_false(inst is self.instance)
-
+
     def test_start_test_or_end_test_do_not_flush_instance(self):
         inst = self.lib.get_instance()
         for _ in range(10):
@@ -292,13 +292,13 @@
             assert_true(inst is self.lib._libinst)

     def test_end_suite_restores_previous_instance_with_one_suite(self):
-        self.lib.start_test()
+        self.lib.start_test()
         self.lib.get_instance()
-        self.lib.end_test()
+        self.lib.end_test()
         self.lib.get_instance()
         self.lib.end_suite()
         assert_none(self.lib._libinst)
-
+
     def test_intance_caching(self):
         inst1 = self.lib.get_instance()
         inst2 = self._start_new_suite()
@@ -311,28 +311,28 @@
         self._verify_end_suite_restores_previous_instance(inst3)
         self._verify_end_suite_restores_previous_instance(inst1)
         self._verify_end_suite_restores_previous_instance(None)
-
+
     def _run_tests(self, exp_inst, count=3):
         for _ in range(count):
             self.lib.start_test()
             assert_true(self.lib.get_instance() is exp_inst)
             self.lib.end_test()
             assert_true(self.lib.get_instance() is exp_inst)
-
-
+
+
 class TestCaseScope(_TestScopes):
-
+
     def setUp(self):
self.lib, self.instance = self._get_lib_and_instance("libraryscope.Test")
         self.lib.start_suite()
-
+
     def test_different_instances_for_all_tests(self):
         self._run_tests(None)
         inst = self.lib.get_instance()
         self._run_tests(inst, 5)
         self.lib.end_suite()
         assert_none(self.lib._libinst)
-
+
     def test_nested_suites(self):
         top_inst = self.lib.get_instance()
         self._run_tests(top_inst, 4)
@@ -343,7 +343,7 @@
         self.lib.end_suite()
         self.lib.end_suite()
         assert_true(self.lib._libinst is top_inst)
-
+
     def _run_tests(self, suite_inst, count=3):
         old_insts = [suite_inst]
         for _ in range(count):
@@ -355,7 +355,7 @@
             self.lib.end_test()
             assert_true(self.lib._libinst is suite_inst)

-
+
 class TestHandlers(unittest.TestCase):

     def test_get_handlers(self):
@@ -367,7 +367,7 @@
             for handler in handlers:
                 assert_false(handler._handler_name.startswith('_'))
                 assert_equals(handler._handler_name.count('skip'), 0)
-
+
     def test_non_global_dynamic_handlers(self):
         lib = TestLibrary("RunKeywordLibrary")
         assert_equals(len(lib.handlers), 2)
@@ -375,7 +375,7 @@
         assert_true(lib.handlers.has_key('Run Keyword That Fails'))
         assert_none(lib.handlers['Run Keyword That Passes']._method)
         assert_none(lib.handlers['Run Keyword That Fails']._method)
-
+
     def test_global_dynamic_handlers(self):
         lib = TestLibrary("RunKeywordLibrary.GlobalRunKeywordLibrary")
         assert_equals(len(lib.handlers), 2)
@@ -384,7 +384,7 @@
             assert_not_none(handler._method)
             assert_not_equals(handler._method, lib._libinst.run_keyword)
             assert_equals(handler._method.__name__, 'handler')
-
+
     def test_synonym_handlers(self):
         testlib = TestLibrary('classes.SynonymLibrary')
         names = [ 'handler', 'synonym_handler', 'another_synonym' ]
@@ -392,20 +392,20 @@
# test 'handler_name' -- raises ValueError if it isn't in 'names'
             names.remove(handler._handler_name)
assert_equals(len(names), 0, 'handlers %s not created' % names, False)
-
+
     def test_global_handlers_are_created_only_once(self):
         lib = TestLibrary('classes.RecordingLibrary')
         calls_after_init = lib._libinst.calls_to_getattr
-        for _ in range(5):
+        for _ in range(5):
             lib.handlers['kw'].run(_FakeContext(), [])
         assert_equals(lib._libinst.calls_to_getattr, calls_after_init)
-
+
     if utils.is_jython:

         def test_get_java_handlers(self):
-            for lib in [ ArgumentTypes,
+            for lib in [ ArgumentTypes,
                          MultipleArguments,
-                         MultipleSignatures,
+                         MultipleSignatures,
                          NoHandlers,
                          Extended ]:
                 testlib = TestLibrary(lib.__name__)
@@ -417,7 +417,7 @@


 class TestDynamicLibrary(unittest.TestCase):
-
+
     def test_get_keyword_doc_is_used_if_present(self):
         lib = TestLibrary('classes.ArgDocDynamicLibrary')
assert_equals(lib.handlers['No Arg'].doc, 'Keyword documentation for No Arg')
@@ -427,7 +427,7 @@
         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 = TestLibrary('classes.InvalidGetDocDynamicLibrary')
         assert_equals(len(lib.handlers), 0)
@@ -438,25 +438,25 @@

     def test_get_keyword_arguments_is_used_if_present(self):
         lib = TestLibrary('classes.ArgDocDynamicLibrary')
-        for name, exp in [ ('No Arg', ()) , ('One Arg', (1,1)),
+        for name, exp in [ ('No Arg', ()) , ('One Arg', (1,1)),
                            ('One or Two Args', (1, 2)),
                            ('Many Args', (0, sys.maxint))]:
             self._assert_handler_args(lib.handlers[name], *exp)
-
+
     def _assert_handler_args(self, handler, minargs=0, maxargs=0):
assert_equals(handler.arguments._arg_limit_checker.minargs, minargs) assert_equals(handler.arguments._arg_limit_checker.maxargs, maxargs)
-
+
     if utils.is_jython:
         def test_dynamic_java_handlers(self):
             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 One or Two Args', 1, 2),
                                     ('Java Many Args', 0, sys.maxint) ]:
-                self._assert_java_handler(lib.handlers[name],
- 'Keyword documentation for %s' % name,
+                self._assert_java_handler(lib.handlers[name],
+ 'Keyword documentation for %s' % name,
                                           min, max)
-
+
def test_get_keyword_doc_and_args_are_ignored_if_not_callable_in_java(self):
             lib = TestLibrary('InvalidAttributeArgDocDynamicJavaLibrary')
             assert_equals(len(lib.handlers), 1)
@@ -465,12 +465,12 @@
def test_handler_is_not_created_if_get_keyword_doc_fails_in_java(self):
             lib = TestLibrary('InvalidSignatureArgDocDynamicJavaLibrary')
             assert_equals(len(lib.handlers), 0)
-
+
         def _assert_java_handler(self, handler, doc, minargs, maxargs):
             assert_equals(handler.doc, doc)
             self._assert_handler_args(handler, minargs, maxargs)
-
-
+
+
 class _FakeNamespace:
     def __init__(self):
         self.variables = _FakeVariableScope()
@@ -498,7 +498,7 @@
     def __getitem__(self, key):
         return self.variables.get(key)

-
+
 class _FakeOutput:
     def trace(self, str):
         pass
@@ -510,6 +510,7 @@
     def __init__(self):
         self.output = _FakeOutput()
         self.namespace =  _FakeNamespace()
+        self.dry_run = False

     def get_current_vars(self):
         return self.namespace.variables

Reply via email to