コード例 #1
0
def list_of_aggregators():
    def helper_default_aggregator_function(jobs):
        yield tuple(jobs)

    def helper_non_default_aggregator_function(jobs):
        for job in jobs:
            yield (job, )

    # The below list contains 14 distinct aggregator objects and some duplicates.
    return [
        _aggregator(),
        _aggregator(),
        _aggregator(helper_default_aggregator_function),
        _aggregator(helper_non_default_aggregator_function),
        _aggregator(helper_non_default_aggregator_function),
        _aggregator.groupsof(1),
        _aggregator.groupsof(1),
        _aggregator.groupsof(2),
        _aggregator.groupsof(3),
        _aggregator.groupsof(4),
        _aggregator.groupby("even"),
        _aggregator.groupby("even"),
        _aggregator.groupby("half", -1),
        _aggregator.groupby("half", -1),
        _aggregator.groupby(["half", "even"], default=[-1, -1]),
    ]
コード例 #2
0
 def test_groupby_with_default_key_for_string(self, setUp, project):
     aggregate_instance = _aggregator.groupby("half", default=-1)
     aggregate_store = aggregate_instance._create_AggregateStore(project)
     for aggregate in aggregate_store.values():
         half = aggregate[0].sp.get("half", -1)
         assert all(half == job.sp.get("half", -1) for job in aggregate)
     assert len(aggregate_store) == 6
コード例 #3
0
 def test_groupby_with_valid_string_key(self, setUp, project):
     aggregate_instance = _aggregator.groupby("even")
     aggregate_store = aggregate_instance._create_AggregateStore(project)
     for aggregate in aggregate_store.values():
         even = aggregate[0].sp.even
         assert all(even == job.sp.even for job in aggregate)
     assert len(aggregate_store) == 2
コード例 #4
0
    def test_groupby_with_invalid_callable_key(self, setUp, project):
        def keyfunction(job):
            return job.sp["half"]

        aggregate_instance = _aggregator.groupby(keyfunction)
        with pytest.raises(KeyError):
            # We will attempt to generate aggregates but will fail in
            # doing so due to the invalid key
            aggregate_instance._create_AggregateStore(project)
コード例 #5
0
    def test_groupby_with_callable_key(self, setUp, project):
        def keyfunction(job):
            return job.sp["even"]

        aggregate_instance = _aggregator.groupby(keyfunction)
        aggregate_store = aggregate_instance._create_AggregateStore(project)
        for aggregate in aggregate_store.values():
            even = aggregate[0].sp.even
            assert all(even == job.sp.even for job in aggregate)
        assert len(aggregate_store) == 2
コード例 #6
0
 def test_groupby_with_valid_default_key_for_Iterable(self, setUp, project):
     aggregate_instance = _aggregator.groupby(["half", "even"],
                                              default=[-1, -1])
     aggregate_store = aggregate_instance._create_AggregateStore(project)
     for aggregate in aggregate_store.values():
         half = aggregate[0].sp.get("half", -1)
         even = aggregate[0].sp.get("even", -1)
         assert all(half == job.sp.get("half", -1)
                    and even == job.sp.get("even", -1) for job in aggregate)
     assert len(aggregate_store) == 6
コード例 #7
0
 def test_groupby_with_invalid_Iterable_key(self, setUp, project):
     aggregate_instance = _aggregator.groupby(["half", "even"])
     with pytest.raises(KeyError):
         # We will attempt to generate aggregates but will fail in
         # doing so due to the invalid keys
         aggregate_instance._create_AggregateStore(project)
コード例 #8
0
 def test_groupby_with_Iterable_key(self, setUp, project):
     aggregate_instance = _aggregator.groupby(["i", "even"])
     aggregate_store = aggregate_instance._create_AggregateStore(project)
     # No aggregation takes place hence this means we don't need to check
     # whether all the aggregate members are equivalent.
     assert len(aggregate_store) == 10
コード例 #9
0
 def test_groupby_with_invalid_string_key(self, setUp, project):
     aggregate_instance = _aggregator.groupby("invalid_key")
     with pytest.raises(KeyError):
         # We will attempt to generate aggregates but will fail in
         # doing so due to the invalid key
         aggregate_instance._create_AggregateStore(project)
コード例 #10
0
 def test_groupby_with_invalid_length_default_key_for_Iterable(self):
     with pytest.raises(ValueError):
         _aggregator.groupby(["half", "even"], default=[-1, -1, -1])
コード例 #11
0
 def test_groupby_with_invalid_type_default_key_for_Iterable(self):
     with pytest.raises(TypeError):
         _aggregator.groupby(["half", "even"], default=-1)
コード例 #12
0
 def test_groupby_with_valid_type_default_for_Iterable(self):
     _aggregator.groupby(["half", "even"], default=[-1, -1])
コード例 #13
0
 def test_group_by_invalid_key(self):
     with pytest.raises(TypeError):
         _aggregator.groupby(1)