def test_paragraph(self): "test the paragraph in the document" doc = rst.Document(u("")) para = rst.Paragraph(u('This is a paragraph.')) doc.add_child(para) text = doc.get_rst() actual_text = u('\n\n\n\nThis is a paragraph.\n\n') self.assertEqual(text, actual_text)
def test_codeblock(self): "test the CodeBlock in the document" doc = rst.Document(u("T")) code = rst.CodeBlock("import sys", lang="python", linenos=True) doc.add_child(code) text = doc.get_rst() actual_text = u( '=\nT\n=\n\n.. code-block:: python\n :linenos:\n\n import sys\n' ) self.assertEqual(text, actual_text)
def test_orderedlist(self): "test the OrderedList in the document" doc = rst.Document(u("T")) blt = rst.Orderedlist() blt.add_item('Fedora') blt.add_item('Debian') doc.add_child(blt) text = doc.get_rst() actual_text = u('=\nT\n=\n\n 1. Fedora\n 2. Debian\n\n') self.assertEqual(text, actual_text)
def test_title(self): "test the title of the document" doc = rst.Document(u("Sample document")) text = doc.get_rst() actual_text = u("""=============== Sample document =============== """) self.assertEqual(text, actual_text)
def test_sections(self): "test the sections in the document" doc = rst.Document(u("Title")) sec = rst.Section('Section One', 2) doc.add_child(sec) sec2 = rst.Section('Section Two', 3) doc.add_child(sec2) text = doc.get_rst() actual_text = u( '=====\nTitle\n=====\n\n\nSection One\n-----------\n\n\nSection Two\n+++++++++++\n\n' ) self.assertEqual(text, actual_text)
def output(self, results): # Prepare the rst doc = rst.Document('Metrics for the code "%s"' % self.prettify(results[CODE_PATH])) doc.add_child( rst.Paragraph('*Date of the report:* %s\n\n' % self.prettify(results[REPORT_DATE]))) table = rst.Table('Metrics', ['Name', 'Value']) for k, v in results.items(): if k in [CODE_PATH, REPORT_DATE]: continue # Skip some fields table.add_item((k, self.prettify(v))) doc.add_child(table) # Write it os.makedirs(os.path.dirname(self.path), exist_ok=True) with open('%s' % self.path, 'w') as file: file.write(doc.get_rst())
def main(): doc = rst.Document('Title of the report') para = rst.Paragraph('Just another paragraph. We need few more of these.') doc.add_child(para) sec = rst.Section('Another', 2) doc.add_child(sec) para = rst.Paragraph('Can we do this? Yes we can.') doc.add_child(para) blt = rst.Orderedlist() blt.add_item('Red Hat') blt.add_item('Fedora') blt.add_item('Debian') doc.add_child(blt) blt = rst.Bulletlist() blt.add_item('Python') blt.add_item('C') blt.add_item('C++') blt.add_item('Lisp') doc.add_child(blt) sec2 = rst.Section('Why Python is awesome?', 2) sec.add_child(sec2) tbl = rst.Table('My friends', ['Name', 'Major Project']) tbl.add_item(('Ramki', 'Python')) tbl.add_item(('Pradeepto', 'Kde')) tbl.add_item(('Nicubunu', 'Fedora')) doc.add_child(tbl) print doc.get_rst()
for line in self.info['steps']: row = [] row.append(line) tbl.add_item(row) doc.add_child(tbl) para = rst.Paragraph('\n**Expected Results**\n') doc.add_child(para) bList = rst.Bulletlist() for line in self.info['expect']: bList.add_item(line) doc.add_child(bList) para = rst.Paragraph('\n**Actual Results**\n') doc.add_child(para) para = rst.Paragraph(' PASS\n') doc.add_child(para) if __name__ == '__main__': with open('testPlan.json') as testFd: testInfo = json.load(testFd) testsList = [None] * int(testInfo['totalTests']) for testName, testDtls in testInfo['tests'].iteritems(): testsList[int(testDtls['index']) - 1] = testPlanDoc(testDtls) doc = rst.Document('Test Cases') for test in testsList: test.generateDoc(doc) with open('source/testCases.rst', 'w+') as testFd: testFd.writelines(doc.get_rst())