Skip to content

Commit

Permalink
Fix evaluation order: config file follows cmdline (#133)
Browse files Browse the repository at this point in the history
* ✅ test for evaluation order

* 🐛 fix evaluation_order. config file follows cmdline
  • Loading branch information
Hi-king authored Jul 31, 2020
1 parent a95532d commit 4717db9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 0 additions & 1 deletion gokart/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class TaskOnKart(luigi.Task):
fix_random_seed_value = luigi.IntParameter(default=None, description='Fix random seed method value.', significant=False)

def __init__(self, *args, **kwargs):
self._add_configuration(kwargs, self.get_task_family())
self._add_configuration(kwargs, 'TaskOnKart')
# 'This parameter is dumped into "workspace_directory/log/task_log/" when this task finishes with success.'
self.task_log = dict()
Expand Down
18 changes: 18 additions & 0 deletions test/test_task_on_kart.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,24 @@ def test_add_configuration(self, mock_config: MagicMock):
self.assertEqual(['c', 'd'], list(kwargs['list_param']))
self.assertEqual(True, kwargs['bool_param'])

@patch('luigi.cmdline_parser.CmdlineParser.get_instance')
def test_add_cofigureation_evaluation_order(self, mock_cmdline: MagicMock):
"""
in case TaskOnKart._add_configuration will break evaluation order
@see https://luigi.readthedocs.io/en/stable/parameters.html#parameter-resolution-order
"""
class DummyTaskAddConfiguration(gokart.TaskOnKart):
aa = luigi.IntParameter()

luigi.configuration.get_config().set(f'DummyTaskAddConfiguration', 'aa', '3')
mock_cmdline.return_value = luigi.cmdline_parser.CmdlineParser(['DummyTaskAddConfiguration'])
self.assertEqual(DummyTaskAddConfiguration().aa, 3)

mock_cmdline.return_value = luigi.cmdline_parser.CmdlineParser(
['DummyTaskAddConfiguration', '--DummyTaskAddConfiguration-aa', '2'])
self.assertEqual(DummyTaskAddConfiguration().aa, 2)


def test_load_list_of_list_pandas(self):
task = _DummyTask()
task.load = MagicMock(return_value=[pd.DataFrame(dict(a=[1])), [pd.DataFrame(dict(a=[2])), pd.DataFrame(dict(a=[3]))]])
Expand Down

0 comments on commit 4717db9

Please sign in to comment.