예제 #1
0
    def testValueGetterDictionaryModifying(self):
        data = {"aspectToGet": "firstValue", "otherAspectToGet": 2}

        col = ColumnDefn("title", valueGetter="aspectToGet")
        self.assertEqual(col.GetValue(data), "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data["aspectToGet"], "newValue")

        col = ColumnDefn("title", valueGetter="otherAspectToGet")
        self.assertEqual(col.GetValue(data), 2)
        col.SetValue(data, 3)
        self.assertEqual(data["otherAspectToGet"], 3)
예제 #2
0
    def testValueGetterListModifying(self):
        data = ["zero", "first", 2, "third"]

        col = ColumnDefn("title", valueGetter=1)
        self.assertEqual(col.GetValue(data), "first")
        col.SetValue(data, "newValue")
        self.assertEqual(data[1], "newValue")
예제 #3
0
    def testValueGetterAttribute(self):
        class DataObject:
            def __init__(self, value1, value2):
                self.aspectToGet = value1
                self.otherAspectToGet = value2

        data = DataObject("firstValue", "secondValue")

        col = ColumnDefn(valueGetter="aspectToGet")
        self.assertEqual(data.aspectToGet, "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.aspectToGet, "newValue")

        col = ColumnDefn(valueGetter="otherAspectToGet")
        self.assertEqual(data.otherAspectToGet, "secondValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.otherAspectToGet, "newValue")
예제 #4
0
    def testValueSetterWrongName(self):
        class DataObject:
            def __init__(self, value1, value2):
                self.someAttribute = value1
                self.someOtherAttribute = value2

        data = DataObject("firstValue", "secondValue")
        col = ColumnDefn(valueSetter="aNameThatIsntAnAttribute")

        self.assertEqual(data.someAttribute, "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.someAttribute, "firstValue")
예제 #5
0
    def testValueGetterMethod(self):
        class DataObject:
            def aspectToGet(self):
                return "firstValue"

            def otherAspectToGet(self):
                return 2

        data = DataObject()

        col = ColumnDefn("title", valueGetter="aspectToGet")
        self.assertEqual(data.aspectToGet(), "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.aspectToGet(), "firstValue")
예제 #6
0
    def testValueGetterFunction(self):
        def getterFunction(modelObject):
            return modelObject.otherAspectToGet * 2

        class DataObject:
            def __init__(self, value1, value2):
                self.aspectToGet = value1
                self.otherAspectToGet = value2

        data = DataObject("firstValue", "secondValue")

        col = ColumnDefn(valueGetter=getterFunction)
        self.assertEqual(data.aspectToGet, "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.aspectToGet, "firstValue")
예제 #7
0
    def testValueSetterMethod(self):
        class DataObject:
            def __init__(self, value1, value2):
                self.someAttribute = value1
                self.someOtherAttribute = value2

            def SetSomeAttribute(self, value):
                self.someAttribute = value

        data = DataObject("firstValue", "secondValue")
        col = ColumnDefn(valueSetter="SetSomeAttribute")

        self.assertEqual(data.someAttribute, "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.someAttribute, "newValue")
예제 #8
0
    def testValueSetterFunction(self):
        def setterFunction(modelObject, value):
            modelObject.someAttribute = value

        class DataObject:
            def __init__(self, value1, value2):
                self.someAttribute = value1
                self.someOtherAttribute = value2

        data = DataObject("firstValue", "secondValue")
        col = ColumnDefn(valueSetter=setterFunction)

        self.assertEqual(data.someAttribute, "firstValue")
        col.SetValue(data, "newValue")
        self.assertEqual(data.someAttribute, "newValue")
예제 #9
0
 def testValueGetterListMiss(self):
     data = ["zero", "first", 2, "third"]
     col = ColumnDefn("title", valueGetter=99)
     self.assertEqual(col.GetValue(data), None)
     col.SetValue(data, 3)
     self.assertEqual(data, ["zero", "first", 2, "third"])