Skip to content

Commit 9f2b024

Browse files
committed
Collector: collection_args - add tests
This shows that we can use external data inside collector hooks
1 parent e49b133 commit 9f2b024

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

tests/fixtures/config/hooks/api_collector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BasicSceneCollector(HookBaseClass):
1919
A basic collector that handles files and general objects.
2020
"""
2121

22-
def process_current_session(self, settings, parent_item):
22+
def process_current_session(self, settings, parent_item, collection_args):
2323
"""
2424
Analyzes the current scene open in a DCC and parents a subtree of items
2525
under the parent_item passed in.
@@ -45,3 +45,6 @@ def process_current_session(self, settings, parent_item):
4545
)
4646

4747
parent_item.local_properties.collector_property = "collector_property"
48+
49+
if collection_args:
50+
parent_item.properties.update(collection_args)

tests/fixtures/config/hooks/collector.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BasicSceneCollector(HookBaseClass):
1919
A basic collector that handles files and general objects.
2020
"""
2121

22-
def process_current_session(self, settings, parent_item):
22+
def process_current_session(self, settings, parent_item, collection_args):
2323
"""
2424
Analyzes the current scene open in a DCC and parents a subtree of items
2525
under the parent_item passed in.

tests/test_manager.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,35 @@ def test_nodes():
154154

155155
with self.assertRaisesRegex(Exception, "Test error!"):
156156
self.manager.publish(test_nodes())
157+
158+
def test_collection_args(self):
159+
"""
160+
Ensures the collection_args propagation to the collector hook
161+
"""
162+
collection_args = {
163+
"flag_1": True,
164+
"flag_2": False,
165+
"flag_3": 10,
166+
}
167+
# if collection_args is provided to collect_session
168+
# api_collector adds collection_args to root item properties
169+
# this is done only for test purposes
170+
171+
# without collection_args provided,
172+
# root_item properties do not contain collection_args
173+
self.manager.collect_session()
174+
root_item = self.manager.tree.root_item
175+
root_item_properties = root_item.properties
176+
self.assertEqual('flag_1' not in root_item_properties, True)
177+
self.assertEqual('flag_2' not in root_item_properties, True)
178+
self.assertEqual('flag_3' not in root_item_properties, True)
179+
180+
# now we provide collection_args
181+
self.manager.collect_session(collection_args)
182+
183+
# so properties should be filled
184+
self.assertEqual(root_item.properties["flag_1"], collection_args["flag_1"])
185+
self.assertEqual(root_item.properties["flag_2"], collection_args["flag_2"])
186+
self.assertEqual(root_item.properties["flag_3"], collection_args["flag_3"])
187+
188+

0 commit comments

Comments
 (0)