Exemplo n.º 1
0
    def test_validate_returns_correct_node_with_correct_parameters(self):
        pl = PositionalList()
        #  setup a correctly referenced _Node:
        expected_node = PositionalList._Node('foo', pl._header, pl._trailer)
        pl._header._next = expected_node
        pl._trailer._prev = expected_node
        good_position = PositionalList.Position(pl, expected_node)

        result_node = pl._validate(good_position)

        self.assertIs(result_node, expected_node)
Exemplo n.º 2
0
    def test_replace_validates_replaces_returns_old_element(self):
        pl = PositionalList()
        original_element = 'foo'
        new_element = 'bar'
        node = PositionalList._Node(original_element, None, None)
        pl._validate = MagicMock(return_value=node)
        position = PositionalList.Position(pl, node)

        result_element = pl.replace(position, new_element)

        pl._validate.assert_called_with(position)
        self.assertIs(result_element, original_element)
        self.assertIs(node._element, new_element)
Exemplo n.º 3
0
    def test_delete_validates_and_calls_delete_node_on_position(self):
        pl = PositionalList()
        expected_element = 'foo'
        node = PositionalList._Node(expected_element, None, None)
        pl._validate = MagicMock(return_value=node)
        pl._delete_node = MagicMock(return_value=expected_element)
        position = PositionalList.Position(pl, node)

        result_element = pl.delete(position)

        pl._validate.assert_called_with(position)
        pl._delete_node.assert_called_with(node)
        self.assertIs(result_element, expected_element)