Skip to content

Commit

Permalink
Collector: collection_args - add tests
Browse files Browse the repository at this point in the history
This shows that we can use external data inside collector hooks
  • Loading branch information
aoblet committed Nov 7, 2018
1 parent b299df6 commit e23599d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tests/fixtures/config/hooks/api_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BasicSceneCollector(HookBaseClass):
A basic collector that handles files and general objects.
"""

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

parent_item.local_properties.collector_property = "collector_property"

if collection_args:
parent_item.properties.update(collection_args)
2 changes: 1 addition & 1 deletion tests/fixtures/config/hooks/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class BasicSceneCollector(HookBaseClass):
A basic collector that handles files and general objects.
"""

def process_current_session(self, settings, parent_item):
def process_current_session(self, settings, parent_item, collection_args):
"""
Analyzes the current scene open in a DCC and parents a subtree of items
under the parent_item passed in.
Expand Down
32 changes: 32 additions & 0 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,35 @@ def test_nodes():

with self.assertRaisesRegex(Exception, "Test error!"):
self.manager.publish(test_nodes())

def test_collection_args(self):
"""
Ensures that collection_args is propagated to the collector hook
"""
collection_args = {
"flag_1": True,
"flag_2": False,
"flag_3": 10,
}
# if collection_args is provided to collect_session
# api_collector adds collection_args to root item properties
# this is done only for test purposes

# without collection_args provided,
# root_item properties do not contain collection_args
self.manager.collect_session()
root_item = self.manager.tree.root_item
root_item_properties = root_item.properties
self.assertNotIn("flag_1", root_item_properties)
self.assertNotIn("flag_2", root_item_properties)
self.assertNotIn("flag_3", root_item_properties)

# now we provide collection_args
self.manager.collect_session(collection_args)

# so properties should be filled
self.assertEqual(root_item.properties["flag_1"], collection_args["flag_1"])
self.assertEqual(root_item.properties["flag_2"], collection_args["flag_2"])
self.assertEqual(root_item.properties["flag_3"], collection_args["flag_3"])


0 comments on commit e23599d

Please sign in to comment.