示例#1
0
 def testOverValueKeyPath(self):
     self.assertEqual(
         DirectString,
         STUB.keyValue_forObject_key_(
             DO_VALUEFORKEYPATH, self.path, "overDirectHead.directString"
         ),
     )
     self.assertEqual(
         DirectString,
         STUB.keyValue_forObject_key_(
             DO_VALUEFORKEYPATH, self.path, "overIndirectHead.directString"
         ),
     )
     self.assertEqual(
         IndirectString,
         STUB.keyValue_forObject_key_(
             DO_VALUEFORKEYPATH, self.path, "overDirectHead.indirectString"
         ),
     )
     self.assertEqual(
         IndirectString,
         STUB.keyValue_forObject_key_(
             DO_VALUEFORKEYPATH, self.path, "overIndirectHead.indirectString"
         ),
     )
示例#2
0
        def testSetValuesForKeysFromDictionary(self):
            o = KeyValueClass2()

            self.assertEqual(o.key3, 3)
            self.assertEqual(o._key4, "4")
            o.key5 = 1
            self.assertNotHasAttr(o, "key9")

            STUB.setKeyValue_forObject_key_value_(
                DO_SETVALUESFORKEYSFROMDICT,
                o,
                None,
                {
                    "key3": "drie",
                    "key4": "vier",
                    "key5": "V",
                    "key9": "IX"
                },
            )

            self.assertEqual(o.key3, "drie")
            self.assertEqual(o._key4, "viervierviervier")
            self.assertEqual(o.key5, "VVVVV")
            self.assertHasAttr(o, "key9")
            self.assertEqual(o.key9, "IX")
示例#3
0
    def testStoredTakeValueForKey2(self):
        o = KeyValueClass3()

        self.assertEqual(o.foo, "foobar")
        STUB.setKeyValue_forObject_key_value_(
            DO_TAKESTOREDVALUE_FORKEY, o, "foo", "FOO"
        )
        self.assertEqual(o.foo, "FOO")

        self.assertRaises(
            KeyError,
            STUB.setKeyValue_forObject_key_value_,
            DO_TAKESTOREDVALUE_FORKEY,
            o,
            "key9",
            "IX",
        )
        self.assertRaises(
            KeyError,
            STUB.setKeyValue_forObject_key_value_,
            DO_TAKESTOREDVALUE_FORKEY,
            o,
            "roprop",
            "IX",
        )
示例#4
0
    def testValueForKeyPath(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, "multiple"),
            o.multiple)
        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o,
                                         "multiple.level2"),
            o.multiple.level2,
        )
        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o,
                                         "multiple.level2.level3.keyA"),
            o.multiple.level2.level3.keyA,
        )
        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o,
                                         "multiple.level2.level3.keyB"),
            o.multiple.level2.level3.keyB,
        )

        self.assertRaises(
            KeyError,
            STUB.keyValue_forObject_key_,
            DO_VALUEFORKEYPATH,
            o,
            "multiple.level2.nokey",
        )
示例#5
0
        def testSetValuesForKeysFromDictionary2(self):
            o = KeyValueClass3()

            self.assertEqual(o.foo, "foobar")
            STUB.setKeyValue_forObject_key_value_(
                DO_SETVALUESFORKEYSFROMDICT, o, None, {"foo": "FOO"}
            )
            self.assertEqual(o.foo, "FOO")

            self.assertRaises(
                KeyError,
                STUB.setKeyValue_forObject_key_value_,
                DO_SETVALUESFORKEYSFROMDICT,
                o,
                None,
                {"key9": "IX"},
            )
            self.assertRaises(
                KeyError,
                STUB.setKeyValue_forObject_key_value_,
                DO_SETVALUESFORKEYSFROMDICT,
                o,
                None,
                {"roprop": "IX"},
            )
        def testTakeValueForKey2(self):
            o = KeyValueClass3()

            self.assertEqual(o.foo, "foobar")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "foo", "FOO")
            self.assertEqual(o.foo, "FOO")

            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUE_FORKEY, o, "key9", "IX")
示例#7
0
        def testTakeValueForKey2(self):
            o = KeyValueClass3()

            self.assertEqual(o.foo, "foobar")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'foo', 'FOO')
            self.assertEqual(o.foo, "FOO")

            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUE_FORKEY, o, 'key9', 'IX')
