logilab/doctools
view test/unittest_transformer.py @ 0:cc367abb080e
forget the past.
forget the past.
| author | root |
|---|---|
| date | Wed, 26 Apr 2006 10:48:09 +0000 |
| parents | |
| children | 23f217b6e336 |
line source
1 # Copyright (c) 2000-2003 LOGILAB S.A. (Paris, FRANCE).
2 # http://www.logilab.fr/ -- mailto:contact@logilab.fr
4 # This program is free software; you can redistribute it and/or modify it under
5 # the terms of the GNU General Public License as published by the Free Software
6 # Foundation; either version 2 of the License, or (at your option) any later
7 # version.
9 # This program is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License along with
14 # this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 """
17 unit tests for the transformer module
18 """
19 __revision__ = "$Id: unittest_transformer.py,v 1.1 2003-09-10 12:38:09 syt Exp $"
21 import unittest
22 import sys
24 from logilab.doctools.transformer import PIManager, FormattingException, \
25 guess_format, InputGuessException
27 class PIManagerClassTest(unittest.TestCase):
28 """unittest of the processing instruction manager"""
30 def setUp(self):
31 self.manager = PIManager()
33 def test_known_values(self):
34 preprocess, styles = self.manager.fromString('''<?xml version="1.0" encoding="iso-8859-15"?>
35 <?logidoc-style target="html" xslt="thisone"?>
36 <?logidoc-style target="pdf" xslt="theotherone"?>
37 <?logidoc-style target="pdf" xslt="ignorethisone"?>
38 <?logidoc-preprocess xslt="thefirstone"?>
39 <?logidoc-preprocess xslt="thesecondone"?>
40 <?ignored-pi xslt="thesecondone"?>
41 <article id="test" lang="fr">
42 Gna gna gna
43 </article>''')
44 self.assertEqual(preprocess, ['thefirstone', 'thesecondone'])
45 self.assertEqual(styles, {'pdf' : 'theotherone', 'html': 'thisone'})
47 def test_raise_1(self):
48 self.assertRaises(FormattingException, self.manager.fromString,
49 '''<?xml version="1.0" encoding="iso-8859-15"?>
50 <?logidoc-style target="html"?>
51 <article id="test" lang="fr">
52 Gna gna gna
53 </article>''')
55 def test_raise_2(self):
56 self.assertRaises(FormattingException, self.manager.fromString,
57 '''<?xml version="1.0" encoding="iso-8859-15"?>
58 <?logidoc-style xslt="theotherone"?>
59 <article id="test" lang="fr">
60 Gna gna gna
61 </article>''')
63 def test_raise_3(self):
64 self.assertRaises(FormattingException, self.manager.fromString,
65 '''<?xml version="1.0" encoding="iso-8859-15"?>
66 <?logidoc-style target="html" xslt="theotherone" truc="bidule"?>
67 <article id="test" lang="fr">
68 Gna gna gna
69 </article>''')
71 def test_raise_4(self):
72 self.assertRaises(FormattingException, self.manager.fromString,
73 '''<?xml version="1.0" encoding="iso-8859-15"?>
74 <?logidoc-preprocess xstl="thefirstone"?>
75 <article id="test" lang="fr">
76 Gna gna gna
77 </article>''')
79 class GuessformatFunctionTest(unittest.TestCase):
82 def test_known_values_1(self):
83 self.assertEqual(guess_format('machin.txt'), 'rest')
85 def test_known_values_2(self):
86 self.assertEqual(guess_format('machin.rst'), 'rest')
88 def test_known_values_3(self):
89 self.assertEqual(guess_format('machin.rest'), 'rest')
91 def test_known_values_4(self):
92 self.assertEqual(guess_format('machin.xml'), 'docbook')
94 def test_known_values_5(self):
95 self.assertEqual(guess_format('machin.dbk'), 'docbook')
97 def test_known_values_6(self):
98 self.assertEqual(guess_format('machin.fo'), 'fo')
100 def test_raise_1(self):
101 self.assertRaises(InputGuessException, guess_format, 'machin.unk')
103 def suite():
104 """return the unitest suite"""
105 loader = unittest.TestLoader()
106 testsuite = loader.loadTestsFromModule(sys.modules[__name__])
107 return testsuite
109 def Run(runner=None):
110 """run tests"""
111 testsuite = suite()
112 if runner is None:
113 runner = unittest.TextTestRunner()
114 # uncomment next line to write tests results in a file
115 #runner.__init__(open('tests.log','w+'))
116 return runner.run(testsuite)
118 if __name__ == '__main__':
119 Run()
