def test_indexed_event_merge(self): """test merging indexed events.""" index = '1h-396206' event1 = IndexedEvent(index, {'a': 5, 'b': 6}) event2 = IndexedEvent(index, freeze({'c': 2})) # pmap for coverage merged = Event.merge([event1, event2]) self.assertEqual(merged[0].get('a'), 5) self.assertEqual(merged[0].get('b'), 6) self.assertEqual(merged[0].get('c'), 2) # bad merges # wrong length/etc self.assertEqual(Event.merge({}), []) self.assertEqual(Event.merge([]), [])
def test_time_range_event_merge(self): """Test merging.""" t_range = TimeRange(self.test_begin_ts, self.test_end_ts) tr1 = TimeRangeEvent(t_range, dict(a=5, b=6)) tr2 = TimeRangeEvent(t_range, dict(c=2)) merged = Event.merge([tr1, tr2]) self.assertEqual(merged[0].get('a'), 5) self.assertEqual(merged[0].get('b'), 6) self.assertEqual(merged[0].get('c'), 2)
def test_nested_merge(self): """trigger merging nested data.""" # pylint: disable=invalid-name e_ts = aware_utcnow() e1 = Event(e_ts, dict(payload=dict(a=1))) e2 = Event(e_ts, dict(payload=dict(b=2))) emerge = Event.merge([e1, e2]) self.assertEqual(emerge[0].get('payload.a'), 1) self.assertEqual(emerge[0].get('payload.b'), 2)
def test_event_merge(self): """Test Event.merge()/merge_events()""" # same timestamp, different keys # good ones, same ts, different payloads pay1 = dict(foo='bar', baz='quux') ev1 = Event(self.aware_ts, pay1) pay2 = dict(foo2='bar', baz2='quux') ev2 = Event(self.aware_ts, pay2) merged = Event.merge([ev1, ev2]) self.assertEqual(set(thaw(merged[0].data())), set(dict(pay1, **pay2)))