Add tests for EventObserver

This commit is contained in:
Alex Root Junior 2019-11-24 01:03:47 +02:00
parent caa7eeab41
commit fd6e78ddf7
2 changed files with 114 additions and 1 deletions

View file

@ -1,5 +1,6 @@
from __future__ import annotations
import copy
from typing import TYPE_CHECKING, Any, Dict, List, Type
from pydantic import ValidationError
@ -39,10 +40,12 @@ class EventObserver:
async def trigger(self, *args, **kwargs):
for handler in self.handlers:
kwargs_copy = copy.copy(kwargs)
result, data = await handler.check(*args, **kwargs)
if result:
kwargs_copy.update(data)
try:
yield await handler.call(*args, **data)
yield await handler.call(*args, **kwargs_copy)
except SkipHandler:
continue