/usr/share/pyshared/twisted/lore/test/test_man2lore.py is in python-twisted-lore 11.1.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | # Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.lore.man2lore}.
"""
from StringIO import StringIO
from twisted.trial.unittest import TestCase
from twisted.lore.man2lore import ManConverter
_TRANSITIONAL_XHTML_DTD = ("""\
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
""")
class ManConverterTestCase(TestCase):
"""
Tests for L{ManConverter}.
"""
def setUp(self):
"""
Build instance variables useful for tests.
@ivar converter: a L{ManConverter} to be used during tests.
"""
self.converter = ManConverter()
def assertConvert(self, inputLines, expectedOutput):
"""
Helper method to check conversion from a man page to a Lore output.
@param inputLines: lines of the manpages.
@type inputLines: C{list}
@param expectedOutput: expected Lore content.
@type expectedOutput: C{str}
"""
inputFile = StringIO()
for line in inputLines:
inputFile.write(line + '\n')
inputFile.seek(0)
outputFile = StringIO()
self.converter.convert(inputFile, outputFile)
self.assertEqual(
outputFile.getvalue(), _TRANSITIONAL_XHTML_DTD + expectedOutput)
def test_convert(self):
"""
Test convert on a minimal example.
"""
inputLines = ['.TH BAR "1" "Oct 2007" "" ""', "Foo\n"]
output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n"
"<h1>BAR.1</h1>\n\n<p>Foo\n\n</p>\n\n</body>\n</html>\n")
self.assertConvert(inputLines, output)
def test_TP(self):
"""
Test C{TP} parsing.
"""
inputLines = ['.TH BAR "1" "Oct 2007" "" ""',
".SH HEADER",
".TP",
"\\fB-o\\fR, \\fB--option\\fR",
"An option"]
output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n"
"<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl><dt>"
"<strong>-o</strong>, <strong>--option</strong>\n</dt>"
"<dd>An option\n</dd>\n\n</dl>\n\n</body>\n</html>\n")
self.assertConvert(inputLines, output)
def test_TPMultipleOptions(self):
"""
Try to parse multiple C{TP} fields.
"""
inputLines = ['.TH BAR "1" "Oct 2007" "" ""',
".SH HEADER",
".TP",
"\\fB-o\\fR, \\fB--option\\fR",
"An option",
".TP",
"\\fB-n\\fR, \\fB--another\\fR",
"Another option",
]
output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n"
"<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl><dt>"
"<strong>-o</strong>, <strong>--option</strong>\n</dt>"
"<dd>An option\n</dd>\n\n<dt>"
"<strong>-n</strong>, <strong>--another</strong>\n</dt>"
"<dd>Another option\n</dd>\n\n</dl>\n\n</body>\n</html>\n")
self.assertConvert(inputLines, output)
def test_TPMultiLineOptions(self):
"""
Try to parse multiple C{TP} fields, with options text on several lines.
"""
inputLines = ['.TH BAR "1" "Oct 2007" "" ""',
".SH HEADER",
".TP",
"\\fB-o\\fR, \\fB--option\\fR",
"An option",
"on two lines",
".TP",
"\\fB-n\\fR, \\fB--another\\fR",
"Another option",
"on two lines",
]
output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n"
"<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl><dt>"
"<strong>-o</strong>, <strong>--option</strong>\n</dt>"
"<dd>An option\non two lines\n</dd>\n\n"
"<dt><strong>-n</strong>, <strong>--another</strong>\n</dt>"
"<dd>Another option\non two lines\n</dd>\n\n</dl>\n\n"
"</body>\n</html>\n")
self.assertConvert(inputLines, output)
def test_ITLegacyManagement(self):
"""
Test management of BL/IT/EL used in some man pages.
"""
inputLines = ['.TH BAR "1" "Oct 2007" "" ""',
".SH HEADER",
".BL",
".IT An option",
"on two lines",
".IT",
"Another option",
"on two lines",
".EL"
]
output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n"
"<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl>"
"<dt>on two lines\n</dt><dd>Another option\non two lines\n"
"</dd></dl>\n\n</body>\n</html>\n")
self.assertConvert(inputLines, output)
def test_interactiveCommand(self):
"""
Test management of interactive command tag.
"""
inputLines = ['.TH BAR "1" "Oct 2007" "" ""',
".SH HEADER",
".BL",
".IT IC foo AR bar",
"option 1",
".IT IC egg AR spam OP AR stuff",
"option 2",
".EL"
]
output = ("<html><head>\n<title>BAR.1</title></head>\n<body>\n\n"
"<h1>BAR.1</h1>\n\n<h2>HEADER</h2>\n\n<dl>"
"<dt>foo <u>bar</u></dt><dd>option 1\n</dd><dt>egg "
"<u>spam</u> [<u>stuff</u>]</dt><dd>option 2\n</dd></dl>"
"\n\n</body>\n</html>\n")
self.assertConvert(inputLines, output)
|