From 3638aa4949d7f0f2b79fed0e829e56777c0eb9c0 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Sat, 27 Jan 2018 17:27:52 -0800 Subject: [PATCH] Add regression test for language files --- gooey/tests/test_language_parity.py | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 gooey/tests/test_language_parity.py diff --git a/gooey/tests/test_language_parity.py b/gooey/tests/test_language_parity.py new file mode 100644 index 0000000..5410db1 --- /dev/null +++ b/gooey/tests/test_language_parity.py @@ -0,0 +1,41 @@ +import os +import unittest +import json +from collections import OrderedDict +from gooey import languages + +from gooey.gui.processor import ProcessController + + +class TestLanguageParity(unittest.TestCase): + """ + Checks that all language files have the same set of keys so that non-english + languages don't silently break as features are added to Gooey. + """ + + def test_languageParity(self): + langDir = os.path.dirname(languages.__file__) + englishFile = os.path.join(langDir, 'english.json') + + english = self.readFile(englishFile) + jsonFiles = [(path, self.readFile(os.path.join(langDir, path))) + for path in os.listdir(langDir) + if path.endswith('json') and 'poooo' not in path and '2' not in path] + + allKeys = set(english.keys()) + for name, contents in jsonFiles: + missing = allKeys.difference(set(contents.keys())) + self.assertEqual( + set(), + missing, + "{} language file is missing keys: [{}]".format(name, missing) + ) + + + def readFile(self, path): + with open(path, 'r', encoding='utf-8') as f: + return json.loads(f.read()) + + +if __name__ == '__main__': + unittest.main()