예제 #1
0
def test_property_descriptor_wrong_type():
    """Test setting a property using a value of the wrong type."""

    # Will attempt to implicitly convert "spam" to int, and fail, resulting in ValueError
    with pytest.raises(ValueError):
        ob = PropertyTest()
        ob.PublicProperty = "spam"
예제 #2
0
def test_protected_instance_property():
    """Test protected instance properties."""
    ob = PropertyTest()

    assert ob.ProtectedProperty == 0
    ob.ProtectedProperty = 1
    assert ob.ProtectedProperty == 1

    with pytest.raises(TypeError):
        del PropertyTest().ProtectedProperty
예제 #3
0
    def test_protected_instance_property(self):
        """Test protected instance properties."""
        ob = PropertyTest()

        self.assertTrue(ob.ProtectedProperty == 0)
        ob.ProtectedProperty = 1
        self.assertTrue(ob.ProtectedProperty == 1)

        with self.assertRaises(TypeError):
            del PropertyTest().ProtectedProperty
예제 #4
0
def test_public_instance_property():
    """Test public instance properties."""
    ob = PropertyTest()

    assert ob.PublicProperty == 0
    ob.PublicProperty = 1
    assert ob.PublicProperty == 1

    with pytest.raises(TypeError):
        del PropertyTest().PublicProperty
예제 #5
0
def test_public_instance_property():
    """Test public instance properties."""
    ob = PropertyTest()

    assert ob.PublicProperty == 0
    ob.PublicProperty = 1
    assert ob.PublicProperty == 1

    with pytest.raises(TypeError):
        del PropertyTest().PublicProperty
예제 #6
0
def test_protected_instance_property():
    """Test protected instance properties."""
    ob = PropertyTest()

    assert ob.ProtectedProperty == 0
    ob.ProtectedProperty = 1
    assert ob.ProtectedProperty == 1

    with pytest.raises(TypeError):
        del PropertyTest().ProtectedProperty
예제 #7
0
def test_private_property():
    """Test private properties."""

    with pytest.raises(AttributeError):
        _ = PropertyTest().PrivateProperty

    with pytest.raises(AttributeError):
        _ = PropertyTest().PrivateStaticProperty

    with pytest.raises(AttributeError):
        _ = PropertyTest.PrivateStaticProperty
예제 #8
0
def test_internal_property():
    """Test internal properties."""

    with pytest.raises(AttributeError):
        _ = PropertyTest().InternalProperty

    with pytest.raises(AttributeError):
        _ = PropertyTest().InternalStaticProperty

    with pytest.raises(AttributeError):
        _ = PropertyTest.InternalStaticProperty
예제 #9
0
    def testPublicInstanceProperty(self):
        """Test public instance properties."""
        object = PropertyTest()

        self.failUnless(object.PublicProperty == 0)
        object.PublicProperty = 1
        self.failUnless(object.PublicProperty == 1)

        def test():
            del PropertyTest().PublicProperty

        self.failUnlessRaises(TypeError, test)
예제 #10
0
    def testPublicInstanceProperty(self):
        """Test public instance properties."""
        object = PropertyTest()

        self.assertTrue(object.PublicProperty == 0)
        object.PublicProperty = 1
        self.assertTrue(object.PublicProperty == 1)

        def test():
            del PropertyTest().PublicProperty

        self.assertRaises(TypeError, test)
예제 #11
0
    def testProtectedInstanceProperty(self):
        """Test protected instance properties."""
        object = PropertyTest()

        self.failUnless(object.ProtectedProperty == 0)
        object.ProtectedProperty = 1
        self.failUnless(object.ProtectedProperty == 1)

        def test():
            del PropertyTest().ProtectedProperty

        self.failUnlessRaises(TypeError, test)
예제 #12
0
    def testPublicInstanceProperty(self):
        """Test public instance properties."""
        object = PropertyTest();

        self.assertTrue(object.PublicProperty == 0)
        object.PublicProperty = 1
        self.assertTrue(object.PublicProperty == 1)

        def test():
            del PropertyTest().PublicProperty

        self.assertRaises(TypeError, test)
예제 #13
0
    def testProtectedInstanceProperty(self):
        """Test protected instance properties."""
        object = PropertyTest();

        self.assertTrue(object.ProtectedProperty == 0)
        object.ProtectedProperty = 1
        self.assertTrue(object.ProtectedProperty == 1)

        def test():
            del PropertyTest().ProtectedProperty

        self.assertRaises(TypeError, test)