示例#8
0
        def testTakeValueForKey2(self):
            o = KeyValueClass3()

            self.assertEquals(o.foo, u"foobar")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'foo', u'FOO')
            self.assertEquals(o.foo, u"FOO")

            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUE_FORKEY, o, u'key9', u'IX')
示例#9
0
    def testTakeValuesFromDictionary2(self):
        o = KeyValueClass3()

        self.assertEqual(o.foo, "foobar")
        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, { 'foo': 'FOO' })
        self.assertEqual(o.foo, "FOO")

        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { 'key9':  'IX' })
        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { 'roprop':  'IX' })
示例#10
0
    def testStoredTakeValueForKey2(self):
        o = KeyValueClass3()

        self.assertEqual(o.foo, "foobar")
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, 'foo', 'FOO')
        self.assertEqual(o.foo, "FOO")

        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, 'key9', 'IX')
        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, 'roprop', 'IX')
示例#11
0
        def testSetValuesForKeysFromDictionary2(self):
            o = KeyValueClass3()

            self.assertEqual(o.foo, "foobar")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, { 'foo': 'FOO' })
            self.assertEqual(o.foo, "FOO")

            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { 'key9': 'IX' })
            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { 'roprop': 'IX' })
示例#12
0
 def testOverValueKey(self):
     self.assertEqual(
         DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base,
                                      "overDirectString"))
     self.assertEqual(
         IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base,
                                      "overIndirectString"))
    def testStoredTakeValueForKey2(self):
        o = KeyValueClass3()

        self.assertEquals(o.foo, u"foobar")
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'foo', u'FOO')
        self.assertEquals(o.foo, u"FOO")

        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, u'key9', u'IX')
        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKESTOREDVALUE_FORKEY, o, u'roprop', u'IX')
    def testTakeValuesFromDictionary2(self):
        o = KeyValueClass3()

        self.assertEquals(o.foo, u"foobar")
        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, { u'foo': u'FOO' })
        self.assertEquals(o.foo, u"FOO")

        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { u'key9':  u'IX' })
        self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_TAKEVALUESFROMDICT, o, None, { u'roprop':  u'IX' })
示例#15
0
        def testSetValuesForKeysFromDictionary2(self):
            o = KeyValueClass3()

            self.assertEquals(o.foo, u"foobar")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, { u'foo': u'FOO' })
            self.assertEquals(o.foo, u"FOO")

            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { u'key9': u'IX' })
            self.assertRaises(KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, { u'roprop': u'IX' })
示例#16
0
 def testBaseValueForKey(self):
     self.assertEqual(DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "directString"))
     self.assertEqual(IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "indirectString"))
     self.assertEqual(DirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "directNumber"))
     self.assertEqual(IndirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, "indirectNumber"))
示例#17
0
 def testBaseValueForKey(self):
     self.assertEquals(DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"directString"))
     self.assertEquals(IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"indirectString"))
     self.assertEquals(DirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"directNumber"))
     self.assertEquals(IndirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEY, self.base, u"indirectNumber"))
示例#18
0
 def testOverValueKeyPath(self):
     self.assertEquals(DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overDirectHead.directString"))
     self.assertEquals(DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overIndirectHead.directString"))
     self.assertEquals(IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overDirectHead.indirectString"))
     self.assertEquals(IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, u"overIndirectHead.indirectString"))
示例#19
0
    def testValueForKeyPath(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple"), o.multiple)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple.level2"), o.multiple.level2)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple.level2.level3.keyA"), o.multiple.level2.level3.keyA)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, o, u"multiple.level2.level3.keyB"), o.multiple.level2.level3.keyB)

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEYPATH, o, u"multiple.level2.nokey")
示例#20
0
    def testStoredValueForKey(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key1"), 1)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key2"), 2)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key3"), 3)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"key4"), u"4")
        self.assertEquals(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, u"multiple"), o.multiple)

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_STOREDVALUEFORKEY, o, u"nokey")
示例#21
0
    def testStoredValueForKey(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key1"), 1)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key2"), 2)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key3"), 3)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "key4"), "4")
        self.assertEqual(STUB.keyValue_forObject_key_(DO_STOREDVALUEFORKEY, o, "multiple"), o.multiple)

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_STOREDVALUEFORKEY, o, "nokey")
示例#22
0
    def testValueForKey2(self):
        o = KeyValueClass3()

        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "foo"), "foobar")
        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "bar"),
            "foobarfoobar")
        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "roprop"),
            "read-only")
