# -*- coding: utf-8 -*-"""Test CLR property support."""import pytestfrom Python.Test import PropertyTestdef test_public_instance_property():"""Test public instance properties."""ob = PropertyTest()assert ob.PublicProperty == 0ob.PublicProperty = 1assert ob.PublicProperty == 1with pytest.raises(TypeError):del PropertyTest().PublicPropertydef test_public_static_property():"""Test public static properties."""ob = PropertyTest()assert PropertyTest.PublicStaticProperty == 0PropertyTest.PublicStaticProperty = 1assert PropertyTest.PublicStaticProperty == 1assert ob.PublicStaticProperty == 1ob.PublicStaticProperty = 0assert ob.PublicStaticProperty == 0with pytest.raises(TypeError):del PropertyTest.PublicStaticPropertywith pytest.raises(TypeError):del PropertyTest().PublicStaticPropertydef test_protected_instance_property():"""Test protected instance properties."""ob = PropertyTest()assert ob.ProtectedProperty == 0ob.ProtectedProperty = 1assert ob.ProtectedProperty == 1with pytest.raises(TypeError):del PropertyTest().ProtectedPropertydef test_protected_static_property():"""Test protected static properties."""ob = PropertyTest()assert PropertyTest.ProtectedStaticProperty == 0PropertyTest.ProtectedStaticProperty = 1assert PropertyTest.ProtectedStaticProperty == 1assert ob.ProtectedStaticProperty == 1ob.ProtectedStaticProperty = 0assert ob.ProtectedStaticProperty == 0with pytest.raises(TypeError):del PropertyTest.ProtectedStaticPropertywith pytest.raises(TypeError):del PropertyTest().ProtectedStaticPropertydef test_internal_property():"""Test internal properties."""with pytest.raises(AttributeError):_ = PropertyTest().InternalPropertywith pytest.raises(AttributeError):_ = PropertyTest().InternalStaticPropertywith pytest.raises(AttributeError):_ = PropertyTest.InternalStaticPropertydef test_private_property():"""Test private properties."""with pytest.raises(AttributeError):_ = PropertyTest().PrivatePropertywith pytest.raises(AttributeError):_ = PropertyTest().PrivateStaticPropertywith pytest.raises(AttributeError):_ = PropertyTest.PrivateStaticPropertydef test_property_descriptor_get_set():"""Test property descriptor get / set."""# This test ensures that setting an attribute implemented with# a descriptor actually goes through the descriptor (rather than# silently replacing the descriptor in the instance or type dict.ob = PropertyTest()assert PropertyTest.PublicStaticProperty == 0assert ob.PublicStaticProperty == 0descriptor = PropertyTest.__dict__['PublicStaticProperty']assert type(descriptor) != intob.PublicStaticProperty = 0descriptor = PropertyTest.__dict__['PublicStaticProperty']assert type(descriptor) != intPropertyTest.PublicStaticProperty = 0descriptor = PropertyTest.__dict__['PublicStaticProperty']assert type(descriptor) != intdef test_property_descriptor_wrong_type():"""Test setting a property using a value of the wrong type."""with pytest.raises(TypeError):ob = PropertyTest()ob.PublicProperty = "spam"def test_property_descriptor_abuse():"""Test property descriptor abuse."""desc = PropertyTest.__dict__['PublicProperty']with pytest.raises(TypeError):desc.__get__(0, 0)with pytest.raises(TypeError):desc.__set__(0, 0)def test_interface_property():"""Test properties of interfaces. Added after a bug reportthat an IsAbstract check was inappropriate and preventeduse of properties when only the interface is known."""from System.Collections import Hashtable, ICollectionmapping = Hashtable()coll = ICollection(mapping)assert coll.Count == 0
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。