Esempio n. 1
0
    def test_get_predefined_values_ok(self):
        settings = AppSettings(path="./settings_test.ini",
                               create_if_not_exists=False)

        distance = settings.get_max_distance_in_km()

        self.assertEqual(distance, 5)
Esempio n. 2
0
    def test_set_than_get(self):
        settings = AppSettings(path="./settings_test.ini",
                               create_if_not_exists=False)

        settings.set_value("NEW-SECTION", "NEW-KEY", "VALUE")
        value = settings.get_value("NEW-SECTION", "NEW-KEY")

        self.assertEqual(value, "VALUE")
Esempio n. 3
0
    def test_get_default_value_raise(self):
        settings = AppSettings(path="./not-existent-file",
                               create_if_not_exists=False)

        distance = settings.get_value_raise("ARGUMENTS", "MAX_DISTANCE_IN_KM")
        self.assertEqual(distance, "10")

        self.assertRaises(
            ItemNotFoundError,
            lambda: settings.get_value_raise("Non-existent-section", "key"))
Esempio n. 4
0
    def test_settings_file_doesnt_exist(self):
        settings_file = "./settings-does-not-exists-test.ini"

        self.assertFalse(os.path.exists(settings_file))
        settings = AppSettings(settings_file)
        self.assertTrue(os.path.exists(settings_file))

        if os.path.exists(settings_file):
            os.remove(settings_file)
Esempio n. 5
0
    def test_to_string(self):
        settings = AppSettings(path="./settings_test.ini",
                               create_if_not_exists=False)

        str_repre = str(settings)

        print(str_repre)

        self.assertTrue("ARGUMENT" in str_repre)
Esempio n. 6
0
    def test_settings_file_doesnt_exist_do_not_create_flag(self):
        settings_file = "./settings-does-not-exists-test.ini"

        self.assertFalse(os.path.exists(settings_file))
        settings = AppSettings(path=settings_file, create_if_not_exists=False)
        self.assertFalse(os.path.exists(settings_file))

        if os.path.exists(settings_file):
            os.remove(settings_file)
Esempio n. 7
0
    def test_get_default_value(self):
        settings = AppSettings(path="./not-existent-file",
                               create_if_not_exists=False)
        distance = settings.get_value("ARGUMENTS", "MAX_DISTANCE_IN_KM")

        self.assertEqual(distance, "10")
Esempio n. 8
0
        logging.error(error_msg)
    logging.info("*********************Finished*********************")
    quit(1)


if __name__ == "__main__":
    logging.basicConfig(
        format="%(asctime)s|%(levelname)s|%(filename)s|%(funcName)s||%(message)s",
        level=logging.INFO
       # datefmt="%H:%M:%S",
    )

    logging.info("*********************Starting*********************")

    # load settings from a file
    settings = AppSettings(create_if_not_exists=True)

    try:
        ARG_EXTENSIONS = settings.get_extensions()
        ARG_ROOT_FOLDER = settings.get_root_folder()
        ARG_LAT = settings.get_latitude()
        ARG_LON = settings.get_longitude()
        ARG_DISTANCE = settings.get_max_distance_in_km()
    except ItemNotFoundError as ex:
        finish_with_error(f"Error in settings file: {ex}")

    if not os.path.isdir(ARG_ROOT_FOLDER):
        finish_with_error("Argument root folder does not exist!!!")

    extensions = re.split(",", ARG_EXTENSIONS)
    extensions = strip_whitespaces_list(extensions)