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)
示例#10
0
 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)
示例#11
0
 def test_should_multiply_booleans(self):
     with closing(io.StringIO('{{ 4 * True }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('4', output)
示例#12
0
 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)
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
 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)
示例#16
0
 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)
示例#17
0
 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)
示例#18
0
 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)
示例#19
0
 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)
示例#20
0
 def test_should_compare_integers4(self):
     with closing(io.StringIO('{{ 2 != 2 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('False', output)
示例#21
0
 def test_should_compare_integers4(self):
     with closing(io.StringIO('{{ 2 != 2 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('False', output)
示例#22
0
 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)
示例#23
0
 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)
示例#24
0
 def test_should_generate_empty_string(self):
     with closing(io.StringIO('')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('', output)
示例#25
0
 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)
示例#26
0
 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)
示例#27
0
 def test_should_compare_integers1(self):
     with closing(io.StringIO('{{ 5 > 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('True', output)
示例#28
0
 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)
示例#29
0
 def test_should_calculate_modulo(self):
     with closing(io.StringIO('{{7 % 3}}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('1', output)
示例#30
0
 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)
示例#31
0
 def test_should_multiply_booleans(self):
     with closing(io.StringIO('{{ 4 * True }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('4', output)
示例#32
0
 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)
示例#33
0
 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)
示例#34
0
 def test_should_omit_comment(self):
     with closing(io.StringIO('{# comment #}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('', output)
示例#35
0
 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)
示例#36
0
 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)
示例#37
0
 def test_should_compare_integers1(self):
     with closing(io.StringIO('{{ 5 > 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('True', output)
示例#38
0
 def test_should_add_numbers(self):
     with closing(io.StringIO('{{ 2 + 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('5', output)
示例#39
0
 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)
示例#40
0
 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)
示例#41
0
 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)
示例#42
0
 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)
示例#43
0
 def test_should_generate_empty_string(self):
     with closing(io.StringIO('')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('', output)
示例#44
0
 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)
示例#45
0
 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)
示例#46
0
 def test_should_subtract_numbers(self):
     with closing(io.StringIO('{{ 2 - 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('-1', output)
示例#47
0
 def test_should_subtract_numbers(self):
     with closing(io.StringIO('{{ 2 - 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('-1', output)
示例#48
0
 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)
示例#49
0
 def test_should_multiply_numbers(self):
     with closing(io.StringIO('{{ 2 * 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('6', output)
示例#50
0
 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)
示例#51
0
 def test_should_omit_comment(self):
     with closing(io.StringIO('{# comment #}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('', output)
示例#52
0
 def test_should_divide_numbers(self):
     with closing(io.StringIO('{{ 8 / 2 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('4.0', output)
示例#53
0
 def test_should_add_numbers(self):
     with closing(io.StringIO('{{ 2 + 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('5', output)
示例#54
0
 def test_should_calculate_modulo(self):
     with closing(io.StringIO('{{7 % 3}}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('1', output)
示例#55
0
 def test_should_multiply_numbers(self):
     with closing(io.StringIO('{{ 2 * 3 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('6', output)
示例#56
0
 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)
示例#57
0
 def test_should_divide_numbers(self):
     with closing(io.StringIO('{{ 8 / 2 }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('4.0', output)
示例#58
0
 def test_should_add_booleans(self):
     with closing(io.StringIO('{{ True + False }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('1', output)
示例#59
0
 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)
示例#60
0
 def test_should_add_booleans(self):
     with closing(io.StringIO('{{ True + False }}')) as input_stream:
         output = parse(input_stream)
         self.assertEqual('1', output)