def test_import_python_module_from_module(self): lib = TestLibrary("pythonmodule.library") self._verify_lib(lib, "pythonmodule.library", [("keyword from submodule", None)])
def setUp(self): self.lib = TestLibrary('ArgTypeCoercion', ['42', 'true'])
def test_failure_in_dynamic_resolving_of_doc(self): init = TestLibrary('dynlibs.FailingDynamicDocLib').init assert_raises(DataError, getattr, init, 'doc')
def test_import_python_class_from_module(self): lib = TestLibrary("BuiltIn.BuiltIn") self._verify_lib(lib, "BuiltIn.BuiltIn", default_keywords)
def test_dynamic_python_library(self): lib = TestLibrary("RunKeywordLibrary") assert_equals(lib.__class__, _DynamicLibrary)
def test_handler_is_not_created_if_get_keyword_doc_fails(self): lib = TestLibrary('InvalidSignatureArgDocDynamicJavaLibrary') assert_equals(len(lib.handlers), 0)
def test_set_test_scope_java(self): lib = TestLibrary('javalibraryscope.Test') assert_equals(lib.scope, 'TESTCASE')
def test_get_keyword_doc_and_args_are_ignored_if_not_callable(self): lib = TestLibrary('classes.InvalidAttributeDynamicLibrary') assert_equals(len(lib.handlers), 5) assert_equals(lib.handlers['No Arg'].doc, '') assert_handler_args(lib.handlers['No Arg'], 0, sys.maxint)
def test_set_global_scope_java(self): lib = TestLibrary('javalibraryscope.Global') assert_equals(lib.scope, 'GLOBAL')
def test_set_suite_scope_java(self): lib = TestLibrary('javalibraryscope.Suite') assert_equals(lib.scope, 'TESTSUITE')
def test_import_java_with_dots(self): lib = TestLibrary("javapkg.JavaPackageExample") self._verify_lib(lib, "javapkg.JavaPackageExample", java_keywords)
def test_import_java(self): lib = TestLibrary("ExampleJavaLibrary") self._verify_lib(lib, "ExampleJavaLibrary", java_keywords)
def test_set_test_scope(self): assert_equals(TestLibrary('libraryscope.Test').scope, 'TESTCASE')
class TestArgumentCoercer(unittest.TestCase): def setUp(self): self.lib = TestLibrary('ArgTypeCoercion', ['42', 'true']) def test_coercion_in_constructor(self): instance = self.lib.get_instance() assert_equals(instance.myInt, 42) assert_equals(instance.myBool, True) def test_coercing_to_integer(self): self._test_coercion(self._handler_named('intArgument'), ['1'], [1]) def test_coercing_to_boolean(self): handler = self._handler_named('booleanArgument') self._test_coercion(handler, ['True'], [True]) self._test_coercion(handler, ['FALSE'], [ False]) def test_coercing_to_real_number(self): self._test_coercion(self._handler_named('doubleArgument'), ['1.42'], [1.42]) self._test_coercion(self._handler_named('floatArgument'), ['-9991.098'], [-9991.098]) def test_coercion_with_compatible_types(self): self._test_coercion(self._handler_named('coercableKeywordWithCompatibleTypes'), ['9999', '-42', 'FaLsE', '31.31'], [9999, -42, False, 31.31]) def test_arguments_that_are_not_strings_are_not_coerced(self): self._test_coercion(self._handler_named('intArgument'), [self.lib], [self.lib]) self._test_coercion(self._handler_named('booleanArgument'), [42], [42]) def test_coercion_fails_with_reasonable_message(self): exp_msg = 'Argument at position 1 cannot be coerced to %s.' self._test_coercion_fails(self._handler_named('intArgument'), exp_msg % 'integer') self._test_coercion_fails(self._handler_named('booleanArgument'), exp_msg % 'boolean') self._test_coercion_fails(self._handler_named('floatArgument'), exp_msg % 'floating point number') def test_no_arg_no_coercion(self): self._test_coercion(self._handler_named('noArgument'), [], []) def test_coercing_multiple_arguments(self): self._test_coercion(self._handler_named('coercableKeyword'), ['10.0', '42', 'tRUe'], [10.0, 42, True]) def test_coercion_is_not_done_with_conflicting_signatures(self): self._test_coercion(self._handler_named('unCoercableKeyword'), ['True', '42'], ['True', '42']) def test_coercable_and_uncoercable_args_in_same_kw(self): self._test_coercion(self._handler_named('coercableAndUnCoercableArgs'), ['1', 'False', '-23', '0'], ['1', False, -23, '0']) def _handler_named(self, name): return self.lib.handlers[name] def _test_coercion(self, handler, args, expected): assert_equals(handler._arg_coercer.coerce(args, {}), expected) def _test_coercion_fails(self, handler, expected_message): assert_raises_with_msg(ValueError, expected_message, handler._arg_coercer.coerce, ['invalid'], {})
def _test_init_handler(self, libname, args=None, min=0, max=0): lib = TestLibrary(libname, args) assert_equals(lib.init.arguments.minargs, min) assert_equals(lib.init.arguments.maxargs, max) return lib
def test_set_suite_scope(self): assert_equals(TestLibrary('libraryscope.Suite').scope, 'TESTSUITE')
def _verify_version(self, name, version): assert_equals(TestLibrary(name).version, version)
def test_handler_is_not_created_if_get_keyword_args_fails(self): lib = TestLibrary('classes.InvalidGetArgsDynamicLibrary') assert_equals(len(lib.handlers), 0)
def _verify_doc_format(self, name, doc_format): assert_equals(TestLibrary(name).doc_format, doc_format)
def test_get_keyword_doc_and_args_are_ignored_if_not_callable(self): lib = TestLibrary('InvalidAttributeArgDocDynamicJavaLibrary') assert_equals(len(lib.handlers), 1) assert_handler_args(lib.handlers['keyword'], 0, sys.maxint)
def test_python_library(self): lib = TestLibrary("BuiltIn") assert_equals(lib.__class__, _ClassLibrary) assert_equals(lib.positional_args, [])
def test_java_library(self): lib = TestLibrary("ExampleJavaLibrary") assert_equals(lib.__class__, _ClassLibrary)
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 _assert_init_doc(self, library_name, expected_doc): assert_equals(TestLibrary(library_name).init.doc, expected_doc)
def test_module_library(self): lib = TestLibrary("module_library") assert_equals(lib.__class__, _ModuleLibrary)
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_overridden_getName(self): handlers = TestLibrary('OverrideGetName').handlers assert_equals(sorted(handler.name for handler in handlers), ['Do Nothing', 'Get Name'])
class TestArgumentCoercer(unittest.TestCase): def setUp(self): self.lib = TestLibrary('ArgTypeCoercion', ['42', 'true']) def test_coercion_in_constructor(self): instance = self.lib.get_instance() assert_equal(instance.myInt, 42) assert_equal(instance.myBool, True) def test_coercing_to_integer(self): self._test_coercion(self._handler_named('intArgument'), ['1'], [1]) def test_coercing_to_boolean(self): handler = self._handler_named('booleanArgument') self._test_coercion(handler, ['True'], [True]) self._test_coercion(handler, ['FALSE'], [False]) def test_coercing_to_real_number(self): self._test_coercion(self._handler_named('doubleArgument'), ['1.42'], [1.42]) self._test_coercion(self._handler_named('floatArgument'), ['-9991.098'], [-9991.098]) def test_coercion_with_compatible_types(self): self._test_coercion( self._handler_named('coercableKeywordWithCompatibleTypes'), ['9999', '-42', 'FaLsE', '31.31'], [9999, -42, False, 31.31]) def test_arguments_that_are_not_strings_are_not_coerced(self): self._test_coercion(self._handler_named('intArgument'), [self.lib], [self.lib]) self._test_coercion(self._handler_named('booleanArgument'), [42], [42]) def test_coercion_fails_with_reasonable_message(self): exp_msg = 'Argument at position 1 cannot be coerced to %s.' self._test_coercion_fails(self._handler_named('intArgument'), exp_msg % 'integer') self._test_coercion_fails(self._handler_named('booleanArgument'), exp_msg % 'boolean') self._test_coercion_fails(self._handler_named('floatArgument'), exp_msg % 'floating point number') def test_no_arg_no_coercion(self): self._test_coercion(self._handler_named('noArgument'), [], []) def test_coercing_multiple_arguments(self): self._test_coercion(self._handler_named('coercableKeyword'), ['10.0', '42', 'tRUe'], [10.0, 42, True]) def test_coercion_is_not_done_with_conflicting_signatures(self): self._test_coercion(self._handler_named('unCoercableKeyword'), ['True', '42'], ['True', '42']) def test_coercable_and_uncoercable_args_in_same_kw(self): self._test_coercion( self._handler_named('coercableAndUnCoercableArgs'), ['1', 'False', '-23', '0'], ['1', False, -23, '0']) def _handler_named(self, name): return self.lib.handlers[name] def _test_coercion(self, handler, args, expected): assert_equal(handler._arg_coercer.coerce(args, {}), expected) def _test_coercion_fails(self, handler, expected_message): assert_raises_with_msg(ValueError, expected_message, handler._arg_coercer.coerce, ['invalid'], {})
def test_extending_java_lib_in_python(self): handlers = TestLibrary('extendingjava.ExtendJavaLib').handlers assert_equals(len(handlers), 25) for handler in 'kw_in_java_extender', 'javaSleep', 'divByZero': assert_true(handler in handlers)
def test_overridden_getName(self): handlers = TestLibrary('OverrideGetName').handlers assert_equals(sorted(handlers.keys()), ['doNothing', 'getName'])
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')
def test_set_global_scope(self): assert_equals(TestLibrary('libraryscope.Global').scope, 'GLOBAL')