예제 #14
0
    def testProtectedInstanceProperty(self):
        """Test protected instance properties."""
        object = PropertyTest();

        self.failUnless(object.ProtectedProperty == 0)
        object.ProtectedProperty = 1
        self.failUnless(object.ProtectedProperty == 1)

        def test():
            del PropertyTest().ProtectedProperty

        self.failUnlessRaises(TypeError, test)
예제 #15
0
def test_protected_static_property():
    """Test protected static properties."""
    ob = PropertyTest()

    assert PropertyTest.ProtectedStaticProperty == 0
    PropertyTest.ProtectedStaticProperty = 1
    assert PropertyTest.ProtectedStaticProperty == 1

    assert ob.ProtectedStaticProperty == 1
    ob.ProtectedStaticProperty = 0
    assert ob.ProtectedStaticProperty == 0

    with pytest.raises(TypeError):
        del PropertyTest.ProtectedStaticProperty

    with pytest.raises(TypeError):
        del PropertyTest().ProtectedStaticProperty
예제 #16
0
def test_protected_static_property():
    """Test protected static properties."""
    ob = PropertyTest()

    assert PropertyTest.ProtectedStaticProperty == 0
    PropertyTest.ProtectedStaticProperty = 1
    assert PropertyTest.ProtectedStaticProperty == 1

    assert ob.ProtectedStaticProperty == 1
    ob.ProtectedStaticProperty = 0
    assert ob.ProtectedStaticProperty == 0

    with pytest.raises(TypeError):
        del PropertyTest.ProtectedStaticProperty

    with pytest.raises(TypeError):
        del PropertyTest().ProtectedStaticProperty
예제 #17
0
    def test_protected_static_property(self):
        """Test protected static properties."""
        ob = PropertyTest()

        self.assertTrue(PropertyTest.ProtectedStaticProperty == 0)
        PropertyTest.ProtectedStaticProperty = 1
        self.assertTrue(PropertyTest.ProtectedStaticProperty == 1)

        self.assertTrue(ob.ProtectedStaticProperty == 1)
        ob.ProtectedStaticProperty = 0
        self.assertTrue(ob.ProtectedStaticProperty == 0)

        with self.assertRaises(TypeError):
            del PropertyTest.ProtectedStaticProperty

        with self.assertRaises(TypeError):
            del PropertyTest().ProtectedStaticProperty
예제 #18
0
    def testPublicStaticProperty(self):
        """Test public static properties."""
        object = PropertyTest();

        self.assertTrue(PropertyTest.PublicStaticProperty == 0)
        PropertyTest.PublicStaticProperty = 1
        self.assertTrue(PropertyTest.PublicStaticProperty == 1)

        self.assertTrue(object.PublicStaticProperty == 1)
        object.PublicStaticProperty = 0
        self.assertTrue(object.PublicStaticProperty == 0)

        def test():
            del PropertyTest.PublicStaticProperty

        self.assertRaises(TypeError, test)

        def test():
            del PropertyTest().PublicStaticProperty

        self.assertRaises(TypeError, test)
예제 #19
0
    def testProtectedStaticProperty(self):
        """Test protected static properties."""
        object = PropertyTest();

        self.failUnless(PropertyTest.ProtectedStaticProperty == 0)
        PropertyTest.ProtectedStaticProperty = 1
        self.failUnless(PropertyTest.ProtectedStaticProperty == 1)

        self.failUnless(object.ProtectedStaticProperty == 1)
        object.ProtectedStaticProperty = 0
        self.failUnless(object.ProtectedStaticProperty == 0)

        def test():
            del PropertyTest.ProtectedStaticProperty

        self.failUnlessRaises(TypeError, test)

        def test():
            del PropertyTest().ProtectedStaticProperty

        self.failUnlessRaises(TypeError, test)
예제 #20
0
    def testProtectedStaticProperty(self):
        """Test protected static properties."""
        object = PropertyTest()

        self.failUnless(PropertyTest.ProtectedStaticProperty == 0)
        PropertyTest.ProtectedStaticProperty = 1
        self.failUnless(PropertyTest.ProtectedStaticProperty == 1)

        self.failUnless(object.ProtectedStaticProperty == 1)
        object.ProtectedStaticProperty = 0
        self.failUnless(object.ProtectedStaticProperty == 0)

        def test():
            del PropertyTest.ProtectedStaticProperty

        self.failUnlessRaises(TypeError, test)

        def test():
            del PropertyTest().ProtectedStaticProperty

        self.failUnlessRaises(TypeError, test)
