1"""
2Tests for objc.synthesize
3"""
4from PyObjCTools.TestSupport import *
5from PyObjCTest.fnd import NSObject
6import objc
7
8class TestSynthesizeCopier (NSObject):
9    def copy(self):
10        return 42
11
12class TestSynthesizeHelper (NSObject):
13    objc.synthesize('someTitle', copy=True)
14    objc.synthesize('stringValue', copy=False)
15    objc.synthesize('read', readwrite=False)
16
17
18class TestSynthesize (TestCase):
19    def testNames(self):
20        self.assertHasAttr(TestSynthesizeHelper, 'someTitle')
21        self.assertHasAttr(TestSynthesizeHelper, 'setSomeTitle_')
22
23        self.assertHasAttr(TestSynthesizeHelper, 'stringValue')
24        self.assertHasAttr(TestSynthesizeHelper, 'setStringValue_')
25
26        self.assertHasAttr(TestSynthesizeHelper, 'read')
27        self.assertNotHasAttr(TestSynthesizeHelper, 'setRead_')
28
29    def testCopying(self):
30        obj = TestSynthesizeHelper.alloc().init()
31
32        v = TestSynthesizeCopier.alloc().init()
33
34        obj.setStringValue_(v)
35        self.assertIs(obj.stringValue(), v)
36
37        obj.setSomeTitle_(v)
38        self.assertEqual(obj.someTitle(), 42)
39
40    def testFailures(self):
41        self.assertRaises(ValueError, objc.synthesize, '')
42        self.assertRaises(ValueError, objc.synthesize, None)
43
44if __name__ == "__main__":
45    main()
46