Skip to content

Commit

Permalink
Add test cases for country and language
Browse files Browse the repository at this point in the history
- Adds test cases for country codes and languages, so that mistakes are already detected by pytest/github workers
- Remove the exception thrown during runtime
  • Loading branch information
Famlam committed Dec 25, 2024
1 parent dcd357b commit f97eeb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
19 changes: 19 additions & 0 deletions osmose_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions plugins/Name_Script.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down

0 comments on commit f97eeb5

Please sign in to comment.