A mock Comm object. Can be used to inspect calls to Comm's open/send/close methods.
| 4 | from ipywidgets import Widget |
| 5 | |
| 6 | class MockComm(Comm): |
| 7 | """A mock Comm object. |
| 8 | |
| 9 | Can be used to inspect calls to Comm's open/send/close methods. |
| 10 | """ |
| 11 | comm_id = 'a-b-c-d' |
| 12 | kernel = 'Truthy' |
| 13 | |
| 14 | def __init__(self, *args, **kwargs): |
| 15 | self.log_open = [] |
| 16 | self.log_send = [] |
| 17 | self.log_close = [] |
| 18 | super(MockComm, self).__init__(*args, **kwargs) |
| 19 | |
| 20 | def open(self, *args, **kwargs): |
| 21 | self.log_open.append((args, kwargs)) |
| 22 | |
| 23 | def send(self, *args, **kwargs): |
| 24 | self.log_send.append((args, kwargs)) |
| 25 | |
| 26 | def close(self, *args, **kwargs): |
| 27 | self.log_close.append((args, kwargs)) |
| 28 | |
| 29 | _widget_attrs = {} |
| 30 | undefined = object() |