pystache.tests.test_renderengine module

Unit tests of renderengine.py.

class pystache.tests.test_renderengine.RenderEngineTestCase(methodName='runTest')[source]

Bases: TestCase

Test the RenderEngine class.

test_init()[source]

Test that __init__() stores all of the arguments correctly.

class pystache.tests.test_renderengine.RenderTests(methodName='runTest')[source]

Bases: TestCase, AssertStringMixin, AssertExceptionMixin

Tests RenderEngine.render().

Explicit spec-test-like tests best go in this class since the RenderEngine class contains all parsing logic. This way, the unit tests will be more focused and fail “closer to the code”.

test__escape()[source]

Test that render() uses the escape attribute.

test__escape_does_not_call_literal()[source]

Test that render() does not call literal before or after calling escape.

test__escape_preserves_unicode_subclasses()[source]

Test that render() preserves unicode subclasses when passing to escape.

This is useful, for example, if one wants to respect whether a variable value is markupsafe.Markup when escaping.

test__literal()[source]

Test that render() uses the literal attribute.

test__non_basestring__literal_and_escaped()[source]

Test a context value that is not a basestring instance.

test__resolve_partial()[source]

Test that render() uses the load_template attribute.

test_comment__multiline()[source]

Check that multiline comments are permitted.

test_custom_delimiters__not_retroactive()[source]

Check that changing custom delimiters back is not “retroactive.”

Test case for issue #35: https://github.com/defunkt/pystache/issues/35

test_custom_delimiters__sections()[source]

Check that custom delimiters can be used to start a section.

Test case for issue #20: https://github.com/defunkt/pystache/issues/20

test_dot_notation()[source]

Test simple dot notation cases.

Check that we can use dot notation when the variable is a dict, user-defined object, or combination of both.

Test that dotted name resolution terminates on a later part not found.

Check that if a later dotted name part is not found in the result from the former resolution, then name resolution terminates rather than starting the search over with the next element of the context stack. From the spec (interpolation section)–

5) If any name parts were retained in step 1, each should be resolved against a context stack containing only the result from the former resolution. If any part fails resolution, the result should be considered falsey, and should interpolate as the empty string.

This test case is equivalent to the test case in the following pull request:

test_dot_notation__multiple_levels()[source]

Test dot notation with multiple levels.

test_implicit_iterator__escaped()[source]

Test an implicit iterator in a normal tag.

test_implicit_iterator__literal()[source]

Test an implicit iterator in a literal tag.

test_interpolation__built_in_type__integer()[source]

Check tag interpolation with a built-in type: integer.

test_interpolation__built_in_type__list()[source]

Check tag interpolation with a built-in type: list.

test_interpolation__built_in_type__string()[source]

Check tag interpolation with a built-in type: string.

test_interpolation__falsey__none()[source]
test_interpolation__falsey__zero()[source]
test_interpolation__nonascii_nonunicode()[source]

Test a tag whose value is a non-ascii, non-unicode string.

test_lambda__returning_nonascii_nonunicode()[source]

Test a lambda tag value returning a non-ascii, non-unicode string.

test_literal__in_partial()[source]

Check that literals work in partials.

test_literal__in_section()[source]

Check that literals work in sections.

test_literal__sigil()[source]
test_partial()[source]
test_partial__context_values()[source]

Test that escape and literal work on context values in partials.

test_render()[source]
test_section__context_precedence()[source]

Check that items higher in the context stack take precedence.

test_section__context_values()[source]

Test that escape and literal work on context values in sections.

test_section__end_tag_mismatch()[source]

Check what happens if the end tag doesn’t match.

test_section__end_tag_with_no_start_tag()[source]

Check what happens if there is an end tag with no start tag.

test_section__iterable()[source]

Check that objects supporting iteration (aside from dicts) behave like lists.

test_section__lambda()[source]
test_section__lambda__list()[source]

Check that lists of lambdas are processed correctly for sections.

This test case is equivalent to a test submitted to the Mustache spec here:

test_section__lambda__mixed_list()[source]

Test a mixed list of lambdas and non-lambdas as a section value.

This test case is equivalent to a test submitted to the Mustache spec here:

test_section__lambda__no_reinterpolation()[source]

Check that section lambda return values are not re-interpolated.

This test is a sanity check that the rendered lambda return value is not re-interpolated as could be construed by reading the section part of the Mustache spec.

This test case is equivalent to a test submitted to the Mustache spec here:

test_section__lambda__not_on_context_stack()[source]

Check that section lambdas are not pushed onto the context stack.

Even though the sections spec says that section data values should be pushed onto the context stack prior to rendering, this does not apply to lambdas. Lambdas obey their own special case.

This test case is equivalent to a test submitted to the Mustache spec here:

test_section__lambda__returning_nonascii_nonunicode()[source]

Test a lambda section value returning a non-ascii, non-unicode string.

test_section__lambda__returning_nonstring()[source]

Test a lambda section value returning a non-string.

test_section__lambda__tag_in_output()[source]

Check that callable output is treated as a template string (issue #46).

The spec says–

When used as the data value for a Section tag, the lambda MUST be treatable as an arity 1 function, and invoked as such (passing a String containing the unprocessed section contents). The returned value MUST be rendered against the current delimiters, then interpolated in place of the section.

test_section__list_referencing_outer_context()[source]

Check that list items can access the parent context.

For sections whose value is a list, check that items in the list have access to the values inherited from the parent context when rendering.

test_section__nested_truthy()[source]

Check that “nested truthy” sections get rendered.

Test case for issue #24: https://github.com/defunkt/pystache/issues/24

This test is copied from the spec. We explicitly include it to prevent regressions for those who don’t pull down the spec tests.

test_section__nested_with_same_keys()[source]

Check a doubly-nested section with the same context key.

Test case for issue #36: https://github.com/defunkt/pystache/issues/36

test_section__nonascii_nonunicode()[source]

Test a section whose value is a non-ascii, non-unicode string.

test_section__output_not_interpolated()[source]

Check that rendered section output is not interpolated.

test_section__string_values_not_lists()[source]

Check that string section values are not interpreted as lists.

test_tag__output_not_interpolated()[source]

Context values should not be treated as templates (issue #44).

test_tag__output_not_interpolated__section()[source]

Context values should not be treated as templates (issue #44).

test_to_str()[source]

Test the to_str attribute.

test_to_str__lambda()[source]

Test the to_str attribute for a lambda.

test_to_str__section_lambda()[source]
test_to_str__section_list()[source]

Test the to_str attribute for a section list.

pystache.tests.test_renderengine.mock_literal(s)[source]

For use as the literal keyword argument to the RenderEngine constructor.

Arguments:

s: a byte string or unicode string.