@@ -82,7 +82,7 @@ def test_set_take_not_found_raises_error(self, mock_get_doc: Mock):
8282 mock_take_a .GetChildren .return_value = []
8383
8484 mock_take_data = Mock ()
85- mock_take_data .GetCurrentTake .return_value = mock_main_take
85+ mock_take_data .GetMainTake .return_value = mock_main_take
8686 mock_main_take .GetChildren .return_value = [mock_take_a ]
8787
8888 mock_doc = Mock ()
@@ -109,7 +109,7 @@ def test_set_take_found_sets_take(self, mock_get_doc: Mock):
109109 mock_take_a .GetChildren .return_value = []
110110
111111 mock_take_data = Mock ()
112- mock_take_data .GetCurrentTake .return_value = mock_main_take
112+ mock_take_data .GetMainTake .return_value = mock_main_take
113113 mock_main_take .GetChildren .return_value = [mock_take_a ]
114114
115115 mock_doc = Mock ()
@@ -119,6 +119,50 @@ def test_set_take_found_sets_take(self, mock_get_doc: Mock):
119119 handler .set_take ({"take" : "A" })
120120 mock_take_data .SetCurrentTake .assert_called_once_with (mock_take_a )
121121
122+ @patch (
123+ "deadline.cinema4d_adaptor.Cinema4DClient.cinema4d_handler.c4d.documents.GetActiveDocument"
124+ )
125+ def test_set_take_from_non_parent_current_take (self , mock_get_doc : Mock ):
126+ """Verify that set_take finds and sets a take even if the active take is not an ancestor of the target take."""
127+ handler = Cinema4DHandler (mock_map_path )
128+
129+ # Hierarchy:
130+ # Main
131+ # / \
132+ # Take A Take B
133+ # |
134+ # Take A1 (current active take)
135+ mock_main_take = Mock ()
136+ mock_main_take .GetName .return_value = "Main"
137+
138+ mock_take_a = Mock ()
139+ mock_take_a .GetName .return_value = "Take A"
140+
141+ mock_take_a1 = Mock ()
142+ mock_take_a1 .GetName .return_value = "Take A1"
143+ mock_take_a1 .GetChildren .return_value = []
144+
145+ mock_take_b = Mock ()
146+ mock_take_b .GetName .return_value = "Take B"
147+ mock_take_b .GetChildren .return_value = []
148+
149+ mock_main_take .GetChildren .return_value = [mock_take_a , mock_take_b ]
150+ mock_take_a .GetChildren .return_value = [mock_take_a1 ]
151+
152+ mock_take_data = Mock ()
153+ # Current active take is Take A1 (which has no children)
154+ mock_take_data .GetCurrentTake .return_value = mock_take_a1
155+ # GetMainTake returns Main take, which roots the entire hierarchy
156+ mock_take_data .GetMainTake .return_value = mock_main_take
157+
158+ mock_doc = Mock ()
159+ mock_doc .GetTakeData .return_value = mock_take_data
160+ mock_get_doc .return_value = mock_doc
161+
162+ # Setting take to "Take B" should succeed because search starts from GetMainTake()
163+ handler .set_take ({"take" : "Take B" })
164+ mock_take_data .SetCurrentTake .assert_called_once_with (mock_take_b )
165+
122166
123167class TestShouldCacheText :
124168 """Tests for the use_cached_text method"""
0 commit comments