diff --git a/bases/rsptx/book_server_api/routers/personalized_parsons/end_to_end.py b/bases/rsptx/book_server_api/routers/personalized_parsons/end_to_end.py index 2f0e9b67a..814defa75 100644 --- a/bases/rsptx/book_server_api/routers/personalized_parsons/end_to_end.py +++ b/bases/rsptx/book_server_api/routers/personalized_parsons/end_to_end.py @@ -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: @@ -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, diff --git a/bases/rsptx/book_server_api/routers/personalized_parsons/evaluate_fixed_code.py b/bases/rsptx/book_server_api/routers/personalized_parsons/evaluate_fixed_code.py index dcc8aeef1..8a335ed22 100644 --- a/bases/rsptx/book_server_api/routers/personalized_parsons/evaluate_fixed_code.py +++ b/bases/rsptx/book_server_api/routers/personalized_parsons/evaluate_fixed_code.py @@ -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( @@ -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) @@ -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( @@ -490,15 +489,15 @@ 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) @@ -506,9 +505,9 @@ def code_distractor_unittest_evaluation( 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):