forked from spotify/luigi
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutil_test.py
80 lines (66 loc) · 2.79 KB
/
util_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
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
#
# Copyright 2016 VNG Corporation
#
# 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 LuigiTestCase, RunOnceTask
import luigi
import luigi.task
from luigi.util import requires
class BasicsTest(LuigiTestCase):
def test_task_ids_using_requries(self):
class ParentTask(luigi.Task):
my_param = luigi.Parameter()
luigi.namespace('blah')
@requires(ParentTask)
class ChildTask(luigi.Task):
pass
luigi.namespace('')
child_task = ChildTask(my_param='hello')
self.assertEqual(str(child_task), 'blah.ChildTask(my_param=hello)')
self.assertIn(ParentTask(my_param='hello'), luigi.task.flatten(child_task.requires()))
def test_task_ids_using_requries_2(self):
# Here we use this decorator in a unnormal way.
# But it should still work.
class ParentTask(luigi.Task):
my_param = luigi.Parameter()
decorator = requires(ParentTask)
luigi.namespace('blah')
class ChildTask(luigi.Task):
pass
luigi.namespace('')
ChildTask = decorator(ChildTask)
child_task = ChildTask(my_param='hello')
self.assertEqual(str(child_task), 'blah.ChildTask(my_param=hello)')
self.assertIn(ParentTask(my_param='hello'), luigi.task.flatten(child_task.requires()))
def _setup_parent_and_child(self):
class ParentTask(luigi.Task):
my_parameter = luigi.Parameter()
class_variable = 'notset'
def run(self):
self.__class__.class_variable = self.my_parameter
def complete(self):
return self.class_variable == 'actuallyset'
@requires(ParentTask)
class ChildTask(RunOnceTask):
pass
return ParentTask
def test_requires_has_effect_run_child(self):
ParentTask = self._setup_parent_and_child()
self.assertTrue(self.run_locally_split('ChildTask --my-parameter actuallyset'))
self.assertEqual(ParentTask.class_variable, 'actuallyset')
def test_requires_has_effect_run_parent(self):
ParentTask = self._setup_parent_and_child()
self.assertTrue(self.run_locally_split('ParentTask --my-parameter actuallyset'))
self.assertEqual(ParentTask.class_variable, 'actuallyset')