#!/www/python/bin/python

"""$URL: svn+ssh://svn.mems-exchange.org/repos/trunk/dulcinea/lib/test/test_immutable_list.py $
$Id: test_immutable_list.py 20909 2003-03-04 14:35:33Z dbinger $

Test for immutable lists.
"""

from sancho.unittest import TestScenario, parse_args, run_scenarios
from dulcinea.immutable_list import ImmutableList

tested_modules = ["dulcinea.immutable_list"]

class ImmutableListTest (TestScenario):

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

    def shutdown (self):
        del self.list

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

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


if __name__ == "__main__":
    (scenarios, options) = parse_args()
    run_scenarios(scenarios, options)
