From f97eeb5e4564d563c2a165b0b053d4b66abc0980 Mon Sep 17 00:00:00 2001 From: Famlam Date: Wed, 25 Dec 2024 21:48:26 +0100 Subject: [PATCH] Add test cases for country and language - Adds test cases for country codes and languages, so that mistakes are already detected by pytest/github workers - Remove the exception thrown during runtime --- osmose_config.py | 19 +++++++++++++++++++ plugins/Name_Script.py | 5 ----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/osmose_config.py b/osmose_config.py index 9e49f5e8e..0a77177c1 100644 --- a/osmose_config.py +++ b/osmose_config.py @@ -2167,6 +2167,25 @@ def test_analysersExist(self): f = "analyser_" + a + ".py" assert f in analyser_files, "Not found: {0}".format(f) + def test_countrycode(self): + # Ensure country codes are uppercase and two letters (before any "-") + countries = list(map(lambda c: c.analyser_options.get("country"), config.values())) + assert [] == list(filter(lambda d: d is not None and len(d.split("-", 1)[0]) != 2, countries)) + assert [] == list(filter(lambda d: d is not None and d != d.upper(), countries)) + + def test_languages(self): + # Ensure languages are lowercase and mapped to a script + from modules.languages import language2scripts + languages = [] + for lang in list(map(lambda c: c.analyser_options.get("language"), config.values())): + if isinstance(lang, list): + languages.extend(lang) + elif lang is not None: + languages.append(lang) + + assert set() == set(filter(lambda d: d[:2] != d[:2].lower(), languages)) + assert set() == set(filter(lambda d: d not in language2scripts, languages)) + if __name__ == "__main__": import json diff --git a/plugins/Name_Script.py b/plugins/Name_Script.py index 60a80f80f..7315a0225 100644 --- a/plugins/Name_Script.py +++ b/plugins/Name_Script.py @@ -93,11 +93,6 @@ def init(self, logger): if not isinstance(languages, list): languages = [languages] - # Assert the languages are mapped to scripts - for language in languages: - if language not in self.lang: - raise Exception("No script setup for language '{0}'".format(language)) - # Disable default scripts if one language is not mapped to scripts for language in languages: if not self.lang[language]: