OILS / doctools / oils_doc_test.py View on Github | oilshell.org

79 lines, 40 significant
1#!/usr/bin/env python2
2"""oils_doc_test.py: Tests for oils_doc.py."""
3from __future__ import print_function
4
5import sys
6import unittest
7
8from doctools import oils_doc # module under test
9from lazylex import html
10
11with open('lazylex/testdata.html') as f:
12 TEST_HTML = f.read()
13
14
15class OilsDocTest(unittest.TestCase):
16
17 def testTopicCssClass(self):
18
19 CASES = [
20 ('language-chapter-links-expr-lang', True),
21 ('language-chapter-links-expr-lang_56', True),
22 ]
23
24 for s, matches in CASES:
25 m = oils_doc.CSS_CLASS_RE.match(s)
26 print(m.groups())
27
28 def testExpandLinks(self):
29 """
30 <a href=$xref:bash>bash</a>
31 ->
32 <a href=/cross-ref?tag=bash#bash>
33
34 NOTE: THIs could really be done with a ref like <a.*href="(.*)">
35 But we're testing it
36 """
37 h = oils_doc.ExpandLinks(TEST_HTML)
38 self.assert_('/blog/tags.html' in h, h)
39
40 def testShPrompt(self):
41 r = oils_doc._PROMPT_LINE_RE
42 line = 'oil$ ls -l&lt;TAB&gt; # comment'
43 m = r.match(line)
44
45 if 0:
46 print(m.groups())
47 print(m.group(2))
48 print(m.end(2))
49
50 plugin = oils_doc.ShPromptPlugin(line, 0, len(line))
51 out = html.Output(line, sys.stdout)
52 plugin.PrintHighlighted(out)
53
54 def testHighlightCode(self):
55 # lazylex/testdata.html has the language-sh-prompt
56
57 h = oils_doc.HighlightCode(TEST_HTML, None)
58 self.assert_('<span class="sh-prompt">' in h, h)
59 #print(h)
60
61 def testPygmentsPlugin(self):
62 # TODO: Doesn't pass on Travis because pygments isn't there
63 # use virtualenv or something?
64 return
65
66 HTML = '''
67<pre><code class="language-sh">
68 echo hi &gt; out.txt
69</code></pre>
70 '''
71 h = oils_doc.HighlightCode(HTML, None)
72
73 # assert there's no double escaping
74 self.assert_('hi &gt; out.txt' in h, h)
75 #print(h)
76
77
78if __name__ == '__main__':
79 unittest.main()