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