def test_push_pop(self): td = TemplateDict() td._push('foo') td._push('bar') self.assertEqual(len(td), 6) self.assertEqual(td[0], 'b') self.assertEqual(td[:], 'bar') self.assertEqual(td.getitem(-1), 'r') self.assertTrue(td() is None) self.assertEqual(td._pop(1), 'bar') self.assertEqual(len(td), 3) self.assertEqual(td[:], 'foo')
def test_callable_httpexception(self): # Subclasses of zException.HTTPException are callable but should # not be called during lookup in the template dict. from zExceptions import NotFound from zExceptions import Unauthorized notfound = NotFound('ouch') unauth = Unauthorized('argh') td = TemplateDict() td._push({'one': unauth, 'two': notfound}) self.assertEqual(td['one'], unauth) self.assertEqual(td['two'], notfound)
def test_stack(self): td = TemplateDict() td._push({'one': 1, 'two': 2}) td._push(object()) td._push({'two': 22, 'three': 3}) td._push({'four': None}) self.assertTrue('three' in td) self.assertEqual(td.getitem('three'), 3) self.assertTrue('two' in td) self.assertEqual(td.getitem('two'), 22) self.assertRaises(TypeError, td.__contains__, 'one') self.assertRaises(TypeError, td.getitem, 'one') self.assertTrue('four' in td) self.assertEqual(td.getitem('four'), None)
def test_callable_doctemp(self): td = TemplateDict() td._push({'zero': DummyDocTemp('zero', False)}) td._push({'one': DummyDocTemp('one'), 'two': 2}) td._push({'two': DummyDocTemp('two'), 'three': 3}) self.assertEqual(td['three'], 3) self.assertEqual(td['two'], ('doctemp', 'two', (None, td))) self.assertEqual(td['one'], ('doctemp', 'one', (None, td))) self.assertEqual(td['zero'], ('doctemp', 'zero', ()))
def __call__(self, **kw): # Never used? md = TemplateDict() md._push(kw) return self.eval(md)
def test_callable_namespace(self): td = TemplateDict() td._push({'one': DummyNamespace('one')}) self.assertEqual(td['one'], ('namespace', 'one', (td, )))