<s> import unittest <EOL> from robot . errors import DataError <EOL> from robot . model import Keywords <EOL> from robot . running . userkeyword import EmbeddedArgumentsHandler <EOL> from robot . running . arguments import EmbeddedArguments , UserKeywordArgumentParser <EOL> from robot . utils . asserts import assert_equal , assert_true , assert_raises <EOL> class Fake ( object ) : <EOL> value = '<STR_LIT>' <EOL> message = '<STR_LIT>' <EOL> def __iter__ ( self ) : <EOL> return iter ( [ ] ) <EOL> class FakeArgs ( object ) : <EOL> def __init__ ( self , args ) : <EOL> self . value = args <EOL> def __nonzero__ ( self ) : <EOL> return bool ( self . value ) <EOL> def __iter__ ( self ) : <EOL> return iter ( self . value ) <EOL> class HandlerDataMock : <EOL> def __init__ ( self , name , args = [ ] ) : <EOL> self . name = name <EOL> self . args = FakeArgs ( args ) <EOL> self . metadata = { } <EOL> self . keywords = Keywords ( ) <EOL> self . defaults = [ ] <EOL> self . varargs = None <EOL> self . minargs = <NUM_LIT:0> <EOL> self . maxargs = <NUM_LIT:0> <EOL> self . return_value = None <EOL> self . doc = Fake ( ) <EOL> self . timeout = Fake ( ) <EOL> self . return_ = Fake ( ) <EOL> self . tags = ( ) <EOL> self . teardown = None <EOL> def EAT ( name , args = [ ] ) : <EOL> handler = HandlerDataMock ( name , args ) <EOL> embedded = EmbeddedArguments ( name ) <EOL> return EmbeddedArgumentsHandler ( handler , '<STR_LIT>' , embedded ) <EOL> class TestEmbeddedArgs ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . tmp1 = EAT ( '<STR_LIT>' ) <EOL> self . tmp2 = EAT ( '<STR_LIT>' ) <EOL> def test_no_embedded_args ( self ) : <EOL> assert_true ( not EmbeddedArguments ( '<STR_LIT>' ) ) <EOL> assert_true ( EmbeddedArguments ( '<STR_LIT>' ) ) <EOL> def test_get_embedded_arg_and_regexp ( self ) : <EOL> assert_equal ( self . tmp1 . embedded_args , [ '<STR_LIT>' ] ) <EOL> assert_equal ( self . tmp1 . embedded_name . pattern , <EOL> '<STR_LIT>' ) <EOL> assert_equal ( self . tmp1 . name , '<STR_LIT>' ) <EOL> def test_get_multiple_embedded_args_and_regexp ( self ) : <EOL> assert_equal ( self . tmp2 . embedded_args , [ '<STR_LIT:x>' , '<STR_LIT:y>' , '<STR_LIT:z>' ] ) <EOL> assert_equal ( self . tmp2 . embedded_name . pattern , <EOL> '<STR_LIT>' ) <EOL> def test_create_runner_when_no_match ( self ) : <EOL> assert_raises ( ValueError , self . tmp1 . create_runner , '<STR_LIT>' ) <EOL> def test_create_runner_with_one_embedded_arg ( self ) : <EOL> runner = self . tmp1 . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> assert_equal ( runner . name , '<STR_LIT>' ) <EOL> assert_equal ( runner . longname , '<STR_LIT>' ) <EOL> runner = self . tmp1 . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> assert_equal ( runner . name , '<STR_LIT>' ) <EOL> assert_equal ( runner . longname , '<STR_LIT>' ) <EOL> def test_create_runner_with_many_embedded_args ( self ) : <EOL> runner = self . tmp2 . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , <EOL> [ ( '<STR_LIT:x>' , '<STR_LIT>' ) , ( '<STR_LIT:y>' , '<STR_LIT>' ) , ( '<STR_LIT:z>' , '<STR_LIT:list>' ) ] ) <EOL> def test_create_runner_with_empty_embedded_arg ( self ) : <EOL> runner = self . tmp1 . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def test_create_runner_with_special_characters_in_embedded_args ( self ) : <EOL> runner = self . tmp2 . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , <EOL> [ ( '<STR_LIT:x>' , '<STR_LIT>' ) , ( '<STR_LIT:y>' , '<STR_LIT>' ) , ( '<STR_LIT:z>' , '<STR_LIT:">' ) ] ) <EOL> def test_embedded_args_without_separators ( self ) : <EOL> template = EAT ( '<STR_LIT>' ) <EOL> runner = template . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , [ ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> def test_embedded_args_with_separators_in_values ( self ) : <EOL> template = EAT ( '<STR_LIT>' ) <EOL> runner = template . create_runner ( "<STR_LIT>" ) <EOL> assert_equal ( runner . embedded_args , <EOL> [ ( '<STR_LIT>' , "<STR_LIT>" ) , ( '<STR_LIT>' , '<STR_LIT>' ) , ( '<STR_LIT:OK>' , '<STR_LIT>' ) ] ) <EOL> def test_creating_runners_is_case_insensitive ( self ) : <EOL> runner = self . tmp1 . create_runner ( '<STR_LIT>' ) <EOL> assert_equal ( runner . embedded_args , [ ( '<STR_LIT>' , '<STR_LIT>' ) ] ) <EOL> assert_equal ( runner . name , '<STR_LIT>' ) <EOL> assert_equal ( runner . longname , '<STR_LIT>' ) <EOL> class TestGetArgSpec ( unittest . TestCase ) : <EOL> def test_no_args ( self ) : <EOL> self . _verify ( '<STR_LIT>' ) <EOL> def test_one_arg ( self ) : <EOL> self . _verify ( '<STR_LIT>' , [ '<STR_LIT>' , ] ) <EOL> def test_one_vararg ( self ) : <EOL> self . _verify ( '<STR_LIT>' , exp_varargs = '<STR_LIT>' ) <EOL> def test_one_default ( self ) : <EOL> self . _verify ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , [ '<STR_LIT:default>' ] , '<STR_LIT>' ) <EOL> def test_one_empty_default ( self ) : <EOL> self . _verify ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' ] , [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> def test_many_defaults ( self ) : <EOL> self . _verify ( '<STR_LIT>' , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def _verify ( self , in_args , exp_args = [ ] , exp_defaults = [ ] , exp_varargs = None ) : <EOL> argspec = self . _parse ( in_args ) <EOL> assert_equal ( argspec . positional , exp_args ) <EOL> assert_equal ( argspec . defaults , exp_defaults ) <EOL> assert_equal ( argspec . varargs , exp_varargs ) <EOL> def _parse ( self , in_args ) : <EOL> return UserKeywordArgumentParser ( ) . parse ( in_args . split ( ) ) <EOL> def test_many_varargs_raises ( self ) : <EOL> assert_raises ( DataError , self . _parse , '<STR_LIT>' ) <EOL> def test_args_after_varargs_raises ( self ) : <EOL> assert_raises ( DataError , self . _parse , '<STR_LIT>' ) <EOL> def test_get_defaults_before_args_raises ( self ) : <EOL> assert_raises ( DataError , self . _parse , '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
