Loading robot2doc/config.py +12 −0 Original line number Diff line number Diff line Loading @@ -18,3 +18,15 @@ DOC_MAIN_TITLE = '9 Test Cases' DOC_FILENAME = 'test_spec_from_robot.docx' FILE = "" BASE_SPEC = 'basespec.docx' # If DRY_RUN is True, no output file is created DRY_RUN = False # If QUIET is True, output on stdout is minimized QUIET = False # Commit URL that may be added after each table. If the GIT_COMMIT # is the empty string, nothing is added # Example: # GIT_COMMIT = "http://acme.com/my/example/abcde" GIT_COMMIT = "" No newline at end of file robot2doc/main.py +30 −17 Original line number Diff line number Diff line Loading @@ -23,6 +23,9 @@ DOC_FILENAME = cfg.DOC_FILENAME FILE = cfg.DOC_FILENAME BASE_SPEC = cfg.BASE_SPEC DRY_RUN = cfg.DRY_RUN QUIET = cfg.QUIET def keyword_to_line(k): ''' Takes a Robot Framework keyword object and returns Loading @@ -36,6 +39,23 @@ def keywords_to_text(kws): ''' return "\n".join(map(keyword_to_line, kws)) def gen_test(suite, this_test, spec, sec, subsec, workspace): global DRY_RUN tp = TP(this_test.doc) log_line = ["TD", str(workspace), str(suite), str(this_test), tp.tp_id or "No ID" ] not QUIET and print(",".join(log_line)) if DRY_RUN: return if tp.tp_id != None: spec.add_heading(str(this_test), DOC_TC_LEVEL, tp.tp_id) else: subsec = subsec + 1 spec.add_heading(str(this_test), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) tp.add_to_spec(spec, keywords_to_text(this_test.keywords)) def gen_doc(src, doc_fn, doc_main_tit): ''' Converts a Robot test suite to a word document Loading @@ -47,8 +67,8 @@ def gen_doc(src, doc_fn, doc_main_tit): doc_main_tit top level title for the section in the doc ''' print("### robot2doc version " + cfg.VERSION) print "Starting.." not QUIET and print("### robot2doc version " + cfg.VERSION) not QUIET and print("Starting..") script_dir = os.path.dirname(os.path.realpath(__file__)) cwd = os.getcwd() Loading @@ -67,35 +87,28 @@ def gen_doc(src, doc_fn, doc_main_tit): print("Please check that first argument is a folder of Robot files or a single file.") exit(-1) print("Loaded "+ str(len(workspace.suites)) + " test suites.") not QUIET and print("Loaded "+ str(len(workspace.suites)) + " test suites.") sec = DOC_CLAUSE_LVL_2 - 1 spec.add_main_heading(doc_main_tit) for suite in workspace.suites: sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 print(" Generating test suite: " + str(suite)) spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in suite.tests: print(" Generating test: " + str(i)) tp = TP(i.doc) if tp.tp_id != None: spec.add_heading(str(i), DOC_TC_LEVEL, tp.tp_id) print(" Has TP ID: " + tp.tp_id) else: subsec = subsec + 1 print(" Has NO TP ID.") spec.add_heading(str(i), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) tp.add_to_spec(spec, keywords_to_text(i.keywords)) gen_test(suite, i, spec, sec, subsec, workspace) print "Saving to: " + doc_fn spec.save(doc_fn) print("Finished.") not QUIET and print("Saving to: " + doc_fn) not DRY_RUN and spec.save(doc_fn) not QUIET and print("Finished.") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: robot2doc <robot_file_or_dir> [<out_file> [spec_section_title]]") exit(-1) FILE = sys.argv[1] DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else DOC_FILENAME Loading robot2doc/testpurpose.py +7 −3 Original line number Diff line number Diff line #!/env/python import config class TpField(): ''' Describe a field in a Test Purpose, via its key and value Loading @@ -19,8 +21,8 @@ class TP(): with key value pairs, each separated by ":". ''' def __init__(self, text): t = text.encode('ascii') self.lines = t.split("\\n") # t = text.encode('ascii') self.lines = text.split("\\n") self.tp_fields = map(TpField, self.lines) self.tp_id = None Loading @@ -33,3 +35,5 @@ class TP(): def add_to_spec(self, spec, test): spec.add_tp(self.tp_fields, test) if config.GIT_COMMIT != "": spec.add_commit_url(config.GIT_COMMIT) No newline at end of file robot2doc/testspec.py +3 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,9 @@ class TestSpec(): TestSpec.cell_text_bold(hdr_cells[0]) TestSpec.cell_text_centered(hdr_cells[0]) def add_commit_url(self, commit): self.doc.add_paragraph("Note: Robot code can be found at " + commit) def add_tp(self, fields, testbehaviour): table = self.doc.add_table(cols=2, rows=1) table.style = TABLE_STYLE Loading Loading
robot2doc/config.py +12 −0 Original line number Diff line number Diff line Loading @@ -18,3 +18,15 @@ DOC_MAIN_TITLE = '9 Test Cases' DOC_FILENAME = 'test_spec_from_robot.docx' FILE = "" BASE_SPEC = 'basespec.docx' # If DRY_RUN is True, no output file is created DRY_RUN = False # If QUIET is True, output on stdout is minimized QUIET = False # Commit URL that may be added after each table. If the GIT_COMMIT # is the empty string, nothing is added # Example: # GIT_COMMIT = "http://acme.com/my/example/abcde" GIT_COMMIT = "" No newline at end of file
robot2doc/main.py +30 −17 Original line number Diff line number Diff line Loading @@ -23,6 +23,9 @@ DOC_FILENAME = cfg.DOC_FILENAME FILE = cfg.DOC_FILENAME BASE_SPEC = cfg.BASE_SPEC DRY_RUN = cfg.DRY_RUN QUIET = cfg.QUIET def keyword_to_line(k): ''' Takes a Robot Framework keyword object and returns Loading @@ -36,6 +39,23 @@ def keywords_to_text(kws): ''' return "\n".join(map(keyword_to_line, kws)) def gen_test(suite, this_test, spec, sec, subsec, workspace): global DRY_RUN tp = TP(this_test.doc) log_line = ["TD", str(workspace), str(suite), str(this_test), tp.tp_id or "No ID" ] not QUIET and print(",".join(log_line)) if DRY_RUN: return if tp.tp_id != None: spec.add_heading(str(this_test), DOC_TC_LEVEL, tp.tp_id) else: subsec = subsec + 1 spec.add_heading(str(this_test), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) tp.add_to_spec(spec, keywords_to_text(this_test.keywords)) def gen_doc(src, doc_fn, doc_main_tit): ''' Converts a Robot test suite to a word document Loading @@ -47,8 +67,8 @@ def gen_doc(src, doc_fn, doc_main_tit): doc_main_tit top level title for the section in the doc ''' print("### robot2doc version " + cfg.VERSION) print "Starting.." not QUIET and print("### robot2doc version " + cfg.VERSION) not QUIET and print("Starting..") script_dir = os.path.dirname(os.path.realpath(__file__)) cwd = os.getcwd() Loading @@ -67,35 +87,28 @@ def gen_doc(src, doc_fn, doc_main_tit): print("Please check that first argument is a folder of Robot files or a single file.") exit(-1) print("Loaded "+ str(len(workspace.suites)) + " test suites.") not QUIET and print("Loaded "+ str(len(workspace.suites)) + " test suites.") sec = DOC_CLAUSE_LVL_2 - 1 spec.add_main_heading(doc_main_tit) for suite in workspace.suites: sec = sec + 1 subsec = DOC_CLAUSE_LVL_4 print(" Generating test suite: " + str(suite)) spec.add_sub_heading(str(suite), DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) for i in suite.tests: print(" Generating test: " + str(i)) tp = TP(i.doc) if tp.tp_id != None: spec.add_heading(str(i), DOC_TC_LEVEL, tp.tp_id) print(" Has TP ID: " + tp.tp_id) else: subsec = subsec + 1 print(" Has NO TP ID.") spec.add_heading(str(i), DOC_TC_LEVEL, DOC_CLAUSE_LVL_1, sec, DOC_CLAUSE_LVL_3, subsec) tp.add_to_spec(spec, keywords_to_text(i.keywords)) gen_test(suite, i, spec, sec, subsec, workspace) print "Saving to: " + doc_fn spec.save(doc_fn) print("Finished.") not QUIET and print("Saving to: " + doc_fn) not DRY_RUN and spec.save(doc_fn) not QUIET and print("Finished.") if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: robot2doc <robot_file_or_dir> [<out_file> [spec_section_title]]") exit(-1) FILE = sys.argv[1] DOC_FILENAME = sys.argv[2] if len(sys.argv) > 2 else DOC_FILENAME Loading
robot2doc/testpurpose.py +7 −3 Original line number Diff line number Diff line #!/env/python import config class TpField(): ''' Describe a field in a Test Purpose, via its key and value Loading @@ -19,8 +21,8 @@ class TP(): with key value pairs, each separated by ":". ''' def __init__(self, text): t = text.encode('ascii') self.lines = t.split("\\n") # t = text.encode('ascii') self.lines = text.split("\\n") self.tp_fields = map(TpField, self.lines) self.tp_id = None Loading @@ -33,3 +35,5 @@ class TP(): def add_to_spec(self, spec, test): spec.add_tp(self.tp_fields, test) if config.GIT_COMMIT != "": spec.add_commit_url(config.GIT_COMMIT) No newline at end of file
robot2doc/testspec.py +3 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,9 @@ class TestSpec(): TestSpec.cell_text_bold(hdr_cells[0]) TestSpec.cell_text_centered(hdr_cells[0]) def add_commit_url(self, commit): self.doc.add_paragraph("Note: Robot code can be found at " + commit) def add_tp(self, fields, testbehaviour): table = self.doc.add_table(cols=2, rows=1) table.style = TABLE_STYLE Loading