def test_dot_notation__missing_part_terminates_search(self): """ 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: https://github.com/mustache/spec/pull/48 """ stack = ContextStack({'a': {'b': 'A.B'}}, {'a': 'A'}) self.assertEqual(stack.get('a'), 'A') self.assertString(stack.get('a.b'), u'') stack.pop() self.assertEqual(stack.get('a.b'), 'A.B')
def test_pop(self): """ Test pop(). """ key = "foo" context = ContextStack({key: "bar"}, {key: "buzz"}) self.assertEqual(context.get(key), "buzz") item = context.pop() self.assertEqual(item, {"foo": "buzz"}) self.assertEqual(context.get(key), "bar")