forked from spotify/luigi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtask_bulk_complete_test.py
73 lines (64 loc) · 2.36 KB
/
task_bulk_complete_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# -*- coding: utf-8 -*-
#
# Copyright 2012-2016 Spotify AB
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from helpers import unittest
from luigi import Task
from luigi import Parameter
from luigi.task import MixinNaiveBulkComplete
COMPLETE_TASKS = ["A", "B", "C"]
class MockTask(MixinNaiveBulkComplete, Task):
param_a = Parameter()
param_b = Parameter(default="Not Mandatory")
def complete(self):
return self.param_a in COMPLETE_TASKS
class MixinNaiveBulkCompleteTest(unittest.TestCase):
"""
Test that the MixinNaiveBulkComplete can handle
input as
- iterable of parameters (for single param tasks)
- iterable of parameter tuples (for multi param tasks)
- iterable of parameter dicts (for multi param tasks)
"""
def test_single_arg_list(self):
single_arg_list = ["A", "B", "x"]
expected_single_arg_list = set(
[p for p in single_arg_list if p in COMPLETE_TASKS]
)
self.assertEqual(
expected_single_arg_list,
set(MockTask.bulk_complete(single_arg_list))
)
def test_multiple_arg_tuple(self):
multiple_arg_tuple = (("A", "1"), ("B", "2"), ("X", "3"), ("C", "2"))
expected_multiple_arg_tuple = set(
[p for p in multiple_arg_tuple if p[0] in COMPLETE_TASKS]
)
self.assertEqual(
expected_multiple_arg_tuple,
set(MockTask.bulk_complete(multiple_arg_tuple))
)
def test_multiple_arg_dict(self):
multiple_arg_dict = (
{"param_a": "X", "param_b": "1"},
{"param_a": "C", "param_b": "1"}
)
expected_multiple_arg_dict = (
[p for p in multiple_arg_dict if p["param_a"] in COMPLETE_TASKS]
)
self.assertEqual(
expected_multiple_arg_dict,
MockTask.bulk_complete(multiple_arg_dict)
)