def test_process_annot(self): """Function to test the complete end to end process of function definition extractor (True False annotation)""" dataframe = extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), annot="@Test", report_folder=None) df2_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_annot.xlsx")) dataframe["Code"] = dataframe["Code"].str.replace(os.linesep, "") df2_list["Code"] = df2_list["Code"].str.replace("\r\n", "") self.assertTrue(dataframe["Code"].equals(df2_list["Code"]))
def test_process_python_test_extract(self): """Function to test the complete end to end process of function definition extractor (True True)""" dataframe = extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), functionstartwith="test_", report_folder=None) df2_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_T_T.xlsx")) dataframe["Code"] = dataframe["Code"].str.replace("\r\n", "") df2_list["Code"] = df2_list["Code"].str.replace(os.linesep, "") self.assertEqual(len(dataframe["Code"]), len(df2_list["Code"]))
def test_process_extract(self): """Function to test the complete end to end process of function definition extractor""" dataframe = extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), None, None) df2_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_T_T_A.xlsx")).sort_values('Uniq ID') dataframe["Code"] = dataframe["Code"].str.replace(os.linesep, "") df2_list["Code"] = df2_list["Code"].str.replace(os.linesep, "") df2_list["Code"] = df2_list["Code"].str.replace("\r", "") self.assertEqual(dataframe["Code"].values.tolist().sort(), df2_list["Code"].values.tolist().sort())
def test_process_ad(self): """Function to test the complete end to end process of function definition extractor with Annotation and delta)""" dataframe = extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), annot="@Test", delta="5") df2_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_T_T_A_D.xlsx")).sort_values('Uniq ID') dataframe["Code"] = dataframe["Code"].str.replace(os.linesep, "") df2_list["Code"] = df2_list["Code"].str.replace("\n", "") self.assertTrue(dataframe["Code"].equals(df2_list["Code"]))
def test_process_ft(self): """Function to test the complete end to end process of function definition extractor (False True)""" dataframe = extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), "False", "True", None, None) self.__write_xlsx(dataframe, "expeccodeextractor_F_T") df1_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "expeccodeextractor_F_T.xlsx")).values.tolist() df2_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_F_T.xlsx")).values.tolist() self.assertEqual(df1_list, df2_list)
def test_process_tta(self): """Function to test the complete end to end process of function definition extractor (True False annotation)""" dataframe = extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), "True", "True", "@Test", None) self.__write_xlsx(dataframe, "expeccodeextractor_T_T_A") df1_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "expeccodeextractor_T_T_A.xlsx")).sort_values( 'Uniq ID').values.tolist() df2_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_T_T_A.xlsx")).sort_values( 'Uniq ID').values.tolist() self.assertEqual(df1_list, df2_list)
def test_get_report(self): """Function to test report generated""" dataframe = get_report( extractor( (os.path.join(self.file_path, "test_resource", "test_repo")), None, None), (os.path.join(os.path.dirname(__file__), os.pardir, "test_resource"))) df1_list = pd.read_excel( os.path.join(os.path.dirname(__file__), os.pardir, "test_resource", "codeextractor_T_T_A.xlsx")).sort_values('Uniq ID') dataframe["Code"] = dataframe["Code"].str.replace(os.linesep, "") df1_list["Code"] = df1_list["Code"].str.replace(os.linesep, "") df1_list["Code"] = df1_list["Code"].str.replace("\r", "") self.assertEqual(dataframe["Code"].values.tolist().sort(), df1_list["Code"].values.tolist().sort()) my_dir = os.path.join(os.path.dirname(__file__), os.pardir, "test_resource") for fname in os.listdir(my_dir): if fname.startswith("ExtractedFunc_"): os.remove(os.path.join(my_dir, fname))
def test_invalid_path(self): """Function to test valid input path""" self.assertEqual(extractor(os.path.join("abc", "sdr")), "Enter valid path")
"""Koninklijke Philips N.V., 2019 - 2020. All rights reserved.""" import sys from condition_checker import check_condition from core_extractor import extractor from core_extractor import get_report from extractor_cmd import validate_inputs from extractor_cmd import create_parser if __name__ == '__main__': # Execute the parse_args() method ARGS = create_parser(sys.argv[1:]) if ARGS.delta is not None and ARGS.annot is None: print("delta(--d) should be in combination with annotation(--a)" ) # pragma: no mutate raise SystemExit if ARGS.conditionchecker is None: validate_inputs(ARGS.path, "repository") ARGS.reportpath = ARGS.path if ARGS.reportpath is None else ARGS.reportpath validate_inputs(ARGS.reportpath, "report folder") get_report( extractor(ARGS.path, ARGS.annot, ARGS.delta, ARGS.funcstartwith, ARGS.reportpath, ARGS.ignorefiles), ARGS.reportpath) else: validate_inputs(ARGS.excelfilepath, "Excel file") # pragma: no mutate check_condition(ARGS.conditionchecker, ARGS.excelfilepath, ARGS.splitter)
help='Required number of lines at annotated method') # ...Create your parser as you like... return func_parser.parse_args(args) def validate_inputs(arg_path): """This function helps in validating the user inputs""" status_path = os.path.exists(arg_path) if not status_path: print("Enter Valid Path") sys.stdout.flush() script = os.path.abspath(os.path.join(os.path.realpath(__file__))) cmd = 'python %s --h' % script subprocess.Popen(cmd).communicate()[0] raise SystemExit if __name__ == '__main__': # Execute the parse_args() method ARGS = create_parser(sys.argv[1:]) validate_inputs(ARGS.path) # Process the similarity with inputs provided DATA_FR = extractor(ARGS.path, ARGS.code, ARGS.test, ARGS.annot, ARGS.delta) WRITER = pd.ExcelWriter('%s.xlsx' % os.path.join(ARGS.path, "funcDefExtractResult"), engine='xlsxwriter') DATA_FR.to_excel(WRITER, sheet_name="funcDefExtractResult") WRITER.save()