コード例 #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_custom_aggregator_function(self, setUp, project):
        # Testing aggregator function returning aggregates of 1
        def helper_aggregator_function(jobs):
            for job in jobs:
                yield (job, )

        aggregate_instance = aggregator(helper_aggregator_function)
        aggregate_store = aggregate_instance._create_AggregateStore(project)
        aggregate_job_manual = helper_aggregator_function(project)
        assert tuple(aggregate_job_manual) == tuple(aggregate_store.values())

        # Testing aggregator function returning aggregates of all the jobs
        aggregate_instance = aggregator(lambda jobs: [jobs])
        aggregate_store = aggregate_instance._create_AggregateStore(project)
        assert (tuple(project), ) == tuple(aggregate_store.values())
コード例 #3
0
    def test_sort_by_callable(self, setUp, project):
        def keyfunction(job):
            return job.sp.i

        helper_sort = partial(sorted, key=keyfunction)
        aggregate_instance = aggregator(sort_by=keyfunction)
        aggregate_store = aggregate_instance._create_AggregateStore(project)
        assert (tuple(helper_sort(project)), ) == tuple(
            aggregate_store.values())
コード例 #4
0
 def test_contains(self, setUp, project):
     jobs = tuple(project)
     aggregator_instance = aggregator()._create_AggregateStore(project)
     default_aggregator = aggregator.groupsof(1)._create_AggregateStore(
         project)
     # Test for an aggregate of all jobs
     assert get_aggregate_id(jobs) in aggregator_instance
     assert get_aggregate_id(jobs) not in default_aggregator
     # Test for an aggregate of single job
     assert not jobs[0].get_id() in aggregator_instance
     assert jobs[0].get_id() in default_aggregator
コード例 #5
0
 def test_get_invalid_id(self, setUp, project):
     jobs = tuple(project)
     aggregator_instance = aggregator()._create_AggregateStore(project)
     default_aggregator = aggregator.groupsof(1)._create_AggregateStore(
         project)
     # Test for an aggregate of single job for aggregator instance
     with pytest.raises(LookupError):
         aggregator_instance[get_aggregate_id((jobs[0], ))]
     # Test for an aggregate of all jobs for default aggregator
     with pytest.raises(LookupError):
         default_aggregator[get_aggregate_id(jobs)]
コード例 #6
0
 def test_default_init(self):
     aggregate_instance = aggregator()
     # Ensure that all values are converted to tuples
     test_values = [(1, 2, 3, 4, 5), (), [1, 2, 3, 4, 5], []]
     assert not aggregate_instance._is_default_aggregator
     assert aggregate_instance._sort_by is None
     assert aggregate_instance._sort_ascending
     assert aggregate_instance._select is None
     for value in test_values:
         assert list(aggregate_instance._aggregator_function(value)) == [
             tuple(value)
         ]
コード例 #7
0
 def test_invalid_call(self):
     call_params = ["str", 1, None]
     for param in call_params:
         with pytest.raises(TypeError):
             aggregator()(param)
コード例 #8
0
 def test_invalid_select(self):
     selectors = ["str", 1, []]
     for _select in selectors:
         with pytest.raises(TypeError):
             aggregator(select=_select)
コード例 #9
0
 def test_invalid_sort_by(self):
     sort_list = [1, {}]
     for sort in sort_list:
         with pytest.raises(TypeError):
             aggregator(sort_by=sort)
コード例 #10
0
 def test_invalid_aggregator_function(self, setUp, project):
     aggregator_functions = ["str", 1, {}]
     for aggregator_function in aggregator_functions:
         with pytest.raises(TypeError):
             aggregator(aggregator_function)
コード例 #11
0
 def test_sort_descending(self, setUp, project):
     helper_sort = partial(sorted, key=lambda job: job.sp.i, reverse=True)
     aggregate_instance = aggregator(sort_by="i", sort_ascending=False)
     aggregate_store = aggregate_instance._create_AggregateStore(project)
     assert (tuple(helper_sort(project)), ) == tuple(
         aggregate_store.values())
コード例 #12
0
 def test_sort_by(self, setUp, project):
     helper_sort = partial(sorted, key=lambda job: job.sp.i)
     aggregate_instance = aggregator(sort_by="i")
     aggregate_store = aggregate_instance._create_AggregateStore(project)
     assert (tuple(helper_sort(project)), ) == tuple(
         aggregate_store.values())
コード例 #13
0
 def test_call_without_decorator(self):
     aggregate_instance = aggregator()
     with pytest.raises(TypeError):
         aggregate_instance()