Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def request_fixed_code_from_openai(
)

print("this-round-result:", unittest_result, cleaned_fixed_code)
if not unittest_result:
if unittest_result is not True:
return example_solution.lstrip(), "example_solution"

if unittest_result:
Expand Down Expand Up @@ -252,7 +252,7 @@ def generate_personalized_fixed_code(
default_test_code,
unittest_case=unittest_code,
)
if not unittest_result:
if unittest_result is not True:
# If the code is not correct, we will TRY to get an example solution first
example_solution = generate_example_solution(
api_token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,16 +414,16 @@ def java_unittest_evaluation(
fixed_code = extract_code_line(fixed_code)
fixed_code = remove_empty_lines(fixed_code)
fixed_code = remove_java_comments(fixed_code)
except Exception as e:
return f"No enough code-{e}", fixed_code
except Exception:
return False, fixed_code

try:
print("fixed_code_test", fixed_code)
java_test_result = load_and_run_java_tests(fixed_code, unittest_case)
print("java_results\n", java_test_result)
return java_test_result, fixed_code
except Exception as e:
return f"We got errors, {e}", fixed_code
except Exception:
return False, fixed_code


def python_unittest_evaluation(
Expand All @@ -447,15 +447,14 @@ def python_unittest_evaluation(
fixed_code = remove_empty_lines(fixed_code)
fixed_code = remove_python_comments(fixed_code)
# print("cleaned_fixed_code\n", fixed_code)
except Exception as e:
return f"No enough code-{e}", fixed_code
except Exception:
return False, fixed_code
try:
##print("fixed_code_first attempt", fixed_code)
results = load_and_run_tests(unittest_case, fixed_code)
print("results.wasSuccessful()\n", results.wasSuccessful())
return results.wasSuccessful(), fixed_code
except Exception as e:
print("Exception", e)
except Exception:
try:
fixed_code = fix_indentation(fixed_code)
results = load_and_run_tests(unittest_case, fixed_code)
Expand All @@ -464,9 +463,9 @@ def python_unittest_evaluation(
# print("results.wasSuccessful()\n", results.wasSuccessful())
return results.wasSuccessful(), fixed_code
else:
return "No starting code", fixed_code
except Exception as e:
return f"We got errors, {e}", fixed_code
return False, fixed_code
except Exception:
return False, fixed_code


def code_distractor_unittest_evaluation(
Expand All @@ -490,25 +489,25 @@ def code_distractor_unittest_evaluation(
code_with_distrator, unittest_case
)
return java_test_result, code_with_distrator
except Exception as e:
return f"We got errors, {e}", code_with_distrator
except Exception:
return False, code_with_distrator
else:
try:
results = load_and_run_tests(unittest_case, code_with_distrator)
if contain_default_starting_code(starting_code, code_with_distrator):
return results.wasSuccessful(), code_with_distrator
else:
return "No starting code", code_with_distrator
return False, code_with_distrator
except Exception:
try:
code_with_distrator = fix_indentation(code_with_distrator)
results = load_and_run_tests(unittest_case, code_with_distrator)
if contain_default_starting_code(starting_code, code_with_distrator):
return results.wasSuccessful(), code_with_distrator
else:
return "No starting code", code_with_distrator
except Exception as e:
return f"We got errors, {e}", code_with_distrator
return False, code_with_distrator
except Exception:
return False, code_with_distrator


def clean_student_code(student_code, default_test_code):
Expand Down
Loading