Remove LRU cache
This commit is contained in:
parent
aee61e856d
commit
c274ad6d54
@ -1,11 +1,8 @@
|
||||
import yaml
|
||||
import os
|
||||
from flask import current_app as app
|
||||
from functools import lru_cache
|
||||
from atst.utils import getattr_path
|
||||
|
||||
ENV = os.getenv("FLASK_ENV", "dev")
|
||||
|
||||
|
||||
class LocalizationInvalidKeyError(Exception):
|
||||
def __init__(self, key, variables):
|
||||
@ -18,26 +15,18 @@ class LocalizationInvalidKeyError(Exception):
|
||||
)
|
||||
|
||||
|
||||
localizations_cache_size = 1 if ENV == "dev" else None
|
||||
|
||||
|
||||
@lru_cache(maxsize=localizations_cache_size)
|
||||
def load_cached_translations_file(file_name):
|
||||
return open(file_name).read()
|
||||
|
||||
|
||||
def _translations_file():
|
||||
file_name = "translations.yaml"
|
||||
|
||||
if app:
|
||||
file_name = app.config.get("TRANSLATIONS_FILE") or file_name
|
||||
file_name = app.config.get("DEFAULT_TRANSLATIONS_FILE", file_name)
|
||||
|
||||
return file_name
|
||||
return open(file_name)
|
||||
|
||||
|
||||
def translate(key, variables=None):
|
||||
translations_file = _translations_file()
|
||||
translations = yaml.safe_load(load_cached_translations_file(translations_file))
|
||||
translations = yaml.safe_load(translations_file)
|
||||
value = getattr_path(translations, key)
|
||||
|
||||
if variables is None:
|
||||
|
@ -1,14 +1,5 @@
|
||||
import pytest
|
||||
from atst.utils.localization import (
|
||||
translate,
|
||||
load_cached_translations_file,
|
||||
LocalizationInvalidKeyError,
|
||||
)
|
||||
|
||||
|
||||
def test_loading_cached_translations_file_returns_the_file_contents():
|
||||
file_name = "translations.yaml"
|
||||
assert load_cached_translations_file(file_name) == open(file_name).read()
|
||||
from atst.utils.localization import translate, LocalizationInvalidKeyError
|
||||
|
||||
|
||||
def test_looking_up_existing_key():
|
||||
|
Loading…
x
Reference in New Issue
Block a user