pystache.tests.test_context module

Unit tests of context.py.

class pystache.tests.test_context.ContextStackTestCase(methodName='runTest')[source]

Bases: TestCase, AssertIsMixin, AssertStringMixin, AssertExceptionMixin

Test the ContextStack class.

test__repr()[source]
test__str()[source]
test_copy()[source]
test_create__context()[source]

Test passing a ContextStack instance.

test_create__dictionary()[source]

Test passing a dictionary.

test_create__kwarg()[source]

Test passing a keyword argument.

test_create__none()[source]

Test passing None.

test_create__object()[source]

Test passing an object.

test_create__precedence_keyword()[source]

Test precedence of keyword arguments.

test_create__precedence_positional()[source]

Test precedence of positional arguments.

test_dot_notation__autocall()[source]
test_dot_notation__dict()[source]
test_dot_notation__missing_attr_or_key()[source]

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__mixed_dict_and_obj()[source]
test_dot_notation__user_object()[source]
test_get__fallback()[source]

Check that first-added stack items are queried on context misses.

test_get__key_missing()[source]

Test getting a missing key.

test_get__key_present()[source]

Test getting a key.

test_get__precedence()[source]

Test that get() respects the order of precedence (later items first).

test_get__single_dot()[source]

Test getting a single dot (“.”).

test_get__single_dot__missing()[source]

Test getting a single dot (“.”) with an empty context stack.

test_init__many_elements()[source]

Check that passing more than two items to __init__() raises no exception.

test_init__no_elements()[source]

Check that passing nothing to __init__() raises no exception.

test_pop()[source]

Test pop().

test_push()[source]

Test push().

test_top()[source]
class pystache.tests.test_context.DictLike[source]

Bases: object

A sample class that implements __getitem__() and __contains__().

class pystache.tests.test_context.GetValueTestCase(methodName='runTest')[source]

Bases: TestCase, AssertIsMixin

Test context._get_value().

assertNotFound(item, key)[source]

Assert that a call to _get_value() returns _NOT_FOUND.

test_built_in_type__integer()[source]

Test getting from an integer.

test_built_in_type__list()[source]

Test getting from a list.

test_built_in_type__string()[source]

Test getting from a string.

test_dictionary__attributes_not_checked()[source]

Test that dictionary attributes are not checked.

test_dictionary__callable_not_called()[source]

Test that callable values are returned as-is (and in particular not called).

test_dictionary__dict_subclass()[source]

Test that subclasses of dict are treated as dictionaries.

test_dictionary__key_missing()[source]

Test getting a missing key from a dictionary.

test_dictionary__key_present()[source]

Test getting a key from a dictionary.

test_object__attribute_is_callable()[source]

Test getting a callable attribute from an object.

test_object__attribute_missing()[source]

Test getting a missing attribute from an object.

test_object__attribute_present()[source]

Test getting an attribute from an object.

test_object__dict_like()[source]

Test getting a key from a dict-like object (an object that implements ‘__getitem__’).

test_object__non_built_in_type()[source]

Test getting an attribute from an instance of a type that isn’t built-in.

test_object__property__raising_exception()[source]

Test getting a property that raises an exception.

class pystache.tests.test_context.SimpleObject[source]

Bases: object

A sample class that does not define __getitem__().

foo_callable()[source]