def test_Must_provide_nonempty_variable_name_in_var(): env = PepEnvironment( PepCppRenderer() ) add_builtins( env ) definit = PepDefInit( ( ( PepSymbol( "MyClass" ), PepSymbol( 'self' ) ), ), ( ( PepVar( ( PepInit( PepSymbol( "int" ), PepSymbol( "self." ), PepInt( 0 ) ), ) ), ) ), ) exception_caught = False try: definit.get_member_variables( env ) except PepUserErrorException, e: exception_caught = True assert_contains( str( e ), "You must provide a variable name, not just 'self.'" )
def test_Not_allowed_non_self_inits_in_var(): env = PepEnvironment( PepCppRenderer() ) add_builtins( env ) definit = PepDefInit( ( ( PepSymbol( "MyClass" ), PepSymbol( 'barself' ) ), ), ( ( PepVar( ( PepInit( PepSymbol( "int" ), PepSymbol( "my_var" ), PepInt( 0 ) ), ) ), ) ), ) exception_caught = False try: definit.get_member_variables( env ) except PepUserErrorException, e: exception_caught = True assert_contains( str( e ), "'my_var' does not start with 'barself.'" )
def Cannot_overwrite_method_with_member_variable__test(): env = PepEnvironment( PepCppRenderer() ) add_builtins( env ) decl = PepClass( name=PepSymbol( "MyClass" ), base_classes=(), body_stmts=( PepDefInit( ( ( PepSymbol( "MyClass" ), PepSymbol( 'self' ) ), ), ( ( PepVar( ( PepInit( PepSymbol( "int" ), PepSymbol( "self.my_meth" ), PepInt( "3" ) ), ) ), ) ), ), PepDef( PepSymbol( "void" ), PepSymbol( "my_meth" ), ( ( PepSymbol( "MyClass" ), PepSymbol( 'self' ) ), ), ( PepPass(), ), ), ) ) assert_equal( "", render_evald( decl, env ) ) exception_caught = False try: make_instance = PepInit( PepSymbol( "MyClass" ), PepSymbol( "my_instance" ), PepFunctionCall( PepSymbol( "MyClass.init" ), () ) ) render_evald( make_instance, env ) except PepUserErrorException, e: exception_caught = True assert_contains( str( e ), "Namespace already contains the name 'my_meth'" )