def test_variable_sub(): in_str = ''' # comment VAR1 = 3 VAR2 = 4 ''' yield assert_equal, _str_sub(in_str,{}), in_str # test dictionary return in_stream = StringIO(in_str) out_stream = StringIO() context = variable_sub(in_stream, out_stream, {}) yield assert_equal, context, {'VAR1': '3', 'VAR2': '4'} out_str = ''' # comment VAR1 := some string VAR2 = 4 ''' dct = {'VAR1':'some string'} yield assert_equal, _str_sub(in_str, dct), out_str
def _str_sub(in_str, subs): in_stream = StringIO(in_str) out_stream = StringIO() variable_sub(in_stream, out_stream, subs) return out_stream.getvalue()