<s> import unittest <EOL> from . import binding <EOL> from . binding import Context <EOL> def count_gen ( ) : <EOL> val = <NUM_LIT:1> <EOL> while ( True ) : <EOL> yield val <EOL> val += <NUM_LIT:1> <EOL> """<STR_LIT>""" <EOL> class BindingTest ( unittest . TestCase ) : <EOL> def test_variables ( self ) : <EOL> """<STR_LIT>""" <EOL> context = Context ( ) <EOL> self . assertTrue ( context . get_value ( '<STR_LIT:foo>' ) is None ) <EOL> self . assertEqual ( <NUM_LIT:0> , context . mod_count ) <EOL> context . bind_variable ( '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , context . get_value ( '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( '<STR_LIT:bar>' , context . get_values ( ) [ '<STR_LIT:foo>' ] ) <EOL> self . assertEqual ( <NUM_LIT:1> , context . mod_count ) <EOL> context . bind_variable ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . assertEqual ( '<STR_LIT>' , context . get_value ( '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , context . mod_count ) <EOL> def test_generator ( self ) : <EOL> """<STR_LIT>""" <EOL> context = Context ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( context . get_generators ( ) ) ) <EOL> my_gen = count_gen ( ) <EOL> context . add_generator ( '<STR_LIT>' , my_gen ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( context . get_generators ( ) ) ) <EOL> self . assertTrue ( '<STR_LIT>' in context . get_generators ( ) ) <EOL> self . assertTrue ( context . get_generator ( '<STR_LIT>' ) is not None ) <EOL> def test_generator_bind ( self ) : <EOL> """<STR_LIT>""" <EOL> context = Context ( ) <EOL> self . assertEqual ( <NUM_LIT:0> , len ( context . get_generators ( ) ) ) <EOL> my_gen = count_gen ( ) <EOL> context . add_generator ( '<STR_LIT>' , my_gen ) <EOL> context . bind_generator_next ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , context . mod_count ) <EOL> self . assertEqual ( <NUM_LIT:1> , context . get_value ( '<STR_LIT:foo>' ) ) <EOL> self . assertTrue ( <NUM_LIT:2> , next ( context . get_generator ( '<STR_LIT>' ) ) ) <EOL> self . assertTrue ( <NUM_LIT:3> , next ( my_gen ) ) <EOL> def test_mixing_binds ( self ) : <EOL> """<STR_LIT>""" <EOL> context = Context ( ) <EOL> context . add_generator ( '<STR_LIT>' , count_gen ( ) ) <EOL> context . bind_variable ( '<STR_LIT:foo>' , '<STR_LIT:100>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , context . mod_count ) <EOL> context . bind_generator_next ( '<STR_LIT:foo>' , '<STR_LIT>' ) <EOL> self . assertEqual ( <NUM_LIT:1> , context . get_value ( '<STR_LIT:foo>' ) ) <EOL> self . assertEqual ( <NUM_LIT:2> , context . mod_count ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
