Iterate through files under `path` to find out all operator names, and update code links to file_func_map_list by file_func_map.
(path)
| 107 | |
| 108 | |
| 109 | def get_test_func(path): |
| 110 | """ |
| 111 | Iterate through files under `path` to find out all operator names, |
| 112 | and update code links to file_func_map_list by file_func_map. |
| 113 | """ |
| 114 | files = os.listdir(path) |
| 115 | commit_bytes = subprocess.check_output(["git", "rev-parse", "HEAD"]) |
| 116 | commit_str = commit_bytes.decode("utf-8").replace("\n", "") |
| 117 | result_func_list = [] |
| 118 | for file in files: |
| 119 | if file != "log" and not os.path.isdir(file) and file.find("__pycache__") == -1: |
| 120 | f = open(os.path.join(path, file)) |
| 121 | last_line = "" |
| 122 | iter_f = iter(f) |
| 123 | line_num = 1 |
| 124 | for line in iter_f: |
| 125 | line = line.strip() |
| 126 | rem = re.match("def .*?(test_.*)\(test_case.*", line) |
| 127 | if rem and "#" not in line: |
| 128 | func_name = rem.group(1).replace("_test_", "").replace("test_", "") |
| 129 | result_func_list.append(func_name) |
| 130 | file_func_map[func_name] = ( |
| 131 | f" [{func_name}](" |
| 132 | + "https://github.com/Oneflow-Inc/oneflow/blob/" |
| 133 | + commit_str |
| 134 | + "/python/oneflow/test/" |
| 135 | + path |
| 136 | + "/" |
| 137 | + file |
| 138 | + f"#L{line_num}) " |
| 139 | ) |
| 140 | elif last_line.startswith("add_docstr"): |
| 141 | result_func_list.append(line[0:-1]) |
| 142 | file_func_map[line[0:-1]] = ( |
| 143 | f" [{line[0:-1]}](" |
| 144 | + "https://github.com/Oneflow-Inc/oneflow/blob/" |
| 145 | + commit_str |
| 146 | + "/python/oneflow/test/" |
| 147 | + path |
| 148 | + "/" |
| 149 | + file |
| 150 | + f"#L{line_num}) " |
| 151 | ) |
| 152 | last_line = line |
| 153 | line_num += 1 |
| 154 | return result_func_list |
| 155 | |
| 156 | |
| 157 | def pure_match(x, y): |
no test coverage detected