Skip to content

Commit

Permalink
fix(ci): Made further changes to run_tests.py (ivy-llc#26811)
Browse files Browse the repository at this point in the history
To correctly read names of instance methods in frontends, ivy array and the stateful API, also added some fail checks to ensure it fails rather than adding meaningless values to the database
  • Loading branch information
vedpatwardhan authored and druvdub committed Oct 14, 2023
1 parent b4db757 commit 59693f8
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,50 @@ def get_submodule_and_function_name(test_path, is_frontend_test=False):
submodule_test = test_path.split("/")[-1]
submodule, test_function = submodule_test.split("::")
submodule = submodule.replace("test_", "").replace(".py", "")
function_name = test_function[5:]
if is_frontend_test:
with open(test_path.split("::")[0]) as test_file:
test_file_content = test_file.read()
test_name = test_function.split(",")[0]
test_function_idx = test_file_content.find(f"def {test_name}")
fn_tree_idx = test_file_content[:test_function_idx].rfind('fn_tree="')

with open(test_path.split("::")[0]) as test_file:
test_file_content = test_file.read()
test_function_idx = test_file_content.find(f"def {test_function}")
test_function_block_idx = test_file_content[:test_function_idx].rfind("\n\n")
if test_function_block_idx == -1:
return submodule, None
relevant_file_content = test_file_content[
test_function_block_idx:test_function_idx
]
fn_tree_idx = relevant_file_content.rfind('fn_tree="')

# frontend test
if is_frontend_test:
function_name = relevant_file_content[fn_tree_idx + 9 :].split('"')[0]

# instance method test
if fn_tree_idx == -1:
class_tree_idx = test_file_content.find('CLASS_TREE = "')
method_name_idx = relevant_file_content.rfind('method_name="')
if class_tree_idx == -1 or method_name_idx == -1:
return submodule, None
class_tree = test_file_content[class_tree_idx + 14 :].split('"')[0]
class_name = ".".join(class_tree.split(".")[3:])
method_name = relevant_file_content[method_name_idx + 13 :].split('"')[
0
]
function_name = f"{class_name}.{method_name}"

# ivy test
else:
function_name = test_function[5:]

# instance method test
if fn_tree_idx == -1:
return submodule, None
function_name = test_file_content[fn_tree_idx + 9 :].split('"')[0]
method_name_idx = relevant_file_content.rfind('method_tree="')
if method_name_idx != -1:
method_name = relevant_file_content[method_name_idx + 13 :].split(
'"'
)[0]
function_name = f"ivy.{method_name}"
else:
return submodule, None

return submodule, function_name


Expand Down

0 comments on commit 59693f8

Please sign in to comment.