2 # -*- coding: iso-8859-1 -*-
4 # Test the pylit.py literal python module
5 # =======================================
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
16 from pprint
import pprint
19 from pylit_elisp
import *
30 code
["simple"] = [";; documentation::\n",
33 filtered_code
["simple"] = code
["simple"]
35 text
["simple"] = ["documentation::\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",
58 filtered_code
["section"] = [";; \n",
59 ";; .. |elisp> ;;;Commentary:\n",
62 text
["section"] = ["\n",
63 ".. |elisp> ;;;Commentary:\n",
68 def test_elisp_code_preprocessor():
69 """test the code preprocessing filter"""
70 for key
in code
.keys():
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
)
79 def test_elisp_code_postprocessor():
80 """test the code preprocessing filter"""
81 for key
in code
.keys():
82 data
= filtered_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
)
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():
99 converter
= Code2Text(data
, language
="elisp")
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():
118 soll
= filtered_code
[key
]
119 converter
= Text2Code(data
, comment_string
=";; ")
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():
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():
139 converter
= Text2Code(data
, language
="elisp")
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