1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | import unittest |
---|
4 | |
---|
5 | import Cheetah |
---|
6 | import Cheetah.Parser |
---|
7 | import Cheetah.Template |
---|
8 | |
---|
9 | class Chep_2_Conditionalized_Import_Behavior(unittest.TestCase): |
---|
10 | def test_ModuleLevelImport(self): |
---|
11 | ''' Verify module level (traditional) import behavior ''' |
---|
12 | pass |
---|
13 | |
---|
14 | def test_InlineImport(self): |
---|
15 | ''' Verify (new) inline import behavior works ''' |
---|
16 | template = ''' |
---|
17 | #def funky($s) |
---|
18 | #try |
---|
19 | #import urllib |
---|
20 | #except ImportError |
---|
21 | #pass |
---|
22 | #end try |
---|
23 | #return urllib.quote($s) |
---|
24 | #end def |
---|
25 | ''' |
---|
26 | try: |
---|
27 | template = Cheetah.Template.Template.compile(template) |
---|
28 | except Cheetah.Parser.ParseError, ex: |
---|
29 | self.fail('Failed to properly generate code %s' % ex) |
---|
30 | template = template() |
---|
31 | rc = tepmlate.funky('abc def') |
---|
32 | assert rc == 'abc+def' |
---|
33 | |
---|
34 | def test_LegacyMode(self): |
---|
35 | ''' Verify disabling of CHEP #2 works ''' |
---|
36 | pass |
---|
37 | |
---|
38 | if __name__ == '__main__': |
---|
39 | unittest.main() |
---|