def test_load_wrong_json_file(self): resource_loader.init_json_loader() with self.assertRaisesRegexp(I18nFileLoadError, "error getting data .*"): resource_loader.load_resource( os.path.join(RESOURCE_FOLDER, "settings", "dummy_config.json"), "foo")
def test_load_json_file(self): resource_loader.init_json_loader() data = resource_loader.load_resource( os.path.join(RESOURCE_FOLDER, "settings", "dummy_config.json"), "settings") self.assertIn("foo", data) self.assertEqual("bar", data['foo'])
def test_load_file_with_strange_encoding(self): resource_loader.init_json_loader() config.set("encoding", "euc-jp") data = resource_loader.load_resource( os.path.join(RESOURCE_FOLDER, "settings", "eucjp_config.json"), "settings") self.assertIn("ほげ", data) self.assertEqual("ホゲ", data['ほげ'])
def test_skip_locale_root_data_nested_json_dict__other_locale(self): config.set("file_format", "json") config.set("load_path", [os.path.join(RESOURCE_FOLDER, "translations", "nested_dict_json")]) config.set("filename_format", "{locale}.{format}") config.set('skip_locale_root_data', True) config.set("locale", "en") resource_loader.init_json_loader() self.assertEqual(t('COMMON.EXECUTE', locale="pl"), 'Wykonaj')
def test_skip_locale_root_data_nested_json_dict__default_locale(self): config.set("file_format", "json") config.set("load_path", [os.path.join(RESOURCE_FOLDER, "translations", "nested_dict_json")]) config.set("filename_format", "{locale}.{format}") config.set('skip_locale_root_data', True) config.set("locale", "en") resource_loader.init_json_loader() self.assertEqual(t('COMMON.START'), 'Start')
def test_search_translation_without_ns_nested_dict__default_locale(self): resource_loader.init_json_loader() config.set("file_format", "json") config.set("load_path", [ os.path.join(RESOURCE_FOLDER, "translations", "nested_dict_json") ]) config.set("filename_format", "{locale}.{format}") config.set('skip_locale_root_data', True) config.set("locale", "en") resource_loader.search_translation("TOP_MENU.TOP_BAR.LOGS") self.assertTrue(translations.has("TOP_MENU.TOP_BAR.LOGS")) self.assertEqual(translations.get("TOP_MENU.TOP_BAR.LOGS"), "Logs")
def test_search_translation_without_ns_nested_dict__two_levels_neting__default_locale( self): resource_loader.init_json_loader() config.set("file_format", "json") config.set("load_path", [ os.path.join(RESOURCE_FOLDER, "translations", "nested_dict_json") ]) config.set("filename_format", "{locale}.{format}") config.set('skip_locale_root_data', True) config.set("locale", ["en", "pl"]) resource_loader.search_translation("COMMON.VERSION") self.assertTrue(translations.has("COMMON.VERSION")) self.assertEqual(translations.get("COMMON.VERSION"), "version")
def test_search_translation_without_ns(self): resource_loader.init_json_loader() config.set('file_format', 'json') config.set('filename_format', '{locale}.{format}') resource_loader.search_translation('foo') self.assertTrue(translations.has('foo'))
def test_search_translation_json(self): resource_loader.init_json_loader() config.set('file_format', 'json') resource_loader.search_translation('bar.baz.qux') self.assertTrue(translations.has('bar.baz.qux'))
def test_search_translation_without_ns(self): resource_loader.init_json_loader() config.set("file_format", "json") config.set("filename_format", "{locale}.{format}") resource_loader.search_translation("foo") self.assertTrue(translations.has("foo"))
def test_search_translation_json(self): resource_loader.init_json_loader() config.set("file_format", "json") resource_loader.search_translation("bar.baz.qux") self.assertTrue(translations.has("bar.baz.qux"))
def test_load_file_with_strange_encoding(self): resource_loader.init_json_loader() config.set("encoding", "euc-jp") data = resource_loader.load_resource(os.path.join(RESOURCE_FOLDER, "settings", "eucjp_config.json"), "settings") self.assertIn("ほげ", data) self.assertEqual("ホゲ", data['ほげ'])
def test_load_json_file(self): resource_loader.init_json_loader() data = resource_loader.load_resource(os.path.join(RESOURCE_FOLDER, "settings", "dummy_config.json"), "settings") self.assertIn("foo", data) self.assertEqual("bar", data['foo'])
def test_load_wrong_json_file(self): resource_loader.init_json_loader() with self.assertRaisesRegexp(I18nFileLoadError, "error getting data .*"): resource_loader.load_resource(os.path.join(RESOURCE_FOLDER, "settings", "dummy_config.json"), "foo")