Exemplo n.º 1
0
    def test_remove_should_acquire_lock_on_parent_nodes(self):
        parent1 = Node((1, 2))
        parent2 = Node((2, 3))
        node = Node((3, 4), parents=set([(1, 2), (2, 3)]))
        parent1.children = set([(3, 4)])
        parent2.children = set([(3, 4)])
        leaf_queue = Mock()

        parent1.lock = Mock()
        parent1.lock.aquire.side_effect = lambda: self.assertTrue(
            node in parent1.children)
        parent1.lock.release.side_effect = lambda: self.assertFalse(
            node in parent1.children)

        parent2.lock = Mock()
        parent2.lock.aquire.side_effect = lambda: self.assertTrue(
            node in parent2.children)
        parent2.lock.release.side_effect = lambda: self.assertFalse(
            node in parent2.children)

        node.remove_from_parents([parent1, parent2], leaf_queue)

        self.assertTrue(parent1.lock.acquire.called)
        self.assertTrue(parent1.lock.release.called)
        self.assertTrue(parent2.lock.acquire.called)
        self.assertTrue(parent2.lock.release.called)

        self.assertEquals(leaf_queue.put.call_args_list,
                          [call((1, 2)), call((2, 3))])
    def test_remove_should_acquire_lock_on_parent_nodes(self):
        parent1 = Node((1, 2))
        parent2 = Node((2, 3))
        node = Node((3, 4), parents=set([(1, 2), (2, 3)]))
        parent1.children = set([(3, 4)])
        parent2.children = set([(3, 4)])
        leaf_queue = Mock()

        parent1.lock = Mock()
        parent1.lock.aquire.side_effect = lambda: self.assertTrue(node in parent1.children)
        parent1.lock.release.side_effect = lambda: self.assertFalse(node in parent1.children)

        parent2.lock = Mock()
        parent2.lock.aquire.side_effect = lambda: self.assertTrue(node in parent2.children)
        parent2.lock.release.side_effect = lambda: self.assertFalse(node in parent2.children)

        node.remove_from_parents([parent1, parent2], leaf_queue)

        self.assertTrue(parent1.lock.acquire.called)
        self.assertTrue(parent1.lock.release.called)
        self.assertTrue(parent2.lock.acquire.called)
        self.assertTrue(parent2.lock.release.called)

        self.assertEquals(
            leaf_queue.put.call_args_list,
            [call((1, 2)), call((2, 3))]
        )
Exemplo n.º 3
0
    def test_equality(self):
        n1 = Node((1, 2), children=set([1]))
        n1.parents = set([2])
        n2 = Node((1, 2), children=set([1]))
        n2.parents = set([2])

        self.assertTrue(n1 == n2)
        self.assertFalse(n1 != n2)

        n2.location = (3, 4)
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)

        n2.location = (1, 2)
        n2.parents = set([3])
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)

        n2.children = set([3])
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)

        n2.parents = set([2])
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)
    def test_equality(self):
        n1 = Node((1, 2), children=set([1]))
        n1.parents = set([2])
        n2 = Node((1, 2), children=set([1]))
        n2.parents = set([2])

        self.assertTrue(n1 == n2)
        self.assertFalse(n1 != n2)

        n2.location = (3, 4)
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)

        n2.location = (1, 2)
        n2.parents = set([3])
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)

        n2.children = set([3])
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)

        n2.parents = set([2])
        self.assertFalse(n1 == n2)
        self.assertTrue(n1 != n2)
Exemplo n.º 5
0
    def test_remove_should_add_new_leaves_to_queue(self):
        parent = Node((1, 2))
        child1 = Node((2, 3), parents=set([parent.location]))
        child2 = Node((3, 4), parents=set([parent.location]))
        parent.children = set([child1.location, child2.location])
        leaf_queue = Mock()

        child1.remove_from_parents([parent], leaf_queue)

        self.assertFalse(leaf_queue.put.called)

        child2.remove_from_parents([parent], leaf_queue)

        self.assertEquals(leaf_queue.put.call_args, ((parent.location, ), {}))
    def test_remove_should_add_new_leaves_to_queue(self):
        parent = Node((1, 2))
        child1 = Node((2, 3), parents=set([parent.location]))
        child2 = Node((3, 4), parents=set([parent.location]))
        parent.children = set([child1.location, child2.location])
        leaf_queue = Mock()

        child1.remove_from_parents([parent], leaf_queue)

        self.assertFalse(leaf_queue.put.called)

        child2.remove_from_parents([parent], leaf_queue)

        self.assertEquals(leaf_queue.put.call_args, ((parent.location,), {}))