-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
externalize: Dont register the copied tasks #1975
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# Copyright 2017 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 | ||
|
||
import luigi | ||
from luigi.task_register import (Register, | ||
TaskClassNotFoundException, | ||
TaskClassAmbigiousException, | ||
) | ||
|
||
|
||
class TaskRegisterTest(LuigiTestCase): | ||
|
||
def test_externalize_taskclass(self): | ||
with self.assertRaises(TaskClassNotFoundException): | ||
Register.get_task_cls('scooby.Doo') | ||
|
||
class Task1(luigi.Task): | ||
@classmethod | ||
def get_task_family(cls): | ||
return "scooby.Doo" | ||
|
||
self.assertEqual(Task1, Register.get_task_cls('scooby.Doo')) | ||
|
||
class Task2(luigi.Task): | ||
@classmethod | ||
def get_task_family(cls): | ||
return "scooby.Doo" | ||
|
||
with self.assertRaises(TaskClassAmbigiousException): | ||
Register.get_task_cls('scooby.Doo') | ||
|
||
class Task3(luigi.Task): | ||
@classmethod | ||
def get_task_family(cls): | ||
return "scooby.Doo" | ||
|
||
# There previously was a rare bug where the third installed class could | ||
# "undo" class ambiguity. | ||
with self.assertRaises(TaskClassAmbigiousException): | ||
Register.get_task_cls('scooby.Doo') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -206,6 +206,26 @@ def run(self): | |
self.assertIsNotNone(MyTask.run) # Check immutability | ||
self.assertIsNotNone(MyTask().run) # Check immutability | ||
|
||
def test_externalize_doesnt_affect_the_registry(self): | ||
class MyTask(luigi.Task): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just externalize luigi.Task in these tests? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think of two reasons:
|
||
pass | ||
reg_orig = luigi.task_register.Register._get_reg() | ||
luigi.task.externalize(MyTask) | ||
reg_afterwards = luigi.task_register.Register._get_reg() | ||
self.assertEqual(reg_orig, reg_afterwards) | ||
|
||
def test_can_uniquely_command_line_parse(self): | ||
class MyTask(luigi.Task): | ||
pass | ||
# This first check is just an assumption rather than assertion | ||
self.assertTrue(self.run_locally(['MyTask'])) | ||
luigi.task.externalize(MyTask) | ||
# Now we check we don't encounter "ambiguous task" issues | ||
self.assertTrue(self.run_locally(['MyTask'])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the idea here is that MyTask is still not external? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah... Yea this code is hard to read. I'm adding a comment. It tests that |
||
# We do this once again, is there previously was a bug like this. | ||
luigi.task.externalize(MyTask) | ||
self.assertTrue(self.run_locally(['MyTask'])) | ||
|
||
|
||
class TaskNamespaceTest(LuigiTestCase): | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
from helpers import LuigiTestCase | ||
from helpers import LuigiTestCase, RunOnceTask | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like you accidentally pulled some unrelated changes to util_test into this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually not completely unrelated. Much of the machinery here is relying on the Registry that got changed here. I'll amend the commit message saying I intentionally added these tests for this change set. |
||
|
||
import luigi | ||
import luigi.task | ||
|
@@ -23,25 +23,25 @@ | |
|
||
class BasicsTest(LuigiTestCase): | ||
|
||
def test_requries(self): | ||
class BaseTask(luigi.Task): | ||
def test_task_ids_using_requries(self): | ||
class ParentTask(luigi.Task): | ||
my_param = luigi.Parameter() | ||
luigi.namespace('blah') | ||
|
||
@requires(BaseTask) | ||
@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(BaseTask(my_param='hello'), luigi.task.flatten(child_task.requires())) | ||
self.assertIn(ParentTask(my_param='hello'), luigi.task.flatten(child_task.requires())) | ||
|
||
def test_requries_weird_way(self): | ||
def test_task_ids_using_requries_2(self): | ||
# Here we use this decorator in a unnormal way. | ||
# But it should still work. | ||
class BaseTask(luigi.Task): | ||
class ParentTask(luigi.Task): | ||
my_param = luigi.Parameter() | ||
decorator = requires(BaseTask) | ||
decorator = requires(ParentTask) | ||
luigi.namespace('blah') | ||
|
||
class ChildTask(luigi.Task): | ||
|
@@ -50,4 +50,31 @@ class ChildTask(luigi.Task): | |
ChildTask = decorator(ChildTask) | ||
child_task = ChildTask(my_param='hello') | ||
self.assertEqual(str(child_task), 'blah.ChildTask(my_param=hello)') | ||
self.assertIn(BaseTask(my_param='hello'), luigi.task.flatten(child_task.requires())) | ||
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did the use case in #822 go away?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, since #1182, the Parameter class became (more) immutable, and a lots of these random corner-cases bugs went away. There were also test cases added with the fix for #822, and I assume green Travis means they still pass. :)