1"""
2Minimal tests for sequence proxies
3
4NOTE: this file is very, very incomplete and just tests copying at the moment.
5"""
6import sys
7from PyObjCTools.TestSupport import *
8from PyObjCTest.fnd import NSArray, NSMutableArray, NSPredicate, NSObject, NSNull
9from PyObjCTest.pythonset import OC_TestSet
10import objc
11
12OC_PythonArray = objc.lookUpClass("OC_PythonArray")
13
14class BasicSequenceTests:
15    # Tests for sets that don't try to mutate the set.
16    # Shared between tests for set() and frozenset()
17    seqClass = None
18
19    def testProxyClass(self):
20        # Ensure that the right class is used to proxy sets
21        self.assertIs(OC_TestSet.classOf_(self.seqClass()), OC_PythonArray)
22
23    def testMutableCopy(self):
24
25        s = self.seqClass(range(20))
26        o = OC_TestSet.set_mutableCopyWithZone_(s, None)
27        self.assertEquals(list(s), o)
28        self.assertIsNot(s, o)
29        self.assertIsInstance(o, list)
30
31        s = self.seqClass()
32        o = OC_TestSet.set_mutableCopyWithZone_(s, None)
33        self.assertEquals(list(s), o)
34        self.assertIsNot(s, o)
35        self.assertIsInstance(o, list)
36
37
38
39
40class TestImmutableSequence (TestCase, BasicSequenceTests):
41    seqClass = tuple
42
43    def testCopy(self):
44        s = self.seqClass()
45        o = OC_TestSet.set_copyWithZone_(s, None)
46        self.assertEquals(s, o)
47
48        s = self.seqClass(range(20))
49        o = OC_TestSet.set_copyWithZone_(s, None)
50        self.assertEquals(s, o)
51
52    def testNotMutable(self):
53        # Ensure that a frozenset cannot be mutated
54        o = self.seqClass([1,2,3])
55        self.assertRaises((TypeError, AttributeError),
56                OC_TestSet.set_addObject_, o, 4)
57
58
59class TestMutableSequence (TestCase, BasicSequenceTests):
60    seqClass = list
61
62    def testCopy(self):
63        s = self.seqClass()
64        o = OC_TestSet.set_copyWithZone_(s, None)
65        self.assertEquals(s, o)
66        self.assertIsNot(s, o)
67
68        s = self.seqClass(range(20))
69        o = OC_TestSet.set_copyWithZone_(s, None)
70        self.assertEquals(s, o)
71        self.assertIsNot(s, o)
72
73
74
75
76if __name__ == "__main__":
77    main()
78