Skip to content

Commit

Permalink
Add tests for task.to_str_params()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hi-king committed Jan 1, 2025
1 parent c6317dc commit a6c8ade
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gokart/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def make_unique_id(self) -> str:
return unique_id

def to_str_params(self, only_significant=False, only_public=False):
if only_significant == True and only_public == False:
if only_significant and (not only_public):
# cache to_str_params to avoid too slow task creation of deep task tree
# e.g. gokart.build(RecursiveTask(dep=RecursiveTask(dep=RecursiveTask(dep=HelloWorldTask())))) takes O(n*n) to_str_params calls
if self._str_params_cache is not None:
Expand Down
11 changes: 11 additions & 0 deletions test/test_task_on_kart.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,17 @@ def test_serialize_and_deserialize_default_values(self):
deserialized: gokart.TaskOnKart = luigi.task_register.load_task(None, task.get_task_family(), task.to_str_params())
self.assertDictEqual(task.to_str_params(), deserialized.to_str_params())

def test_to_str_params_changes_on_values_and_flags(self):
class _DummyTaskWithParams(gokart.TaskOnKart):
task_namespace = __name__
param: str = luigi.Parameter()

t1 = _DummyTaskWithParams(param='a')
self.assertEqual(t1.to_str_params(), t1.to_str_params()) # cache
self.assertEqual(t1.to_str_params(), _DummyTaskWithParams(param='a').to_str_params()) # same value
self.assertNotEqual(t1.to_str_params(), _DummyTaskWithParams(param='b').to_str_params()) # different value
self.assertNotEqual(t1.to_str_params(), t1.to_str_params(only_significant=True))

def test_should_lock_run_when_set(self):
class _DummyTaskWithLock(gokart.TaskOnKart):
def run(self):
Expand Down

0 comments on commit a6c8ade

Please sign in to comment.