예제 #21
0
    def testPublicStaticProperty(self):
        """Test public static properties."""
        object = PropertyTest()

        self.assertTrue(PropertyTest.PublicStaticProperty == 0)
        PropertyTest.PublicStaticProperty = 1
        self.assertTrue(PropertyTest.PublicStaticProperty == 1)

        self.assertTrue(object.PublicStaticProperty == 1)
        object.PublicStaticProperty = 0
        self.assertTrue(object.PublicStaticProperty == 0)

        def test():
            del PropertyTest.PublicStaticProperty

        self.assertRaises(TypeError, test)

        def test():
            del PropertyTest().PublicStaticProperty

        self.assertRaises(TypeError, test)
예제 #22
0
def 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 == 0
    assert ob.PublicStaticProperty == 0

    descriptor = PropertyTest.__dict__['PublicStaticProperty']
    assert type(descriptor) != int

    ob.PublicStaticProperty = 0
    descriptor = PropertyTest.__dict__['PublicStaticProperty']
    assert type(descriptor) != int

    PropertyTest.PublicStaticProperty = 0
    descriptor = PropertyTest.__dict__['PublicStaticProperty']
    assert type(descriptor) != int
예제 #23
0
    def testPropertyDescriptorGetSet(self):
        """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.

        object = PropertyTest()

        self.failUnless(PropertyTest.PublicStaticProperty == 0)
        self.failUnless(object.PublicStaticProperty == 0)

        descriptor = PropertyTest.__dict__['PublicStaticProperty']
        self.failUnless(type(descriptor) != types.IntType)

        object.PublicStaticProperty = 0
        descriptor = PropertyTest.__dict__['PublicStaticProperty']
        self.failUnless(type(descriptor) != types.IntType)

        PropertyTest.PublicStaticProperty = 0
        descriptor = PropertyTest.__dict__['PublicStaticProperty']
        self.failUnless(type(descriptor) != types.IntType)
예제 #24
0
def 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 == 0
    assert ob.PublicStaticProperty == 0

    descriptor = PropertyTest.__dict__['PublicStaticProperty']
    assert type(descriptor) != int

    ob.PublicStaticProperty = 0
    descriptor = PropertyTest.__dict__['PublicStaticProperty']
    assert type(descriptor) != int

    PropertyTest.PublicStaticProperty = 0
    descriptor = PropertyTest.__dict__['PublicStaticProperty']
    assert type(descriptor) != int
예제 #25
0
    def testPropertyDescriptorGetSet(self):
        """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.

        object = PropertyTest()

        self.failUnless(PropertyTest.PublicStaticProperty == 0)
        self.failUnless(object.PublicStaticProperty == 0)

        descriptor = PropertyTest.__dict__['PublicStaticProperty']
        self.failUnless(type(descriptor) != types.IntType)

        object.PublicStaticProperty = 0
        descriptor = PropertyTest.__dict__['PublicStaticProperty']
        self.failUnless(type(descriptor) != types.IntType)

        PropertyTest.PublicStaticProperty = 0
        descriptor = PropertyTest.__dict__['PublicStaticProperty']
        self.failUnless(type(descriptor) != types.IntType)
예제 #26
0
 def test():
     del PropertyTest().ProtectedStaticProperty
예제 #27
0
 def test():
     del PropertyTest().ProtectedProperty
예제 #28
0
 def test():
     del PropertyTest().PublicStaticProperty
예제 #29
0
 def test():
     object = PropertyTest()
     object.PublicProperty = "spam"
예제 #30
0
 def test():
     f = PropertyTest().PrivateStaticProperty
예제 #31
0
 def test():
     f = PropertyTest().PrivateProperty
예제 #32
0
def 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"
예제 #33
0
 def test():
     object = PropertyTest()
     object.PublicProperty = "spam"
예제 #34
0
 def test():
     f = PropertyTest().InternalProperty
예제 #35
0
 def test():
     f = PropertyTest().InternalStaticProperty
예제 #36
0
def 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"