Spaces:
Runtime error
Runtime error
File size: 1,178 Bytes
0af0a55 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
import unittest
import sys
import io
import contextlib
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
def run_tests(test_code):
"""Execute the generated test cases."""
try:
# Redirect stdout to capture test results
with io.StringIO() as buf, contextlib.redirect_stdout(buf):
# Execute the test code
exec(test_code, globals())
# Find test suite and run it
for var_name, var_value in globals().items():
if isinstance(var_value, type) and issubclass(
var_value, unittest.TestCase):
suite = unittest.TestLoader().loadTestsFromTestCase(var_value)
unittest.TextTestRunner(stream=buf, verbosity=2).run(suite)
test_output = buf.getvalue()
print(test_output)
return 0 # Return 0 to indicate successful execution
except Exception as e:
print(f"Error executing tests: {str(e)}")
return 1 # Return 1 to indicate an error
if __name__ == "__main__":
test_code = sys.stdin.read()
exit_code = run_tests(test_code)
sys.exit(exit_code) |