diff --git a/py-scripts/lf_graph.py b/py-scripts/lf_graph.py index 9704c305..aef088e5 100755 --- a/py-scripts/lf_graph.py +++ b/py-scripts/lf_graph.py @@ -24,7 +24,7 @@ import matplotlib.pyplot as plt import numpy as np import pdfkit from matplotlib.colors import ListedColormap - +import argparse sys.path.append(os.path.join(os.path.abspath(__file__ + "../../../"))) @@ -412,8 +412,40 @@ class lf_line_graph(): print("{}.csv".format(self.graph_image_name)) return "%s.png" % self.graph_image_name -# Unit Test -if __name__ == "__main__": +def main(): + # arguments + parser = argparse.ArgumentParser( + prog='lf_graph.py', + formatter_class=argparse.RawTextHelpFormatter, + epilog='''\ + lf_graph.py : unit test in lf_graph.py for exersizing the lf_graph.py library + ''', + description='''\ +----------------- +NAME: lf_graph.py + +PURPOSE: +Common Library for generating graphs for LANforge output + +SETUP: +/lanforge/html-reports directory needs to be present or output generated in local file + +EXAMPLE: +see: /py-scritps/lf_report_test.py for example + +COPYWRITE + Copyright 2021 Candela Technologies Inc + License: Free to distribute and modify. LANforge systems must be licensed. + +INCLUDE_IN_README +--------------------- + ''') + parser.add_argument('--mgr','--lfmgr', dest='lfmgr', help='sample argument: where LANforge GUI is running', default='localhost') + # the args parser is not really used , this is so the report is not generated when testing + # the imports with --help + args = parser.parse_args() + print("LANforge manager {lfmgr}".format(lfmgr=args.lfmgr)) + output_html_1 = "graph_1.html" output_pdf_1 = "graph_1.pdf" @@ -467,3 +499,8 @@ if __name__ == "__main__": # sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb options = {"enable-local-file-access": None} # prevent eerror Blocked access to file pdfkit.from_file(output_html_2, output_pdf_2, options=options) + +# Unit Test +if __name__ == "__main__": + main() + diff --git a/py-scripts/lf_report_test.py b/py-scripts/lf_report_test.py index 15c1b597..831fe400 100755 --- a/py-scripts/lf_report_test.py +++ b/py-scripts/lf_report_test.py @@ -39,16 +39,33 @@ lf_scatter_graph = lf_graph.lf_scatter_graph lf_stacked_graph = lf_graph.lf_stacked_graph lf_horizontal_stacked_graph = lf_graph.lf_horizontal_stacked_graph - # Unit Test -if __name__ == "__main__": +def main(): # Testing: generate data frame - parser = argparse.ArgumentParser( prog="lf_report_test.py", formatter_class=argparse.RawTextHelpFormatter, - description="Tests reporting library") - parser.add_argument('--lfmgr', help='sample argument: where LANforge GUI is running', default='localhost') + description='''\ +----------------- +NAME: lf_report_test.py + +PURPOSE: +Common file for testing lf_report and lf_graph Library generates html and pdf output + +SETUP: +/lanforge/html-reports directory needs to be present or output generated in local file + +EXAMPLE: +./lf_report_test.py : currently script does not accept input + +COPYWRITE + Copyright 2021 Candela Technologies Inc + License: Free to distribute and modify. LANforge systems must be licensed. + +INCLUDE_IN_README +''') + + parser.add_argument('--mgr','--lfmgr', dest='lfmgr', help='sample argument: where LANforge GUI is running', default='localhost') # the args parser is not really used , this is so the report is not generated when testing # the imports with --help args = parser.parse_args() @@ -227,3 +244,5 @@ if __name__ == "__main__": # report.write_pdf(_page_size = 'Legal', _orientation='Portrait') # report.generate_report() +if __name__ == "__main__": + main()