Example #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"
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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
Example #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
Example #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
Example #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)
Example #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)
Example #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)
Example #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)
Example #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
Example #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)
Example #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
Example #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)
Example #26
0
 def test():
     del PropertyTest().ProtectedStaticProperty
Example #27
0
 def test():
     del PropertyTest().ProtectedProperty
Example #28
0
 def test():
     del PropertyTest().PublicStaticProperty
Example #29
0
 def test():
     object = PropertyTest()
     object.PublicProperty = "spam"
Example #30
0
 def test():
     f = PropertyTest().PrivateStaticProperty
Example #31
0
 def test():
     f = PropertyTest().PrivateProperty
Example #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"
Example #33
0
 def test():
     object = PropertyTest()
     object.PublicProperty = "spam"
Example #34
0
 def test():
     f = PropertyTest().InternalProperty
Example #35
0
 def test():
     f = PropertyTest().InternalStaticProperty
Example #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"