Skip to content

Commit

Permalink
Merge pull request #95 from mpozpnd/generate_default_target
Browse files Browse the repository at this point in the history
Generate default target automatically
  • Loading branch information
nishiba authored Sep 28, 2019
2 parents 32bc44e + fda4336 commit 572a150
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gokart/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ def __init__(self, *args, **kwargs):
super(TaskOnKart, self).__init__(*args, **kwargs)
self._rerun_state = self.rerun

def output(self):
file_path = self.__module__.replace(".", "/")
return self.make_target(os.path.join(file_path, f"{type(self).__name__}.pkl"))

@classmethod
def _add_configuration(cls, kwargs, section):
config = luigi.configuration.get_config()
Expand Down
16 changes: 16 additions & 0 deletions test/test_task_on_kart.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,21 @@ class _DummyTask(gokart.TaskOnKart):
param = luigi.IntParameter(default=1)
list_param = luigi.ListParameter(default=['a', 'b'])
bool_param = luigi.BoolParameter()
def output(self):
return None


class _DummyTaskA(gokart.TaskOnKart):
task_namespace = __name__
def output(self):
return None


@inherits(_DummyTaskA)
class _DummyTaskB(gokart.TaskOnKart):
task_namespace = __name__
def output(self):
return None

def requires(self):
return self.clone(_DummyTaskA)
Expand All @@ -34,10 +40,14 @@ def requires(self):
@inherits(_DummyTaskB)
class _DummyTaskC(gokart.TaskOnKart):
task_namespace = __name__
def output(self):
return None

def requires(self):
return self.clone(_DummyTaskB)

class _DummyTaskD(gokart.TaskOnKart):
task_namespace = __name__

class TaskTest(unittest.TestCase):
def setUp(self):
Expand Down Expand Up @@ -104,6 +114,12 @@ def test_complete_when_modification_time_equals_output(self):
task.output = MagicMock(return_value=output_target)
self.assertTrue(task.complete())

def test_default_target(self):
task = _DummyTaskD()
default_target = task.output()
self.assertIsInstance(default_target, SingleFileTarget)
self.assertEqual(f'./resources/test/test_task_on_kart/_DummyTaskD_{task.task_unique_id}.pkl', default_target._target.path)

def test_make_target(self):
task = _DummyTask()
target = task.make_target('test.txt')
Expand Down

0 comments on commit 572a150

Please sign in to comment.