def testIsBooleanOnNonBool (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultBool = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING) assert ConfigValues.isBoolean (resultBool) == False
def testNonExistentConfigValueFileNoDefault (self): # Setup with file known that is known to be non-existent. tstCV = ConfigValues(self.NON_EXISTENT_FILENAME) tstCV.InitConfig() # With no passed in default value resultNoDef = tstCV.GetOption (self.NON_EXISTENT_SECTIONNAME, self.NON_EXISTENT_KEYNAME) assert resultNoDef == self.NO_DEFAULT_VALUE
def testIsConstrainedNumberOnNegativeNumber (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultIntNeg = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_INTNEG) assert ConfigValues.isConstrainedNumber (resultIntNeg, int) == False
def testIsConstrainedNumberOnFloat (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultFloat = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_FLOAT) assert ConfigValues.isConstrainedNumber (resultFloat, float) == True
def testNonExistentKeyNoDefault (self): # Setup with file known to exist, with section known to exist. tstCV = ConfigValues(self.EXISTING_FILENAME) tstCV.InitConfig() # With no passed in default value resultNoDef = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.NON_EXISTENT_KEYNAME) assert resultNoDef == self.NO_DEFAULT_VALUE
def testGetOptionWithValidationBoolOnNonBool (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultBool = tstCV.GetOptionWithValidation (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING, False) assert resultBool == False # resultBool should contain the DEFAULT value, in this case, False.
def testGetOptionWithValidationBoolOnBool (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultBool = tstCV.GetOptionWithValidation (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_BOOL, True) assert resultBool == True
def testIsConstrainedStringExactPass (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultStr = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING) assert ConfigValues.isConstrainedString (resultStr, self.EXISTING_KEY_STRINGVALUE) == True
def testExistingKeyFormat2NoDefault (self): # Setup with file known to exist, with section and key known to exist. # Key-value pair format 2: Key:Value tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() # With no passed in default value resultNoDef = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_FORMAT2) assert resultNoDef == self.EXISTING_KEY_VALUE2
def testGetOptionWithValidationStringOnExactFail (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() resultStr = tstCV.GetOptionWithValidation (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING, "StringDefaultValue", list([self.EXISTING_KEY_STRINGVALUE + "junk"])) assert resultStr == "StringDefaultValue"
def testIsConstrainedStringContainsFail (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() # List of strings which does NOT contain the string to be tested. testStringValues = list(["sixOfOne", "halfDozenOfTheOther"]) resultStr = tstCV.GetOption (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING) assert ConfigValues.isConstrainedString (resultStr, testStringValues) == False
def testHasSection (self): # Setup with file known to exist. tstCV = ConfigValues(self.EXISTING_FILENAME) tstCV.InitConfig() # For non-existent section resultDef = tstCV.HasSection (self.NON_EXISTENT_SECTIONNAME) assert resultDef == False # For existing section resultDef = tstCV.HasSection (self.EXISTING_SECTIONNAME) assert resultDef == True
def testGetOptionWithValidationStringOnContainsFail (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() # List of strings which does NOT contain the string to be tested. testStringValues = list(["sixOfOne", "halfDozenOfTheOther"]) resultStr = tstCV.GetOptionWithValidation (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING, "StringDefaultValue", testStringValues) assert resultStr == "StringDefaultValue"
def testGetOptionWithValidationStringOnContainsPass (self): # Setup with file known to exist, with section and key known to exist. tstCV = ConfigValues (self.EXISTING_FILENAME) tstCV.InitConfig() # List of strings which CONTAINS the string to be tested. testStringValues = list(["sixOfOne", self.EXISTING_KEY_STRINGVALUE, "halfDozenOfTheOther"]) resultStr = tstCV.GetOptionWithValidation (self.EXISTING_SECTIONNAME, self.EXISTING_KEYNAME_STRING, self.DEFAULT_VALUE_STRING, testStringValues) assert resultStr == self.EXISTING_KEY_STRINGVALUE