示例#23
0
        def testPythonConvention(self):
            o = KeyValueClass2()

            self.assertEqual(o._pythonConvention, "BAD")
            self.assertEqual(o.pythonConvention(), "GOOD")
            self.assertEqual(o._pythonConventionValue, "GOOD")
            self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), "GOOD")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "pythonConvention", "CHANGED")
            self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), "CHANGED")
            self.assertEqual(o._pythonConvention, "BAD")
            self.assertEqual(o.pythonConvention(), "CHANGED")
            self.assertEqual(o._pythonConventionValue, "CHANGED")
示例#24
0
        def testSetValueForKeyPath(self):
            o = KeyValueClass2()
            o.addMultiple()

            self.assertEqual(o.multiple.level2.level3.keyA, "hello")
            self.assertEqual(o.multiple.level2.level3.keyB, "world")

            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, "multiple.level2.level3.keyA", "KeyAValue")
            self.assertEqual(o.multiple.level2.level3.keyA, "KeyAValue")

            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, "multiple.level2.level3.keyB", 9.999)
            self.assertEqual(o.multiple.level2.level3.keyB, 9.999)
示例#25
0
        def testSetValueForKeyPath(self):
            o = KeyValueClass2()
            o.addMultiple()

            self.assertEquals(o.multiple.level2.level3.keyA, u"hello")
            self.assertEquals(o.multiple.level2.level3.keyB, u"world")

            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyA", u"KeyAValue")
            self.assertEquals(o.multiple.level2.level3.keyA, u"KeyAValue")

            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyB", 9.999)
            self.assertEquals(o.multiple.level2.level3.keyB, 9.999)
示例#26
0
    def testTakeValueForKeyPath(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEqual(o.multiple.level2.level3.keyA, "hello")
        self.assertEqual(o.multiple.level2.level3.keyB, "world")

        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, "multiple.level2.level3.keyA", "KeyAValue")
        self.assertEqual(o.multiple.level2.level3.keyA, "KeyAValue")

        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, "multiple.level2.level3.keyB", 9.999)
        self.assertEqual(o.multiple.level2.level3.keyB, 9.999)
    def testTakeValueForKeyPath(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEquals(o.multiple.level2.level3.keyA, u"hello")
        self.assertEquals(o.multiple.level2.level3.keyB, u"world")

        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyA", u"KeyAValue")
        self.assertEquals(o.multiple.level2.level3.keyA, u"KeyAValue")

        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUE_FORKEYPATH, o, u"multiple.level2.level3.keyB", 9.999)
        self.assertEquals(o.multiple.level2.level3.keyB, 9.999)
示例#28
0
        def testPythonConvention(self):
            o = KeyValueClass2()

            self.assertEquals(o._pythonConvention, u'BAD')
            self.assertEquals(o.pythonConvention(), u'GOOD')
            self.assertEquals(o._pythonConventionValue, u'GOOD')
            self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"pythonConvention"), u'GOOD')
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'pythonConvention', u'CHANGED')
            self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"pythonConvention"), u'CHANGED')
            self.assertEquals(o._pythonConvention, u'BAD')
            self.assertEquals(o.pythonConvention(), u'CHANGED')
            self.assertEquals(o._pythonConventionValue, u'CHANGED')
示例#29
0
        def testPythonConvention(self):
            o = KeyValueClass2()

            self.assertEqual(o._pythonConvention, 'BAD')
            self.assertEqual(o.pythonConvention(), 'GOOD')
            self.assertEqual(o._pythonConventionValue, 'GOOD')
            self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), 'GOOD')
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'pythonConvention', 'CHANGED')
            self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), 'CHANGED')
            self.assertEqual(o._pythonConvention, 'BAD')
            self.assertEqual(o.pythonConvention(), 'CHANGED')
            self.assertEqual(o._pythonConventionValue, 'CHANGED')
