<s> """<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> from google . apputils import basetest <EOL> from googleapis . codegen import data_types <EOL> from googleapis . codegen import data_value <EOL> from googleapis . codegen import language_model <EOL> from googleapis . codegen . template_objects import CodeObject <EOL> class LanguageModelTest ( basetest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . language_model = language_model . LanguageModel ( ) <EOL> def _CreateDataValue ( self , value , val_type ) : <EOL> def_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:type>' : val_type , <EOL> } <EOL> prototype = data_types . DataType ( <EOL> def_dict , None , language_model = self . language_model ) <EOL> dv = data_value . DataValue ( value , prototype ) <EOL> return dv <EOL> def testConstructor ( self ) : <EOL> foo = self . language_model <EOL> bar = language_model . LanguageModel ( ) <EOL> self . assertEqual ( <EOL> foo . _SUPPORTED_TYPES . keys ( ) , bar . _SUPPORTED_TYPES . keys ( ) ) <EOL> foo . _SUPPORTED_TYPES [ '<STR_LIT:bar>' ] = '<STR_LIT:foo>' <EOL> self . assertNotEqual ( <EOL> foo . _SUPPORTED_TYPES . keys ( ) , bar . _SUPPORTED_TYPES . keys ( ) ) <EOL> def testRenderInteger ( self ) : <EOL> dv = self . _CreateDataValue ( <NUM_LIT> , '<STR_LIT>' ) <EOL> render_method = self . language_model . _SUPPORTED_TYPES [ '<STR_LIT>' ] <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( dv ) ) <EOL> dv . SetValue ( '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , render_method , dv ) <EOL> def testRenderFloat ( self ) : <EOL> dv = self . _CreateDataValue ( <NUM_LIT> , '<STR_LIT>' ) <EOL> render_method = self . language_model . _SUPPORTED_TYPES [ '<STR_LIT>' ] <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( dv ) ) <EOL> dv . SetValue ( <NUM_LIT:4> ) <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( dv ) ) <EOL> dv . SetValue ( '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , render_method , dv ) <EOL> dv . SetValue ( float ( '<STR_LIT>' ) ) <EOL> self . assertRaises ( ValueError , render_method , dv ) <EOL> def testRenderString ( self ) : <EOL> dv = self . _CreateDataValue ( '<STR_LIT:foo>' , '<STR_LIT:string>' ) <EOL> render_method = self . language_model . _SUPPORTED_TYPES [ '<STR_LIT:string>' ] <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( dv ) ) <EOL> dv . SetValue ( '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( dv ) ) <EOL> def testRenderDataValue ( self ) : <EOL> render_method = self . language_model . RenderDataValue <EOL> string_dv = self . _CreateDataValue ( '<STR_LIT>' , '<STR_LIT:string>' ) <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( string_dv ) ) <EOL> integer_dv = self . _CreateDataValue ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( integer_dv ) ) <EOL> float_dv = self . _CreateDataValue ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , render_method ( float_dv ) ) <EOL> float_dv = self . _CreateDataValue ( <NUM_LIT> , '<STR_LIT>' ) <EOL> self . assertRaises ( ValueError , render_method , float_dv ) <EOL> class LanguagePolicyTest ( basetest . TestCase ) : <EOL> def testApplyCaseTransform ( self ) : <EOL> class TestLanguageModel ( language_model . LanguageModel ) : <EOL> allowed_characters = '<STR_LIT:#>' <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( TestLanguageModel , self ) . __init__ ( ** kwargs ) <EOL> m = TestLanguageModel ( ) <EOL> s = '<STR_LIT>' <EOL> p = language_model . NamingPolicy ( case_transform = language_model . LOWER_CASE ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . PRESERVE_CASE , <EOL> separator = '<STR_LIT:_>' ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CASE , <EOL> separator = '<STR_LIT:_>' ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . LOWER_CASE , <EOL> separator = '<STR_LIT:_>' ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . LOWER_CAMEL_CASE ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE ) <EOL> s = '<STR_LIT>' <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( s , p ) ) <EOL> def testApplyFormat ( self ) : <EOL> class TestLanguageModel ( language_model . LanguageModel ) : <EOL> allowed_characters = '<STR_LIT:#>' <EOL> member_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE , <EOL> format_string = '<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( TestLanguageModel , self ) . __init__ ( ** kwargs ) <EOL> m = TestLanguageModel ( ) <EOL> api = CodeObject ( { '<STR_LIT:name>' : '<STR_LIT>' } , None , wire_name = '<STR_LIT>' ) <EOL> schema = CodeObject ( { '<STR_LIT:name>' : '<STR_LIT>' } , api , wire_name = '<STR_LIT>' , <EOL> parent = api ) <EOL> member = CodeObject ( { '<STR_LIT:name>' : '<STR_LIT:object>' } , api , parent = schema ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyFormat ( member , '<STR_LIT>' , m . member_policy ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyPolicy ( '<STR_LIT>' , member , '<STR_LIT>' ) ) <EOL> def testPoliciesGetUsedInTheRightMethods1 ( self ) : <EOL> class TestLanguageModel ( language_model . LanguageModel ) : <EOL> class_name_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE , <EOL> separator = '<STR_LIT>' , <EOL> format_string = '<STR_LIT>' ) <EOL> constant_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CASE , <EOL> separator = '<STR_LIT>' , <EOL> format_string = '<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( TestLanguageModel , self ) . __init__ ( ** kwargs ) <EOL> m = TestLanguageModel ( ) <EOL> max_results = '<STR_LIT>' <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyPolicy ( '<STR_LIT>' , None , max_results ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyPolicy ( '<STR_LIT>' , None , max_results ) ) <EOL> def testPoliciesGetUsedInTheRightMethods2 ( self ) : <EOL> class TestLanguageModel ( language_model . LanguageModel ) : <EOL> member_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . LOWER_CASE , <EOL> separator = '<STR_LIT>' , <EOL> format_string = '<STR_LIT>' ) <EOL> getter_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . LOWER_CAMEL_CASE , <EOL> separator = '<STR_LIT>' , <EOL> format_string = '<STR_LIT>' ) <EOL> setter_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE , <EOL> separator = '<STR_LIT>' , <EOL> format_string = '<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( TestLanguageModel , self ) . __init__ ( ** kwargs ) <EOL> m = TestLanguageModel ( ) <EOL> max_results = '<STR_LIT>' <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyPolicy ( '<STR_LIT>' , None , max_results ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyPolicy ( '<STR_LIT>' , None , max_results ) ) <EOL> self . assertEquals ( '<STR_LIT>' , <EOL> m . ApplyPolicy ( '<STR_LIT>' , None , max_results ) ) <EOL> def testArrayOf ( self ) : <EOL> class TestLanguageModel ( language_model . LanguageModel ) : <EOL> array_of_policy = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE , <EOL> separator = '<STR_LIT>' , <EOL> format_string = '<STR_LIT>' ) <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( TestLanguageModel , self ) . __init__ ( ** kwargs ) <EOL> m = TestLanguageModel ( ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ArrayOf ( None , '<STR_LIT>' ) ) <EOL> def testAtSignPolicy ( self ) : <EOL> class TestLanguageModel ( language_model . LanguageModel ) : <EOL> allowed_characters = '<STR_LIT:#>' <EOL> def __init__ ( self , ** kwargs ) : <EOL> super ( TestLanguageModel , self ) . __init__ ( ** kwargs ) <EOL> m = TestLanguageModel ( ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( '<STR_LIT>' , p ) ) <EOL> self . assertEquals ( '<STR_LIT:Name>' , m . ApplyCaseTransform ( '<STR_LIT>' , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE , <EOL> atsign_policy = language_model . ATSIGN_STRIP ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( '<STR_LIT>' , p ) ) <EOL> self . assertEquals ( '<STR_LIT:Name>' , m . ApplyCaseTransform ( '<STR_LIT>' , p ) ) <EOL> p = language_model . NamingPolicy ( <EOL> case_transform = language_model . UPPER_CAMEL_CASE , <EOL> atsign_policy = language_model . ATSIGN_BREAK ) <EOL> self . assertEquals ( '<STR_LIT>' , m . ApplyCaseTransform ( '<STR_LIT>' , p ) ) <EOL> self . assertEquals ( '<STR_LIT:Name>' , m . ApplyCaseTransform ( '<STR_LIT>' , p ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> basetest . main ( ) </s>
