Beispiel #1
0
 def test_float_int(self):
     assert is_float(1)
     assert is_float(1.1)
     assert is_float(1.0)
     assert not is_float("test")
     assert is_int(1)
     assert is_int(1.0)
     assert not is_int(1.1)
     assert not is_int("test")
Beispiel #2
0
 def test_float_int(self) -> None:
     """TODO: Doku."""
     self.assertTrue(is_float(1))
     self.assertTrue(is_float(1.1))
     self.assertTrue(is_float(1.0))
     self.assertFalse(is_float("test"))
     self.assertTrue(is_int(1))
     self.assertTrue(is_int(1.0))
     self.assertFalse(is_int(1.1))
     self.assertFalse(is_int("test"))
Beispiel #3
0
 def test_float_int(self):
     """
     TODO: Doku
     """
     assert is_float(1)
     assert is_float(1.1)
     assert is_float(1.0)
     assert not is_float("test")
     assert is_int(1)
     assert is_int(1.0)
     assert not is_int(1.1)
     assert not is_int("test")
Beispiel #4
0
 def get_value(self, section: str, key: str) -> any:
     """Returns a value in a given section from the configuration file.
     Returns String, Float, Integer, Boolean"""
     value = ""
     try:
         value = self.configlib[section][key]
     except KeyError:
         error("Could not find key {} in section {}".format(key, section))
         info("Valid sections are: ")
         info("{}".format(self.get_sections()))
     if value in ["yes", "no", "true", "false", "on", "off"]:
         return self.configlib.getboolean(section, key)
     if is_int(value):
         return self.configlib.getint(section, key)
     if is_float(value):
         return self.configlib.getfloat(section, key)
     return value
Beispiel #5
0
    def get_value(self, section: str, key: str) -> Union[bool, int, float, str]:
        """
        Return a value from a given section of the configuration.

        [Data Types] String, Float, Integer, Boolean
        """
        self.read_config_file()
        value = ""
        try:
            value = self.configlib[section][key]
        except KeyError:
            error("Could not find key {} in section {}".format(key, section))
            info("Valid sections are: ")
            info("{}".format(self.get_sections()))
        if value.lower() in ["yes", "no", "true", "false", "on", "off"]:
            return self.configlib.getboolean(section, key)
        if is_int(value):
            return self.configlib.getint(section, key)
        if is_float(value):
            return self.configlib.getfloat(section, key)
        return value