def test_log_event(self) -> None: e = Event( name="torch.monitor.TestEvent", timestamp=datetime.now(), data={ "str": "a string", "float": 1234.0, "int": 1234, }, ) self.assertEqual(e.name, "torch.monitor.TestEvent") self.assertIsNotNone(e.timestamp) self.assertIsNotNone(e.data) log_event(e)
def test_event_handler(self) -> None: events = [] def handler(event: Event) -> None: events.append(event) handle = register_event_handler(handler) e = Event( name="torch.monitor.TestEvent", timestamp=datetime.now(), data={}, ) log_event(e) self.assertEqual(len(events), 1) self.assertEqual(events[0], e) log_event(e) self.assertEqual(len(events), 2) unregister_event_handler(handle) log_event(e) self.assertEqual(len(events), 2)