Esempio n. 1
0
 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
Esempio n. 2
0
    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
Esempio n. 3
0
 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
Esempio n. 4
0
 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
Esempio n. 5
0
    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
Esempio n. 6
0
 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.
Esempio n. 7
0
 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
Esempio n. 8
0
 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
Esempio n. 9
0
 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
Esempio n. 10
0
 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"
Esempio n. 11
0
    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
Esempio n. 12
0
    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
Esempio n. 13
0
    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"
Esempio n. 14
0
    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