示例#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)