"""
INFO = 'INFO'
ERROR = 'ERROR'
- regex_v1 = re.compile(r'^([^ ]+) ([^:]+):([^ ]+) \[([^\]]+)\] "(.*)"$')
+ regex_v1 = re.compile(r'^([^ ]+) ([^:]+):([^ ]+) \[([^\]]+)\] "((?:.|\n)*)"$', re.MULTILINE)
def __init__(self, created: Union[str, datetime.datetime], kind, subject, level, message):
if isinstance(created, str):
created = self.created.strftime(DATEFMT)
return f'{created} {self.kind_subject()} [{self.level}] "{self.message}"'
-
@classmethod
@handle_type_error
def from_json(cls, data) -> "OrchestratorEvent":
return cls(*match.groups())
raise ValueError(f'Unable to match: "{data}"')
+ def __eq__(self, other):
+ if not isinstance(other, OrchestratorEvent):
+ return False
+
+ return self.created == other.created and self.kind == other.kind \
+ and self.subject == other.subject and self.message == other.message
+
def _mk_orch_methods(cls):
# Needs to be defined outside of for.
from __future__ import absolute_import
+import datetime
import json
import pytest
assert to_format([object], 'yaml', True, cls) == y
j = json.loads(to_format(object, 'json', False, cls))
- assert to_format(cls.from_json(j), 'yaml', False, cls) == y
\ No newline at end of file
+ assert to_format(cls.from_json(j), 'yaml', False, cls) == y
+
+
+def test_event_multiline():
+ from .._interface import OrchestratorEvent
+ e = OrchestratorEvent(datetime.datetime.utcnow(), 'service', 'subject', 'ERROR', 'message')
+ assert OrchestratorEvent.from_json(e.to_json()) == e
+
+ e = OrchestratorEvent(datetime.datetime.utcnow(), 'service', 'subject', 'ERROR', 'multiline\nmessage')
+ assert OrchestratorEvent.from_json(e.to_json()) == e