Spaces:
Paused
Paused
File size: 1,378 Bytes
81b8721 | 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 37 38 39 40 41 42 43 44 45 46 | import base64
import unittest
from core.trae_bot import TraeBot
class DummyPage:
def __init__(self):
self.url = "https://example.com/x"
def content(self):
return "<html><body>hi</body></html>"
def screenshot(self, full_page=True, type="png"):
return b"\x89PNG\r\n\x1a\nfake"
class DummyPageNoScreenshot(DummyPage):
def screenshot(self, full_page=True, type="png"):
raise RuntimeError("no screenshot")
class TestDebugCapture(unittest.TestCase):
def test_capture_sets_fields(self):
bot = TraeBot("sid")
try:
raise ValueError("boom")
except Exception as e:
bot._capture_debug(DummyPage(), e)
self.assertIn("ValueError", bot.last_error)
self.assertIsInstance(bot.last_traceback, str)
self.assertEqual(bot.last_url, "https://example.com/x")
self.assertIn("hi", bot.last_html)
png = base64.b64decode(bot.last_screenshot_png_b64.encode("ascii"))
self.assertTrue(png.startswith(b"\x89PNG"))
def test_capture_survives_screenshot_failure(self):
bot = TraeBot("sid")
try:
raise RuntimeError("boom")
except Exception as e:
bot._capture_debug(DummyPageNoScreenshot(), e)
self.assertIn("RuntimeError", bot.last_error)
self.assertIsNone(bot.last_screenshot_png_b64)
|