def setUp(self): """Set up the test case.""" self.node = CompositorNode(MagicMock()) self.node.add_required_nodes([MagicMock(), MagicMock()]) self.node.add_optional_nodes([MagicMock()]) self.node_copy = self.node.copy()
class TestCompositorNodeCopy(unittest.TestCase): """Test case for copying a node.""" def setUp(self): """Set up the test case.""" self.node = CompositorNode(MagicMock()) self.node.add_required_nodes([MagicMock(), MagicMock()]) self.node.add_optional_nodes([MagicMock()]) self.node_copy = self.node.copy() def test_node_data_is_copied(self): """Test that the data of the node is copied.""" assert self.node_copy.data is not self.node.data def test_node_data_required_nodes_are_copies(self): """Test that the required nodes of the node data are copied.""" for req1, req2 in zip(self.node.required_nodes, self.node_copy.required_nodes): assert req1 is not req2 def test_node_data_optional_nodes_are_copies(self): """Test that the optional nodes of the node data are copied.""" for req1, req2 in zip(self.node.optional_nodes, self.node_copy.optional_nodes): assert req1 is not req2
def _find_compositor(self, dataset_key, query): """Find the compositor object for the given dataset_key.""" # NOTE: This function can not find a modifier that performs # one or more modifications if it has modifiers see if we can find # the unmodified version first if dataset_key.is_modified(): implicit_dependency_node = self._create_implicit_dependency_subtree( dataset_key, query) dataset_key = self._promote_query_to_modified_dataid( dataset_key, implicit_dependency_node.name) try: compositor = self.get_modifier(dataset_key) except KeyError: raise KeyError("Can't find anything called {}".format( str(dataset_key))) compositor.attrs['prerequisites'] = [ implicit_dependency_node ] + list(compositor.attrs['prerequisites']) else: try: compositor = self.get_compositor(dataset_key) except KeyError: raise KeyError("Can't find anything called {}".format( str(dataset_key))) root = CompositorNode(compositor) composite_id = root.name prerequisite_filter = composite_id.create_filter_query_without_required_fields( dataset_key) # Get the prerequisites LOG.trace( "Looking for composite prerequisites for: {}".format(dataset_key)) prereqs = [ create_filtered_query(prereq, prerequisite_filter) if not isinstance(prereq, Node) else prereq for prereq in compositor.attrs['prerequisites'] ] prereqs = self._create_required_subtrees(root, prereqs, query=query) root.add_required_nodes(prereqs) # Get the optionals LOG.trace( "Looking for optional prerequisites for: {}".format(dataset_key)) optionals = [ create_filtered_query(prereq, prerequisite_filter) if not isinstance(prereq, Node) else prereq for prereq in compositor.attrs['optional_prerequisites'] ] optionals = self._create_optional_subtrees(root, optionals, query=query) root.add_optional_nodes(optionals) return root
def setUp(self): """Set up the test case.""" self.name = 'hej' self.fake = FakeCompositor(self.name) self.c_node = CompositorNode(self.fake)
class TestCompositorNode(unittest.TestCase): """Test case for the compositor node object.""" def setUp(self): """Set up the test case.""" self.name = 'hej' self.fake = FakeCompositor(self.name) self.c_node = CompositorNode(self.fake) def test_compositor_node_init(self): """Test compositor node initialization.""" assert self.c_node.name == self.name assert self.fake in self.c_node.data def test_add_required_nodes(self): """Test adding required nodes.""" self.c_node.add_required_nodes([1, 2, 3]) assert self.c_node.required_nodes == [1, 2, 3] def test_add_required_nodes_twice(self): """Test adding required nodes twice.""" self.c_node.add_required_nodes([1, 2]) self.c_node.add_required_nodes([3]) assert self.c_node.required_nodes == [1, 2, 3] def test_add_optional_nodes(self): """Test adding optional nodes.""" self.c_node.add_optional_nodes([1, 2, 3]) assert self.c_node.optional_nodes == [1, 2, 3] def test_add_optional_nodes_twice(self): """Test adding optional nodes twice.""" self.c_node.add_optional_nodes([1, 2]) self.c_node.add_optional_nodes([3]) assert self.c_node.optional_nodes == [1, 2, 3]