diff --git a/README.md b/README.md index d46dfae..0b21554 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,15 @@ print(out_put[0], out_put[1]) >>>python -m functiondefextractor --p "path/to/repo" ``` +- To extract functions from repo having specific annotation. + +```sh +>>>python -m functiondefextractor --p "path/to/repo" --a "@SuppressWarnings(\"UnusedReturnValue\")" +``` + +Note: If annotation contains double quotes as part of annotation(like +above example) use backslash(\) before double quote inside annotation. + - To ignore files from repo using regex pattern. ```sh diff --git a/functiondefextractor/__main__.py b/functiondefextractor/__main__.py index 1be45f5..360e51f 100644 --- a/functiondefextractor/__main__.py +++ b/functiondefextractor/__main__.py @@ -16,8 +16,8 @@ raise SystemExit if ARGS.conditionchecker is None: validate_inputs(ARGS.path, "repository") - ARGS.reportpath = ARGS.path if ARGS.reportpath is None else ARGS.reportpath # pragma: no mutate - validate_inputs(ARGS.reportpath, "report folder") # pragma: no mutate + 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: diff --git a/functiondefextractor/condition_checker.py b/functiondefextractor/condition_checker.py index 1ac4ba3..afcd158 100644 --- a/functiondefextractor/condition_checker.py +++ b/functiondefextractor/condition_checker.py @@ -63,7 +63,7 @@ def get_pivot_table_result(data, test_assert, splitter, file_path): splitter: key to split statement in pivot table file_path: Input xlsx file used for searching pattern""" specifier_column = clean_data(splitter, data) - data_frame = DataFrame(specifier_column, columns=['Count']) + data_frame = DataFrame(specifier_column, columns=['Count']) # pragma: no mutate data_table = data_frame.Count.value_counts() data_table = data_table.to_frame() data_table = data_table.reset_index() diff --git a/functiondefextractor/core_extractor.py b/functiondefextractor/core_extractor.py index 3ebf27f..542eb3f 100644 --- a/functiondefextractor/core_extractor.py +++ b/functiondefextractor/core_extractor.py @@ -189,7 +189,7 @@ def get_annot_methods(filename, line_num, annot): file_content = get_file_content(filename) iterator = int(line_num) - 2 # Iterating through lines to check for annotations try: - for _ in range(int(line_num) - 2): + for _ in range(int(line_num) - 2): # pragma: no mutate data = str(file_content[iterator]).strip() iterator = iterator - 1 ret_val = process_annot_method_body(annot, data, filename, line_num) @@ -262,13 +262,13 @@ def get_py_annot_method_names(line_data, annot, val): data = [] for i, _ in enumerate(line_data): if annot in line_data[i]: - if str(line_data[i]).strip().split(" ")[0] == "def": - func_name = line_data[i + 1 + val].strip().split(" ")[1].split("(")[0] + if str(line_data[i]).strip().split(" ")[0] == "def": # pragma: no mutate + func_name = line_data[i + 1 + val].strip().split(" ")[1].split("(")[0] # pragma: no mutate data.append(func_name) else: for j in range(i, len(line_data)): - if str(line_data[j]).strip().split(" ")[0] == "def": - func_name = line_data[j].strip().split(" ")[1].split("(")[0] + if str(line_data[j]).strip().split(" ")[0] == "def": # pragma: no mutate + func_name = line_data[j].strip().split(" ")[1].split("(")[0] # pragma: no mutate data.append(func_name) break return data @@ -336,7 +336,7 @@ def process_py_methods(file_name, line_numbers, line_data): for i, _ in enumerate(line_numbers): start = line_numbers[i] stop = len(line_data) if i == len(line_numbers) - 1 else line_numbers[i + 1] - 1 - data.append(os.linesep.join(line_data[start - 1:stop])) + data.append(os.linesep.join(line_data[start - 1:stop])) # pragma: no mutate data_func_name.append(str(file_name) + "_" + str(line_data[start - 1].strip().split(" ")[1].split("(")[0])) if data[len(data) - 1].startswith("class") or "lambda" in data[len(data) - 1]: data.remove(data[len(data) - 1]) @@ -407,7 +407,7 @@ def filter_files(list_files): This function returns the list of required file(.java, .cpp, .c, .cs, .py) paths """ local_files = [] for files in list_files: - extension = files.split('.')[-1].upper() + extension = files.split('.')[-1].upper() # pragma: no mutate if len(extension).__trunc__() > 0: if extension in FILE_TYPE: local_files.append(files) @@ -640,7 +640,7 @@ def initialize_values(delta, annot, path_loc, report_folder): if report_folder is None: report_folder = path_loc if validate_input_paths(report_folder): - return "Enter valid report path" + return "Enter valid report path" # pragma: no mutate LOG.info("Input report folder path validated successfully") # pragma: no mutate return report_folder, annot diff --git a/setup.cfg b/setup.cfg index af5913e..722e90f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,4 +1,4 @@ [mutmut] -paths_to_mutate=functiondefextractor/core_extractor.py, functiondefextractor/condition_checker.py, functiondefextractor/extractor_log.py +paths_to_mutate=functiondefextractor/condition_checker.py, functiondefextractor/core_extractor.py, functiondefextractor/extractor_cmd.py, functiondefextractor/extractor_log.py paths_to_exclude=test_resource runner=python -m pytest test diff --git a/spell_check/spell_ignore_md.txt b/spell_check/spell_ignore_md.txt index 1ce22aa..5e081f5 100644 --- a/spell_check/spell_ignore_md.txt +++ b/spell_check/spell_ignore_md.txt @@ -78,3 +78,4 @@ Supresswarnings cpp regex functionstartwith +UnusedReturnValue