()
| 87 | |
| 88 | |
| 89 | def main(): |
| 90 | code, success = clean_code(bad_code) |
| 91 | |
| 92 | if not success: |
| 93 | print("Code cleaning failed!") |
| 94 | return |
| 95 | |
| 96 | print(f"Cleaned code: {code}") |
| 97 | |
| 98 | # Add this call back into the code |
| 99 | code += "\ndostuff()" |
| 100 | |
| 101 | # Test script file name to execute in the Docker container |
| 102 | sources_dirname = "test_sources" |
| 103 | test_script = "test_script.py" |
| 104 | expected_output = """5 + 2 = 7 |
| 105 | 5 - 2 = 3 |
| 106 | 5 * 2 = 10 |
| 107 | 5 / 2 = 2.5 |
| 108 | The area of a circle with radius 3 is 28.27 |
| 109 | The square root of 49 is 7.0 |
| 110 | The maximum value in the list is 91 |
| 111 | 7 is a prime number""" |
| 112 | |
| 113 | script_path = os.path.join(os.getcwd(), sources_dirname, test_script) |
| 114 | os.makedirs(os.path.join(os.getcwd(), sources_dirname), exist_ok=True) |
| 115 | |
| 116 | # Write a simple test script to execute in the container |
| 117 | with open(script_path, "w") as f: |
| 118 | f.write(code) |
| 119 | |
| 120 | docker_execute = DockerExecute(sources_dirname=sources_dirname) |
| 121 | |
| 122 | # Prime the pump |
| 123 | exit_code, output = docker_execute.execute(test_script) |
| 124 | assert output == expected_output, f"Unexpected output: {output}" |
| 125 | assert exit_code == 0, f"Unexpected exit code: {exit_code}" |
| 126 | |
| 127 | # Remove the test script file |
| 128 | os.remove(script_path) |
| 129 | |
| 130 | print("Success! Script now runs and prints the expected output.") |
| 131 | |
| 132 | if __name__ == "__main__": |
| 133 | main() |
no test coverage detected