pylit 0.7.10
[pylit.git] / contribs / pylit_elisp_test.py
bloba50e68b01f6c1d86d590e05faeb759126c82c6d7
1 #!/usr/bin/env python
2 # -*- coding: iso-8859-1 -*-
4 # Test the pylit.py literal python module
5 # =======================================
6 #
7 # :Date: $Date$
8 # :Version: SVN-Revision $Revision$
9 # :URL: $URL: svn+ssh://svn.berlios.de/svnroot/repos/pylit/trunk/test/pylit_test.py $
10 # :Copyright: 2006 Guenter Milde.
11 # Released under the terms of the GNU General Public License
12 # (v. 2 or later)
14 # .. contents::
16 from pprint import pprint
17 # import operator
18 from pylit import *
19 from pylit_elisp import *
20 import nose
22 # Test source samples
23 # ===================
26 code = {}
27 filtered_code = {}
28 text = {}
30 code["simple"] = [";; documentation::\n",
31 "\n",
32 "code_block\n"]
33 filtered_code["simple"] = code["simple"]
35 text["simple"] = ["documentation::\n",
36 "\n",
37 " code_block\n"]
40 code["section header"] = [";; \n", ";;;Commentary:\n"]
41 filtered_code["section header"] = [";; \n", ";; .. |elisp> ;;;Commentary:\n"]
42 text["section header"] = ["\n", ".. |elisp> ;;;Commentary:\n"]
45 # This example fails, as the rst-comment in the first text line is recognized
46 # as a leading code_block (header).
48 # code["section header"] = [";;;Commentary:\n"]
49 # filtered_code["section header"] = [";; .. |elisp> ;;;Commentary:\n"]
50 # text["section header"] = [".. |elisp> ;;;Commentary:\n"]
54 code["section"] = [";; \n",
55 ";;;Commentary:\n",
56 ";; This is\n",
57 ";; a test."]
58 filtered_code["section"] = [";; \n",
59 ";; .. |elisp> ;;;Commentary:\n",
60 ";; This is\n",
61 ";; a test."]
62 text["section"] = ["\n",
63 ".. |elisp> ;;;Commentary:\n",
64 "This is\n",
65 "a test."]
68 def test_elisp_code_preprocessor():
69 """test the code preprocessing filter"""
70 for key in code.keys():
71 data = code[key]
72 soll = filtered_code[key]
73 output = [line for line in elisp_code_preprocessor(data)]
74 print "ist %r (%s)"%(output, key)
75 print "soll %r (%s)"%(soll, key)
76 assert output == soll
79 def test_elisp_code_postprocessor():
80 """test the code preprocessing filter"""
81 for key in code.keys():
82 data = filtered_code[key]
83 soll = code[key]
84 output = [line for line in elisp_code_postprocessor(data)]
85 print "ist %r (%s)"%(output, key)
86 print "soll %r (%s)"%(soll, key)
87 assert output == soll
89 def test_elisp_settings():
90 assert defaults.languages[".el"] == "elisp"
91 assert defaults.comment_strings["elisp"] == ';; '
92 assert defaults.preprocessors["elisp2text"] == elisp_code_preprocessor
93 assert defaults.postprocessors["text2elisp"] == elisp_code_postprocessor
95 def test_elisp2text():
96 for key in code.keys():
97 data = code[key]
98 soll = text[key]
99 converter = Code2Text(data, language="elisp")
100 output = converter()
101 print "ist %r (%s)"%(output, key)
102 print "soll %r (%s)"%(soll, key)
103 assert output == soll
105 class test_Code2Text(object):
106 def test_setup(self):
107 converter = Code2Text(text['simple'], language="elisp")
108 assert converter.preprocessor == elisp_code_preprocessor
110 class test_Text2Code(object):
111 def test_setup(self):
112 converter = Text2Code(text['simple'], language="elisp")
113 assert converter.postprocessor == elisp_code_postprocessor
115 def test_call_without_filter(self):
116 for key in code.keys():
117 data = text[key]
118 soll = filtered_code[key]
119 converter = Text2Code(data, comment_string=";; ")
120 output = converter()
121 print "ist %r (%s)"%(output, key)
122 print "soll %r (%s)"%(soll, key)
123 assert output == soll
125 def test_convert(self):
126 for key in code.keys():
127 data = text[key]
128 soll = filtered_code[key]
129 converter = Text2Code(data, language="elisp")
130 output = [line for line in converter.convert(data)]
131 print "ist %r (%s)"%(output, key)
132 print "soll %r (%s)"%(soll, key)
133 assert output == soll
135 def test_call_with_filter(self):
136 for key in code.keys():
137 data = text[key]
138 soll = code[key]
139 converter = Text2Code(data, language="elisp")
140 output = converter()
141 print "ist %r (%s)"%(output, key)
142 print "soll %r (%s)"%(soll, key)
143 assert output == soll
146 if __name__ == "__main__":
147 nose.runmodule() # requires nose 0.9.1
148 sys.exit()