def test_should_print_macro_content(self): with closing( io.StringIO( "{% macro name(firstname, lastname) %}{{ firstname }} {{ lastname }}{% endmacro %}" "{{name('Jon', 'Smith')}}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Jon Smith', output)
def test_should_print_results_from_elif_statement(self): with closing( io.StringIO( '{% if False %}Hello{% elif True %}World{% endif %}') ) as input_stream: output = parse(input_stream) self.assertEqual('World', output)
def test_should_concatenate_values_from_csv_file(self): with closing( io.StringIO( "{{ model[0]['firstname'] + ' ' + model[0]['lastname'] }}") ) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Brad Smith', output)
def test_should_print_values_from_csv_file_in_a_loop(self): with closing( io.StringIO( "{% for value in model %}{{ value['firstname'] + ' ' }}{% endfor %}" )) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Brad Will Jennifer ', output)
def test_should_print_value_from_local_scope(self): with closing(io.StringIO("{% set firstname = 'Adam' %}" "{% macro name(firstname) %}" "{{ firstname }}" "{% endmacro %}" "{{ name('Tom') }} " "{{ firstname }}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Tom Adam', output)
def test_should_print_value_from_local_scope(self): with closing( io.StringIO("{% set firstname = 'Adam' %}" "{% macro name(firstname) %}" "{{ firstname }}" "{% endmacro %}" "{{ name('Tom') }} " "{{ firstname }}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Tom Adam', output)
def test_should_check_if_char_is_not_in_string(self): with closing(io.StringIO('{{ not "a" in "str"}}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_conjunct_boolean_expression(self): with closing(io.StringIO('{{ True and False }}')) as input_stream: output = parse(input_stream) self.assertEqual('False', output)
def test_should_conjunct_complex_boolean_expression2(self): with closing(io.StringIO( '{{ 2 and (False or not False) and True}}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_multiply_numbers_and_convert_to_float(self): with closing(io.StringIO('{{ 2 * -3.0 }}')) as input_stream: output = parse(input_stream) self.assertEqual('-6.0', output)
def test_should_multiply_booleans(self): with closing(io.StringIO('{{ 4 * True }}')) as input_stream: output = parse(input_stream) self.assertEqual('4', output)
def test_should_print_value_defined_in_set_statement(self): with closing(io.StringIO( "{% set value = 123 %}{{ value }}")) as input_stream: output = parse(input_stream) self.assertEqual('123', output)
def test_should_accept_inverted_indexing(self): with closing(io.StringIO("{{ model[-1]['age'] }}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('17', output)
def test_should_add_values_from_csv_file(self): with closing(io.StringIO("{{ model[0]['age'] + model[1]['age'] }}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('76', output)
def test_should_concatenate_values_from_csv_file(self): with closing(io.StringIO("{{ model[0]['firstname'] + ' ' + model[0]['lastname'] }}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Brad Smith', output)
def test_should_print_results_from_elif_statement(self): with closing(io.StringIO('{% if False %}Hello{% elif True %}World{% endif %}')) as input_stream: output = parse(input_stream) self.assertEqual('World', output)
def test_should_print_value_defined_in_set_statement(self): with closing(io.StringIO("{% set value = 123 %}{{ value }}")) as input_stream: output = parse(input_stream) self.assertEqual('123', output)
def test_should_not_print_results_from_if_statement(self): with closing(io.StringIO('{% if 5 < 3 %}Hello World{% endif %}')) as input_stream: output = parse(input_stream) self.assertEqual('', output)
def test_should_compare_arithmetic_results(self): with closing(io.StringIO('{{ 2 * 3 >= 6 and 2 < 6 }}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_compare_integers4(self): with closing(io.StringIO('{{ 2 != 2 }}')) as input_stream: output = parse(input_stream) self.assertEqual('False', output)
def test_should_not_print_results_from_if_statement(self): with closing(io.StringIO( '{% if 5 < 3 %}Hello World{% endif %}')) as input_stream: output = parse(input_stream) self.assertEqual('', output)
def test_should_generate_empty_string(self): with closing(io.StringIO('')) as input_stream: output = parse(input_stream) self.assertEqual('', output)
def test_should_add_values_from_csv_file(self): with closing(io.StringIO( "{{ model[0]['age'] + model[1]['age'] }}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('76', output)
def test_should_print_values_from_csv_file_in_a_loop(self): with closing(io.StringIO("{% for value in model %}{{ value['firstname'] + ' ' }}{% endfor %}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Brad Will Jennifer ', output)
def test_should_compare_integers1(self): with closing(io.StringIO('{{ 5 > 3 }}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_print_macro_content(self): with closing(io.StringIO("{% macro name(firstname, lastname) %}{{ firstname }} {{ lastname }}{% endmacro %}" "{{name('Jon', 'Smith')}}")) as input_stream: output = parse(input_stream, self.MODEL_FILE) self.assertEqual('Jon Smith', output)
def test_should_calculate_modulo(self): with closing(io.StringIO('{{7 % 3}}')) as input_stream: output = parse(input_stream) self.assertEqual('1', output)
def test_should_return_string_from_boolean_expression(self): with closing(io.StringIO('{{ False or "str"}}')) as input_stream: output = parse(input_stream) self.assertEqual('str', output)
def test_should_generate_simple_html(self): with closing(io.StringIO('<span>Hello World</span>')) as input_stream: output = parse(input_stream) self.assertEqual('<span>Hello World</span>', output)
def test_should_alternate_boolean_expression(self): with closing(io.StringIO('{{ True or False }}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_omit_comment(self): with closing(io.StringIO('{# comment #}')) as input_stream: output = parse(input_stream) self.assertEqual('', output)
def test_should_delete_comment_from_simple_html(self): with closing(io.StringIO('<span>Hello {# comment #}World</span>')) as input_stream: output = parse(input_stream) self.assertEqual('<span>Hello World</span>', output)
def test_should_add_numbers(self): with closing(io.StringIO('{{ 2 + 3 }}')) as input_stream: output = parse(input_stream) self.assertEqual('5', output)
def test_should_compare_arithmetic_results(self): with closing( io.StringIO('{{ 2 * 3 >= 6 and 2 < 6 }}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_conjunct_complex_boolean_expression2(self): with closing(io.StringIO('{{ 2 and (False or not False) and True}}')) as input_stream: output = parse(input_stream) self.assertEqual('True', output)
def test_should_delete_comment_from_simple_html(self): with closing(io.StringIO( '<span>Hello {# comment #}World</span>')) as input_stream: output = parse(input_stream) self.assertEqual('<span>Hello World</span>', output)
def test_should_subtract_numbers(self): with closing(io.StringIO('{{ 2 - 3 }}')) as input_stream: output = parse(input_stream) self.assertEqual('-1', output)
def test_should_multiply_numbers(self): with closing(io.StringIO('{{ 2 * 3 }}')) as input_stream: output = parse(input_stream) self.assertEqual('6', output)
def test_should_divide_numbers(self): with closing(io.StringIO('{{ 8 / 2 }}')) as input_stream: output = parse(input_stream) self.assertEqual('4.0', output)
def test_should_calculate_result_in_brackets(self): with closing(io.StringIO('{{ ((8 / 2) + (2) * 3) + 7 % 3}}')) as input_stream: output = parse(input_stream) self.assertEqual('11.0', output)
def test_should_add_booleans(self): with closing(io.StringIO('{{ True + False }}')) as input_stream: output = parse(input_stream) self.assertEqual('1', output)
def test_should_calculate_result_in_brackets(self): with closing(io.StringIO( '{{ ((8 / 2) + (2) * 3) + 7 % 3}}')) as input_stream: output = parse(input_stream) self.assertEqual('11.0', output)