示例#30
0
        def testSetValuesForKeysFromDictionary2(self):
            o = KeyValueClass3()

            self.assertEqual(o.foo, "foobar")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None, {"foo": "FOO"})
            self.assertEqual(o.foo, "FOO")

            self.assertRaises(
                KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, {"key9": "IX"}
            )
            self.assertRaises(
                KeyError, STUB.setKeyValue_forObject_key_value_, DO_SETVALUESFORKEYSFROMDICT, o, None, {"roprop": "IX"}
            )
示例#31
0
 def testPathValueForKey(self):
     self.assertEqual(
         DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "directHead.directString"))
     self.assertEqual(
         DirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "indirectHead.directString"))
     self.assertEqual(
         IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "directHead.indirectString"))
     self.assertEqual(
         IndirectString,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "indirectHead.indirectString"))
     self.assertEqual(
         DirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "directHead.directNumber"))
     self.assertEqual(
         DirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "indirectHead.directNumber"))
     self.assertEqual(
         IndirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "directHead.indirectNumber"))
     self.assertEqual(
         IndirectNumber,
         STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path,
                                      "indirectHead.indirectNumber"))
示例#32
0
 def testPathValueForKey(self):
     self.assertEqual(
         DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.directString")
     )
     self.assertEqual(
         DirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.directString")
     )
     self.assertEqual(
         IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.indirectString")
     )
     self.assertEqual(
         IndirectString, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.indirectString")
     )
     self.assertEqual(
         DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.directNumber")
     )
     self.assertEqual(
         DirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.directNumber")
     )
     self.assertEqual(
         IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "directHead.indirectNumber")
     )
     self.assertEqual(
         IndirectNumber, STUB.keyValue_forObject_key_(DO_VALUEFORKEYPATH, self.path, "indirectHead.indirectNumber")
     )
示例#33
0
    def testTakeStoredValueForKey(self):
        o = KeyValueClass2()

        self.assertEqual(o.key3, 3)
        STUB.setKeyValue_forObject_key_value_(
            DO_TAKESTOREDVALUE_FORKEY, o, "key3", "drie"
        )
        self.assertEqual(o.key3, "drie")

        self.assertEqual(o._key4, "4")
        STUB.setKeyValue_forObject_key_value_(
            DO_TAKESTOREDVALUE_FORKEY, o, "key4", "vier"
        )
        self.assertEqual(o._key4, "viervierviervier")

        o.key5 = 1
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, "key5", "V")
        self.assertEqual(o.key5, "VVVVV")

        self.assertNotHasAttr(o, "key9")
        STUB.setKeyValue_forObject_key_value_(
            DO_TAKESTOREDVALUE_FORKEY, o, "key9", "IX"
        )
        self.assertHasAttr(o, "key9")
        self.assertEqual(o.key9, "IX")
示例#34
0
    def testStrCap(self):
        class Foo:
            def callme(self):
                return u"FOO"

        # check the result for valueForKey: u"callme" on a Foo instance
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, Foo(), u"callme"), u"FOO")
示例#35
0
    def testCopy(self):
        class MyCopyClass(NSObject):
            def copyWithZone_(self, zone):
                # NSObject doesn't implement the copying protocol
                #o = super(MyCopyClass, self).copyWithZone_(zone)
                o = self.__class__.alloc().init()
                o.foobar = 2
                return o

            copyWithZone_ = objc.selector(
                copyWithZone_,
                signature=NSObject.copyWithZone_.signature,
                isClassMethod=0)

        # Make sure the runtime correctly marked our copyWithZone_
        # implementation.
        o = MyCopyClass.alloc().init()

        self.assertFalse((o.copyWithZone_.__metadata__()['classmethod']))
        self.assertTrue(
            o.copyWithZone_.__metadata__()['retval']['already_retained'])
        #self.assertTrue(o.copyWithZone_.callable == MyCopyClass.__dict__['copyWithZone_'].callable)

        o = MyCopyClass.alloc().init()
        o.foobar = 1

        self.assertEquals(o.foobar, 1)

        # Make a copy from ObjC (see testbundle.m)
        c = PyObjC_TestClass3.makeACopy_(o)

        self.assertIsInstance(c, MyCopyClass)
        self.assertEquals(c.foobar, 2)
示例#36
0
    def testCopy(self):
        class MyCopyClass (NSObject):
            def copyWithZone_(self, zone):
                # NSObject doesn't implement the copying protocol
                #o = super(MyCopyClass, self).copyWithZone_(zone)
                o = self.__class__.alloc().init()
                o.foobar = 2
                return o
            copyWithZone_ = objc.selector(
                copyWithZone_,
                signature=NSObject.copyWithZone_.signature,
                isClassMethod=0)


        # Make sure the runtime correctly marked our copyWithZone_
        # implementation.
        o = MyCopyClass.alloc().init()

        self.assertFalse((o.copyWithZone_.__metadata__()['classmethod']))
        self.assertTrue(o.copyWithZone_.__metadata__()['retval']['already_retained'])
        #self.assertTrue(o.copyWithZone_.callable == MyCopyClass.__dict__['copyWithZone_'].callable)

        o = MyCopyClass.alloc().init()
        o.foobar = 1

        self.assertEquals(o.foobar, 1)

        # Make a copy from ObjC (see testbundle.m)
        c = PyObjC_TestClass3.makeACopy_(o)

        self.assertIsInstance(c, MyCopyClass)
        self.assertEquals(c.foobar, 2)
示例#37
0
    def testStrCap(self):
        class Foo:
            def callme(self):
                return "FOO"

        # check the result for valueForKey: "callme" on a Foo instance
        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, Foo(), "callme"), "FOO")
示例#38
0
        def testSetValuesForKeysFromDictionary(self):
            o = KeyValueClass2()

            self.assertEqual(o.key3, 3)
            self.assertEqual(o._key4, "4")
            o.key5 = 1
            self.assertNotHasAttr(o, "key9")

            STUB.setKeyValue_forObject_key_value_(
                DO_SETVALUESFORKEYSFROMDICT, o, None, {"key3": "drie", "key4": "vier", "key5": "V", "key9": "IX"}
            )

            self.assertEqual(o.key3, "drie")
            self.assertEqual(o._key4, "viervierviervier")
            self.assertEqual(o.key5, "VVVVV")
            self.assertHasAttr(o, "key9")
            self.assertEqual(o.key9, "IX")
示例#39
0
    def testValuesForKeys(self):
        o = KeyValueClass2()

        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUESFORKEYS, o, ["key1", "key2", "key3", "key4"]),
            {"key1": 1, "key2": 2, "key3": 3, "key4": "4"},
        )

        self.assertRaises(
            KeyError, STUB.keyValue_forObject_key_, DO_VALUESFORKEYS, o, ["key1", "key2", "nokey", "key3"]
        )
示例#40
0
        def testPythonConvention(self):
            o = KeyValueClass2()

            self.assertEqual(o._pythonConvention, "BAD")
            self.assertEqual(o.pythonConvention(), "GOOD")
            self.assertEqual(o._pythonConventionValue, "GOOD")
            self.assertEqual(
                STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"),
                "GOOD",
            )
            STUB.setKeyValue_forObject_key_value_(
                DO_SETVALUE_FORKEY, o, "pythonConvention", "CHANGED"
            )
            self.assertEqual(
                STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"),
                "CHANGED",
            )
            self.assertEqual(o._pythonConvention, "BAD")
            self.assertEqual(o.pythonConvention(), "CHANGED")
            self.assertEqual(o._pythonConventionValue, "CHANGED")
示例#41
0
    def testTakeValuesFromDictionary(self):
        o = KeyValueClass2()

        self.assertEqual(o.key3, 3)
        self.assertEqual(o._key4, "4")
        o.key5 = 1
        self.assertNotHasAttr(o, 'key9')

        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None, {
            'key3': 'drie',
            'key4': 'vier',
            'key5': 'V',
            'key9': 'IX',
        })

        self.assertEqual(o.key3, "drie")
        self.assertEqual(o._key4, "viervierviervier")
        self.assertEqual(o.key5, "VVVVV")
        self.assertHasAttr(o, 'key9')
        self.assertEqual(o.key9, 'IX')
示例#42
0
        def testSetValuesForKeysFromDictionary(self):
            o = KeyValueClass2()

            self.assertEqual(o.key3, 3)
            self.assertEqual(o._key4, "4")
            o.key5 = 1
            self.assertNotHasAttr(o, 'key9')

            STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None,
                {
                    'key3': 'drie',
                    'key4': 'vier',
                    'key5': 'V',
                    'key9': 'IX',
                })

            self.assertEqual(o.key3, "drie")
            self.assertEqual(o._key4, "viervierviervier")
            self.assertEqual(o.key5, "VVVVV")
            self.assertHasAttr(o, 'key9')
            self.assertEqual(o.key9, 'IX')
        def testSetValuesForKeysFromDictionary(self):
            o = KeyValueClass2()

            self.assertEquals(o.key3, 3)
            self.assertEquals(o._key4, u"4")
            o.key5 = 1
            self.assert_(not hasattr(o, u'key9'))

            STUB.setKeyValue_forObject_key_value_(DO_SETVALUESFORKEYSFROMDICT, o, None,
                {
                    u'key3': u'drie',
                    u'key4': u'vier',
                    u'key5': u'V',
                    u'key9': u'IX',
                })

            self.assertEquals(o.key3, u"drie")
            self.assertEquals(o._key4, u"viervierviervier")
            self.assertEquals(o.key5, u"VVVVV")
            self.assert_(hasattr(o, u'key9'))
            self.assertEquals(o.key9, u'IX')
示例#44
0
    def testTakeValuesFromDictionary(self):
        o = KeyValueClass2()

        self.assertEquals(o.key3, 3)
        self.assertEquals(o._key4, u"4")
        o.key5 = 1
        self.assertNotHasAttr(o, u'key9')

        STUB.setKeyValue_forObject_key_value_(DO_TAKEVALUESFROMDICT, o, None,
            {
                u'key3': u'drie',
                u'key4': u'vier',
                u'key5': u'V',
                u'key9': u'IX',
            })

        self.assertEquals(o.key3, u"drie")
        self.assertEquals(o._key4, u"viervierviervier")
        self.assertEquals(o.key5, u"VVVVV")
        self.assertHasAttr(o, u'key9')
        self.assertEquals(o.key9, u'IX')
        def testReceiveObserved(self):
            # Create an object in Objective-C, add an observer and then
            # pass the object to Python. Unless we take special care the
            # Python wrapper will have the wrong type (that of the
            # internal helper class).

            observer = PyObjCTestObserver.alloc().init()
            o = STUB.createObservedOfClass_observer_keyPath_(
                    NSObject, observer, u"observationInfo")

            try:
                self.assert_(isinstance(o, NSObject))
            finally:
                o.removeObserver_forKeyPath_(observer, u"observationInfo")
示例#46
0
    def testValuesForKeys(self):
        o = KeyValueClass2()

        self.assertEqual(
            STUB.keyValue_forObject_key_(DO_VALUESFORKEYS, o,
                                         ["key1", "key2", "key3", "key4"]), {
                                             "key1": 1,
                                             "key2": 2,
                                             "key3": 3,
                                             "key4": "4"
                                         })

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_,
                          DO_VALUESFORKEYS, o,
                          ["key1", "key2", "nokey", "key3"])
示例#47
0
        def testReceiveObserved(self):
            # Create an object in Objective-C, add an observer and then
            # pass the object to Python. Unless we take special care the
            # Python wrapper will have the wrong type (that of the
            # internal helper class).
            #
            # NOTE: This test is known to fail on OSX 10.5 due to the way
            # KVO is implemented there.

            observer = PyObjCTestObserver.alloc().init()
            o = STUB.makeObservedOfClass_observer_keyPath_(NSObject, observer, "observationInfo")

            try:
                self.assertIsInstance(o, NSObject)
            finally:
                o.removeObserver_forKeyPath_(observer, "observationInfo")
示例#48
0
        def testReceiveObserved(self):
            # Create an object in Objective-C, add an observer and then
            # pass the object to Python. Unless we take special care the
            # Python wrapper will have the wrong type (that of the
            # internal helper class).
            #
            # NOTE: This test is known to fail on OSX 10.5 due to the way
            # KVO is implemented there.

            observer = PyObjCTestObserver.alloc().init()
            o = STUB.makeObservedOfClass_observer_keyPath_(
                    NSObject, observer, "observationInfo")

            try:
                self.assertIsInstance(o, NSObject)
            finally:
                o.removeObserver_forKeyPath_(observer, "observationInfo")
示例#49
0
        def testSetValueForKey(self):
            o = KeyValueClass2()

            self.assertEqual(o.key3, 3)
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key3", "drie")
            self.assertEqual(o.key3, "drie")

            self.assertEqual(o._key4, "4")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key4", "vier")
            self.assertEqual(o._key4, "viervierviervier")

            o.key5 = 1
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key5", "V")
            self.assertEqual(o.key5, "VVVVV")

            self.assertNotHasAttr(o, "key9")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, "key9", "IX")
            self.assertHasAttr(o, "key9")
            self.assertEqual(o.key9, "IX")
示例#50
0
    def testValueForKey(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key1"), 1)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key2"), 2)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key3"), 3)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "key4"), "4")
        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "multiple"), o.multiple)
        self.assertEqual(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, "pythonConvention"), 'GOOD')

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEY, o, "nokey")
示例#51
0
        def testSetValueForKey(self):
            o = KeyValueClass2()

            self.assertEqual(o.key3, 3)
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key3', 'drie')
            self.assertEqual(o.key3, "drie")

            self.assertEqual(o._key4, "4")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key4', 'vier')
            self.assertEqual(o._key4, "viervierviervier")

            o.key5 = 1
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key5', 'V')
            self.assertEqual(o.key5, "VVVVV")

            self.assertNotHasAttr(o, 'key9')
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key9', 'IX')
            self.assertHasAttr(o, 'key9')
            self.assertEqual(o.key9, 'IX')
示例#52
0
        def testSetValueForKey(self):
            o = KeyValueClass2()

            self.assertEqual(o.key3, 3)
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key3', 'drie')
            self.assertEqual(o.key3, "drie")

            self.assertEqual(o._key4, "4")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key4', 'vier')
            self.assertEqual(o._key4, "viervierviervier")

            o.key5 = 1
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key5', 'V')
            self.assertEqual(o.key5, "VVVVV")

            self.assertNotHasAttr(o, 'key9')
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, 'key9', 'IX')
            self.assertHasAttr(o, 'key9')
            self.assertEqual(o.key9, 'IX')
        def testSetValueForKey(self):
            o = KeyValueClass2()

            self.assertEquals(o.key3, 3)
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key3', u'drie')
            self.assertEquals(o.key3, u"drie")

            self.assertEquals(o._key4, u"4")
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key4', u'vier')
            self.assertEquals(o._key4, u"viervierviervier")

            o.key5 = 1
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key5', u'V')
            self.assertEquals(o.key5, u"VVVVV")

            self.assert_(not hasattr(o, u'key9'))
            STUB.setKeyValue_forObject_key_value_(DO_SETVALUE_FORKEY, o, u'key9', u'IX')
            self.assert_(hasattr(o, u'key9'))
            self.assertEquals(o.key9, u'IX')
示例#54
0
    def testValueForKey(self):
        o = KeyValueClass2()
        o.addMultiple()

        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key1"), 1)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key2"), 2)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key3"), 3)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"key4"), u"4")
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"multiple"), o.multiple)
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"pythonConvention"), u'GOOD')

        self.assertRaises(KeyError, STUB.keyValue_forObject_key_, DO_VALUEFORKEY, o, u"nokey")
示例#55
0
    def testTakeStoredValueForKey(self):
        o = KeyValueClass2()

        self.assertEquals(o.key3, 3)
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key3', u'drie')
        self.assertEquals(o.key3, u"drie")

        self.assertEquals(o._key4, u"4")
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key4', u'vier')
        self.assertEquals(o._key4, u"viervierviervier")

        o.key5 = 1
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key5', u'V')
        self.assertEquals(o.key5, u"VVVVV")

        self.assertNotHasAttr(o, u'key9')
        STUB.setKeyValue_forObject_key_value_(DO_TAKESTOREDVALUE_FORKEY, o, u'key9', u'IX')
        self.assertHasAttr(o, u'key9')
        self.assertEquals(o.key9, u'IX')
示例#56
0
    def testValueForKey2(self):
        o = KeyValueClass3()

        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"foo"), u"foobar")
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"bar"), u"foobarfoobar")
        self.assertEquals(STUB.keyValue_forObject_key_(DO_VALUEFORKEY, o, u"roprop"), u"read-only")