def test_replace(self):
        oc = OrderedCollection([1, 2, 3, 4, 5])
        oc.replace(id(6), 6)
        assert [i for i in oc] == [
            1,
            2,
            3,
            4,
            5,
            6,
            ]
        oc.replace(id(4), 7)
        assert [i for i in oc] == [
            1,
            2,
            3,
            7,
            5,
            6,
            ]
        assert oc[id(7)] == 7
        with pytest.raises(KeyError):

            # our key should also be gone after the delete

            oc[id(4)]
        with pytest.raises(TypeError):
            oc.replace(id(7), 'not an int')
 def test_replace(self):
     oc = OrderedCollection([1, 2, 3, 4, 5])
     oc.replace(s_id(4), 7)  # replace by object ID
     oc.replace(0, 0)  # replace by index
     assert [i for i in oc] == [0, 2, 3, 7, 5]
     assert oc[s_id(7)] == 7
     with raises(KeyError):
         # our key should also be gone after the delete
         oc[s_id(4)]
     with raises(TypeError):
         oc.replace(s_id(7), "not an int")
Beispiel #3
0
    def test_replace(self):
        oc = OrderedCollection([1, 2, 3, 4, 5])
        oc.replace(s_id(4), 7)  # replace by object ID
        oc.replace(0, 0)  # replace by index
        assert [i for i in oc] == [0, 2, 3, 7, 5]
        assert oc[s_id(7)] == 7

        with raises(KeyError):
            # our key should also be gone after the delete
            oc[s_id(4)]

        with raises(TypeError):
            oc.replace(s_id(7), 'not an int')