Exemple #1
0
 def test_event_map_no_key_map_all(self):
     """Test Event.map() with no field key - it will map everything"""
     result = Event.map(self._get_event_series())
     self.assertEqual(set(result),
                      set({'in': [2, 4, 6, 8],
                           'name': ['source1', 'source1', 'source1', 'source1'],
                           'out': [11, 13, 15, 18]}))
Exemple #2
0
 def test_event_map_multi_key(self):
     """Test Event.map() with multiple field keys."""
     result = Event.map(self._get_event_series(), ['in', 'out'])
     self.assertEqual(set(result),
                      set({
                          'out': [11, 13, 15, 18],
                          'in': [2, 4, 6, 8]
                      }))
Exemple #3
0
    def test_event_map_function_arg_and_reduce(self):  # pylint: disable=invalid-name
        """Test Event.map() with a custom function and Event.reduce()"""
        def map_sum(event):  # pylint: disable=missing-docstring
            # return 'sum', event.get('in') + event.get('out')
            return dict(sum=event.get('in') + event.get('out'))
        result = Event.map(self._get_event_series(), map_sum)
        self.assertEqual(set(result), set({'sum': [13, 17, 21, 26]}))

        res = Event.reduce(result, Functions.avg())
        self.assertEqual(set(res), set({'sum': 19.25}))
Exemple #4
0
 def test_event_map_no_key_map_all(self):
     """Test Event.map() with no field key - it will map everything"""
     result = Event.map(self._get_event_series())
     self.assertEqual(
         set(result),
         set({
             'in': [2, 4, 6, 8],
             'name': ['source1', 'source1', 'source1', 'source1'],
             'out': [11, 13, 15, 18]
         }))
Exemple #5
0
    def test_event_map_function_arg_and_reduce(self):  # pylint: disable=invalid-name
        """Test Event.map() with a custom function and Event.reduce()"""
        def map_sum(event):  # pylint: disable=missing-docstring
            # return 'sum', event.get('in') + event.get('out')
            return dict(sum=event.get('in') + event.get('out'))

        result = Event.map(self._get_event_series(), map_sum)
        self.assertEqual(set(result), set({'sum': [13, 17, 21, 26]}))

        res = Event.reduce(result, Functions.avg())
        self.assertEqual(set(res), set({'sum': 19.25}))
Exemple #6
0
 def test_event_map_multi_key(self):
     """Test Event.map() with multiple field keys."""
     result = Event.map(self._get_event_series(), ['in', 'out'])
     self.assertEqual(set(result), set({'out': [11, 13, 15, 18], 'in': [2, 4, 6, 8]}))
Exemple #7
0
    def test_event_map_single_key(self):
        """Test Event.map() with single field key"""

        result = Event.map(self._get_event_series(), 'in')
        self.assertEqual(set(result), set({'in': [2, 4, 6, 8]}))
Exemple #8
0
    def test_event_map_single_key(self):
        """Test Event.map() with single field key"""

        result = Event.map(self._get_event_series(), 'in')
        self.assertEqual(set(result), set({'in': [2, 4, 6, 8]}))