<s> from __future__ import unicode_literals <EOL> from unittest import TestCase <EOL> from django . template import Context , Engine <EOL> class CallableVariablesTests ( TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . engine = Engine ( ) <EOL> super ( CallableVariablesTests , cls ) . setUpClass ( ) <EOL> def test_callable ( self ) : <EOL> class Doodad ( object ) : <EOL> def __init__ ( self , value ) : <EOL> self . num_calls = <NUM_LIT:0> <EOL> self . value = value <EOL> def __call__ ( self ) : <EOL> self . num_calls += <NUM_LIT:1> <EOL> return { "<STR_LIT>" : self . value } <EOL> my_doodad = Doodad ( <NUM_LIT> ) <EOL> c = Context ( { "<STR_LIT>" : my_doodad } ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( my_doodad . num_calls , <NUM_LIT:1> ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( my_doodad . num_calls , <NUM_LIT:2> ) <EOL> def test_alters_data ( self ) : <EOL> class Doodad ( object ) : <EOL> alters_data = True <EOL> def __init__ ( self , value ) : <EOL> self . num_calls = <NUM_LIT:0> <EOL> self . value = value <EOL> def __call__ ( self ) : <EOL> self . num_calls += <NUM_LIT:1> <EOL> return { "<STR_LIT>" : self . value } <EOL> my_doodad = Doodad ( <NUM_LIT> ) <EOL> c = Context ( { "<STR_LIT>" : my_doodad } ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( my_doodad . num_calls , <NUM_LIT:0> ) <EOL> def test_do_not_call ( self ) : <EOL> class Doodad ( object ) : <EOL> do_not_call_in_templates = True <EOL> def __init__ ( self , value ) : <EOL> self . num_calls = <NUM_LIT:0> <EOL> self . value = value <EOL> def __call__ ( self ) : <EOL> self . num_calls += <NUM_LIT:1> <EOL> return { "<STR_LIT>" : self . value } <EOL> my_doodad = Doodad ( <NUM_LIT> ) <EOL> c = Context ( { "<STR_LIT>" : my_doodad } ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( my_doodad . num_calls , <NUM_LIT:0> ) <EOL> def test_do_not_call_and_alters_data ( self ) : <EOL> class Doodad ( object ) : <EOL> do_not_call_in_templates = True <EOL> alters_data = True <EOL> def __init__ ( self , value ) : <EOL> self . num_calls = <NUM_LIT:0> <EOL> self . value = value <EOL> def __call__ ( self ) : <EOL> self . num_calls += <NUM_LIT:1> <EOL> return { "<STR_LIT>" : self . value } <EOL> my_doodad = Doodad ( <NUM_LIT> ) <EOL> c = Context ( { "<STR_LIT>" : my_doodad } ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> t = self . engine . from_string ( '<STR_LIT>' ) <EOL> self . assertEqual ( t . render ( c ) , '<STR_LIT>' ) <EOL> self . assertEqual ( my_doodad . num_calls , <NUM_LIT:0> ) </s>
