From aca0da5d6b8ff0a2c612d78890b53578967bfe84 Mon Sep 17 00:00:00 2001 From: Famlam Date: Wed, 25 Dec 2024 21:48:26 +0100 Subject: [PATCH 1/2] 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. The runtime exception was kept on request. --- osmose_config.py | 19 +++++++++++++++++++ plugins/Name_Script.py | 1 + 2 files changed, 20 insertions(+) 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..78431a79e 100644 --- a/plugins/Name_Script.py +++ b/plugins/Name_Script.py @@ -102,6 +102,7 @@ def init(self, logger): for language in languages: if not self.lang[language]: languages = None + break # Build default regex if languages: From 49bc26e873de31a8849b7245d2a238abb89b18c0 Mon Sep 17 00:00:00 2001 From: Famlam Date: Wed, 25 Dec 2024 21:56:34 +0100 Subject: [PATCH 2/2] Add 'sw' as a Latin language --- modules/languages.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/languages.py b/modules/languages.py index 5b18ef833..35960f7bc 100644 --- a/modules/languages.py +++ b/modules/languages.py @@ -94,6 +94,7 @@ 'sr': ['Cyrillic'], 'sr-Latn': [u'[A-Za-zČĆĐŠŽčćđšž]'], 'sv': ['Latin'], + 'sw': ['Latin'], 'ta': ['Tamil'], 'tg': ['Arabic', 'Cyrillic'], 'th': ['Thai'],