本文整理汇总了Python中PyObjCTest.testhelper.PyObjC_TestClass3类的典型用法代码示例。如果您正苦于以下问题:Python PyObjC_TestClass3类的具体用法?Python PyObjC_TestClass3怎么用?Python PyObjC_TestClass3使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PyObjC_TestClass3类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testBytes
def testBytes(self):
r = PyObjC_TestClass3.makeDataWithBytes_method_(MyData3, 1)
b = PyObjC_TestClass3.getBytes_(r)
self.assertEquals(str(b.bytes()), 'hello world')
self.assertEquals(b.getBytes_length_(None, 4), 'hell')
self.assertEquals(b.getBytes_range_(None, NSRange(2, 4)), 'llo ')
示例2: testBytes
def testBytes(self):
r = PyObjC_TestClass3.makeDataWithBytes_method_(MyData3, 1)
b = PyObjC_TestClass3.getBytes_(r)
# Check for memoryview
if isinstance(b.bytes(), memoryview):
self.assertEqual(b.bytes().tobytes(), b'hello world')
else:
self.assertEqual(bytes(b.bytes()), b'hello world')
self.assertEqual(b.getBytes_length_(None, 4), b'hell')
self.assertEqual(b.getBytes_range_(None, NSRange(2, 4)), b'llo ')
示例3: testDictWithObjects
def testDictWithObjects(self):
o = PyObjC_TestClass3.makeDictFromClass_method_(MyDictionary2, 0)
self.assert_(isinstance(o, tuple))
self.assertEquals(o[2], 4)
self.assertEquals(len(o[1]), 4)
self.assertEquals(len(o[0]), 4)
示例4: testInitWithObjects
def testInitWithObjects(self):
o = PyObjC_TestClass3.makeDictFromClass_method_(MyDictionary1, 1)
self.assert_(isinstance(o, MyDictionary1))
self.assertEquals(o._count, 4)
self.assertEquals(len(o._keys), 4)
self.assertEquals(len(o._objects), 4)
示例5:
def testKVO3(self):
"""
Check if observations work for python-based keys on ObjC classes
"""
observer = KeyValueObserver.alloc().init()
self.assertEquals(observer.observed, [])
o = KeyValueClass1.alloc().init()
STUB.setKeyValue_forObject_key_value_(2, o, u'key3', u'three')
o.addObserver_forKeyPath_options_context_(observer, u"key3",
NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld,
0)
try:
STUB.setKeyValue_forObject_key_value_(2, o, u'key3', u'drie')
self.assertEquals(o.key3, u"drie")
self.assertEquals(len(observer.observed), 1)
keyPath, object, change = observer.observed[0]
self.assertEquals(keyPath, u"key3")
self.assert_(object is o)
self.assertEquals(change,
{
NSKeyValueChangeKindKey:1,
NSKeyValueChangeNewKey:u'drie',
NSKeyValueChangeOldKey:u'three'
})
finally:
o.removeObserver_forKeyPath_(observer, u'key3')
示例6:
def testKVO3(self):
"""
Check if observations work for python-based keys on ObjC classes
"""
observer = KeyValueObserver.alloc().init()
self.assertEqual(observer.observed, [])
o = KeyValueClass1.alloc().init()
STUB.setKeyValue_forObject_key_value_(2, o, b'key3'.decode('ascii'), b'three'.decode('ascii'))
o.addObserver_forKeyPath_options_context_(observer, b"key3".decode('ascii'),
NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld,
0)
try:
STUB.setKeyValue_forObject_key_value_(2, o, b'key3'.decode('ascii'), b'drie'.decode('ascii'))
self.assertEqual(o.key3, b"drie".decode('ascii'))
self.assertEqual(len(observer.observed), 1)
keyPath, object, change = observer.observed[0]
self.assertEqual(keyPath, b"key3".decode('ascii'))
self.assert_(object is o)
self.assertEqual(change,
{
NSKeyValueChangeKindKey:1,
NSKeyValueChangeNewKey:b'drie'.decode('ascii'),
NSKeyValueChangeOldKey:b'three'.decode('ascii')
})
finally:
o.removeObserver_forKeyPath_(observer, b'key3'.decode('ascii'))
示例7: testStoredValueForKey
def testStoredValueForKey(self):
o = KeyValueClass1.alloc().init()
o.addMultiple()
self.assertEqual(STUB.keyValue_forObject_key_(2, o, b"key1".decode('ascii')), 1)
self.assertEqual(STUB.keyValue_forObject_key_(2, o, b"key2".decode('ascii')), 2)
self.assertEqual(STUB.keyValue_forObject_key_(2, o, b"key3".decode('ascii')), 3)
self.assertEqual(STUB.keyValue_forObject_key_(2, o, b"key4".decode('ascii')), "4")
self.assertEqual(STUB.keyValue_forObject_key_(2, o, b"multiple".decode('ascii')), o.multiple)
self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 2, o, b"nokey".decode('ascii'))
示例8: testStoredValueForKey
def testStoredValueForKey(self):
o = KeyValueClass1Explicit.alloc().init()
o.addMultiple()
self.assertEquals(STUB.keyValue_forObject_key_(2, o, u"key1"), 1)
self.assertEquals(STUB.keyValue_forObject_key_(2, o, u"key2"), 2)
self.assertEquals(STUB.keyValue_forObject_key_(2, o, u"key3"), 3)
self.assertEquals(STUB.keyValue_forObject_key_(2, o, u"key4"), "4")
self.assertEquals(STUB.keyValue_forObject_key_(2, o, u"multiple"), o._values['multiple'])
self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 2, o, u"nokey")
示例9: testValueForKey
def testValueForKey(self):
o = KeyValueClass1Explicit.alloc().init()
o.addMultiple()
self.assertEqual(STUB.keyValue_forObject_key_(0, o, b"key1".decode('ascii')), 1)
self.assertEqual(STUB.keyValue_forObject_key_(0, o, b"key2".decode('ascii')), 2)
self.assertEqual(STUB.keyValue_forObject_key_(0, o, b"key3".decode('ascii')), 3)
self.assertEqual(STUB.keyValue_forObject_key_(0, o, b"key4".decode('ascii')), "4")
self.assertEqual(STUB.keyValue_forObject_key_(0, o, b"multiple".decode('ascii')), o._values['multiple'])
self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 0, o, b"nokey".decode('ascii'))
示例10: testTakeValueForKeyPath
def testTakeValueForKeyPath(self):
o = KeyValueClass1Explicit.alloc().init()
o.addMultiple()
self.assertEquals(o._values['multiple']._values['level2']._values['level3']._values['keyA'], u"hello")
self.assertEquals(o._values['multiple']._values['level2']._values['level3']._values['keyB'], u"world")
STUB.setKeyValue_forObject_key_value_(1, o, u"multiple.level2.level3.keyA", u"KeyAValue")
self.assertEquals(o._values['multiple']._values['level2']._values['level3']._values['keyA'], u"KeyAValue")
STUB.setKeyValue_forObject_key_value_(1, o, u"multiple.level2.level3.keyB", 9.999)
self.assertEquals(o._values['multiple']._values['level2']._values['level3']._values['keyB'], 9.999)
示例11: testTakeValueForKeyPath
def testTakeValueForKeyPath(self):
o = KeyValueClass1Explicit.alloc().init()
o.addMultiple()
self.assertEqual(o._values['multiple']._values['level2']._values['level3']._values['keyA'], b"hello".decode('ascii'))
self.assertEqual(o._values['multiple']._values['level2']._values['level3']._values['keyB'], b"world".decode('ascii'))
STUB.setKeyValue_forObject_key_value_(1, o, b"multiple.level2.level3.keyA".decode('ascii'), b"KeyAValue".decode('ascii'))
self.assertEqual(o._values['multiple']._values['level2']._values['level3']._values['keyA'], b"KeyAValue".decode('ascii'))
STUB.setKeyValue_forObject_key_value_(1, o, b"multiple.level2.level3.keyB".decode('ascii'), 9.999)
self.assertEqual(o._values['multiple']._values['level2']._values['level3']._values['keyB'], 9.999)
示例12: testValueForKeyPath
def testValueForKeyPath(self):
o = KeyValueClass1Explicit.alloc().init()
o.addMultiple()
self.assertEquals(STUB.keyValue_forObject_key_(1, o, u"multiple"), o._values['multiple'])
self.assertEquals(STUB.keyValue_forObject_key_(1, o, u"multiple.level2"), o._values['multiple']._values['level2'])
self.assertEquals(STUB.keyValue_forObject_key_(1, o, u"multiple.level2.level3.keyA"),
o._values['multiple']._values['level2']._values['level3']._values['keyA'])
self.assertEquals(STUB.keyValue_forObject_key_(1, o, u"multiple.level2.level3.keyB"),
o._values['multiple']._values['level2']._values['level3']._values['keyB'])
self.assertRaises(KeyError, STUB.keyValue_forObject_key_, 1, o, u"multiple.level2.nokey")
示例13: testTakeValuesFromDictionary
def testTakeValuesFromDictionary(self):
o = KeyValueClass1Explicit.alloc().init()
self.assertEquals(o._values['key3'], 3)
self.assertEquals(o._values['key4'], u"4")
o._values['key5'] = 1
self.assert_('key9' not in o._values)
STUB.setKeyValue_forObject_key_value_(3, o, None,
{
u'key3': u'drie',
u'key4': u'vier',
u'key5': u'V',
u'key9': u'IX',
})
self.assertEquals(o._values['key3'], u"drie")
self.assertEquals(o._values['key4'], u"viervierviervier")
self.assertEquals(o._values['key5'], u"VVVVV")
self.assertEquals(o._values['key9'], u'IX')
示例14: testTakeValuesFromDictionary
def testTakeValuesFromDictionary(self):
o = KeyValueClass1Explicit.alloc().init()
self.assertEqual(o._values['key3'], 3)
self.assertEqual(o._values['key4'], b"4".decode('ascii'))
o._values['key5'] = 1
self.assert_('key9' not in o._values)
STUB.setKeyValue_forObject_key_value_(3, o, None,
{
b'key3'.decode('ascii'): b'drie'.decode('ascii'),
b'key4'.decode('ascii'): b'vier'.decode('ascii'),
b'key5'.decode('ascii'): b'V'.decode('ascii'),
b'key9'.decode('ascii'): b'IX'.decode('ascii'),
})
self.assertEqual(o._values['key3'], b"drie".decode('ascii'))
self.assertEqual(o._values['key4'], b"viervierviervier".decode('ascii'))
self.assertEqual(o._values['key5'], b"VVVVV".decode('ascii'))
self.assertEqual(o._values['key9'], b'IX'.decode('ascii'))
示例15: testTakeStoredValueForKey
def testTakeStoredValueForKey(self):
o = KeyValueClass1Explicit.alloc().init()
self.assertEquals(o._values['key3'], 3)
STUB.setKeyValue_forObject_key_value_(2, o, u'key3', u'drie')
self.assertEquals(o._values['key3'], u"drie")
self.assertEquals(o._values['key4'], u"4")
STUB.setKeyValue_forObject_key_value_(2, o, u'key4', u'vier')
self.assertEquals(o._values['key4'], u"viervierviervier")
o.key5 = 1
STUB.setKeyValue_forObject_key_value_(2, o, u'key5', u'V')
self.assertEquals(o._values['key5'], u"VVVVV")
self.assert_('key9' not in o._values)
STUB.setKeyValue_forObject_key_value_(2, o, u'key9', u'IX')
self.assert_('key9' in o._values)
self.assertEquals(o._values['key9'], u'IX')