コード例 #1
0
 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')
コード例 #2
0
 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')
コード例 #3
0
    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)
コード例 #4
0
    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)
コード例 #5
0
 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)
コード例 #6
0
 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)
コード例 #7
0
 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', ()))
コード例 #8
0
 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', ()))
コード例 #9
0
 def __call__(self, **kw):
     # Never used?
     md = TemplateDict()
     md._push(kw)
     return self.eval(md)
コード例 #10
0
 def test_callable_namespace(self):
     td = TemplateDict()
     td._push({'one': DummyNamespace('one')})
     self.assertEqual(td['one'], ('namespace', 'one', (td, )))
コード例 #11
0
 def test_callable_namespace(self):
     td = TemplateDict()
     td._push({'one': DummyNamespace('one')})
     self.assertEqual(td['one'], ('namespace', 'one', (td, )))