コード例 #1
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)
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
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)
コード例 #8
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)
コード例 #9
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)
コード例 #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)