#!/www/python/bin/python

"""$URL: svn+ssh://svn/repos/trunk/dulcinea/lib/test/utest_immutable_list.py $
$Id: utest_immutable_list.py 25054 2004-09-09 18:04:30Z dbinger $

Test for immutable lists.
"""

from sancho.utest import UTest
from dulcinea.immutable_list import ImmutableList


class ImmutableListTest (UTest):

    def _pre (self):
        self.list = ImmutableList([1,2,3])

    def _post (self):
        del self.list

    def check_addition (self):
        "Check that immutable lists can be added to other lists"
        assert self.list + [4,5,6] == [1,2,3,4,5,6]
        (self.list + [4,5,6]).append(7)
        ([4,5,6] + self.list).append(7)

    def check_failure (self):
        "Check that mutating methods fail"
        try:
            self.list[0] = 0
            assert 0
        except TypeError: pass
        try:
            self.list[0:2] = [0]
            assert 0
        except TypeError: pass
        try:
            self.list += [4]
            assert 0
        except TypeError: pass
        try:
            self.list.append(4)
            assert 0
        except TypeError: pass
        try:
            self.list.extend([4,5,6])
            assert 0
        except TypeError: pass
        try:
            self.list += [4]
            assert 0
        except TypeError: pass
        try:
            self.list *= 4
            assert 0
        except TypeError: pass


if __name__ == "__main__":
    ImmutableListTest()
