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)
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")
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")
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")
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")
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")
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")
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")
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"])