Ensure tokenizer tests are run with a fixed UI language

This commit is contained in:
Kovid Goyal 2021-06-18 21:38:15 +05:30
parent c86f439e64
commit d9b773bd19
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 6 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include <locale>
#include <vector>
#include <map>
#include <mutex>
#include <cstring>
#include <sqlite3ext.h>
#include <unicode/unistr.h>
@ -88,6 +89,7 @@ populate_icu_string(const char *text, int text_sz, icu::UnicodeString &str, std:
// }}}
static char ui_language[16] = {0};
static std::mutex global_mutex;
class IteratorDescription {
public:
@ -176,6 +178,7 @@ private:
}
void ensure_basic_iterator(void) {
std::lock_guard<std::mutex> lock(global_mutex);
if (current_ui_language != ui_language || iterators.find("") == iterators.end()) {
current_ui_language.clear(); current_ui_language = ui_language;
icu::ErrorCode status;
@ -393,6 +396,7 @@ get_locales_for_break_iteration(PyObject *self, PyObject *args) {
static PyObject*
set_ui_language(PyObject *self, PyObject *args) {
std::lock_guard<std::mutex> lock(global_mutex);
const char *val;
if (!PyArg_ParseTuple(args, "s", &val)) return NULL;
strncpy(ui_language, val, sizeof(ui_language) - 1);

View File

@ -19,6 +19,8 @@ def print(*args, **kwargs):
class TestConn(Connection):
def __init__(self, remove_diacritics=True):
from calibre_extensions.sqlite_extension import set_ui_language
set_ui_language('en')
super().__init__(':memory:')
plugins.load_apsw_extension(self, 'sqlite_extension')
options = []