self.assertEqual(len(errors), 1) self.assertIsInstance(errors[0], RuntimeError) class FakeFile(list): def write(self, bytes): self.append(bytes) def flush(self): pass IOBase.register(FakeFile) class EvilStr: def __str__(self): 1 // 0 class EvilRepr: def __str__(self): return "Happy Evil Repr" def __repr__(self):
publisher.msg("Hello!") self.assertEqual(set(publisher.observers), set([logError, fail])) self.assertEqual(len(errors), 1) self.assertIsInstance(errors[0], RuntimeError) class FakeFile(list): def write(self, bytes): self.append(bytes) def flush(self): pass IOBase.register(FakeFile) # type: ignore[attr-defined] class EvilStr: def __str__(self) -> str: return str(1 // 0) class EvilRepr: def __str__(self) -> str: return "Happy Evil Repr" def __repr__(self) -> str: return str(1 // 0)
def truncate(self, size=None): return self.get_underlying_io().truncate() def writable(self): return self.get_underlying_io().writable() def writelines(self, lines): return self.get_underlying_io().writelines(lines) def __del__(self): io = self.get_underlying_io() cls = type(io) cls.__del__(io) IOBase.register(IUserIOBase) class UserIOBase(IUserIOBase): def __init__(self, io): self.__io = io def get_underlying_io(self): return self.__io class IUserIOBase__aspect(IUserIOBase): @abstractmethod def before_io(self): raise NotImplementedError