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