# encoding: utf-8
import translationbackends as tb

# less static
kw = {
    "lang": "en",
    "from": "auto",
    "quick": 0,
    "quick": 0,
    "debug": 1,
    "mode": "page",
    "api_key": "",
    "email": "",
    "cmd": "",
}

def _ab(backend):
    kw["backend"] = backend
    return tb.assign_service(kw)
    

def google():
    assert isinstance(_ab("google translate"), tb.GoogleWeb)
    assert isinstance(_ab("google ajax"), tb.GoogleAjax)

def other():
    assert isinstance(_ab("Argos"), tb.ArgosNmt)
    assert isinstance(_ab("Duck"), tb.DuckDuckGo)

def deep():
    for name in "DT: Google", "Pons Dict", "DT: Libre":
        assert isinstance(_ab(name), tb.DeepTranslator)
    assert isinstance(_ab("DTA: Any"), tb.DeepTransApi)

def classes():
    assert len(tb.BackendUtils.subclasses()) >= 10

def dec_silence():
    func = tb.BackendUtils.silence(lambda x: undef)
    func(2)

def dec_from_words():
    ls = []
    func = tb.BackendUtils.from_words(lambda text: ls.append(text))
    func("one two three")
    assert len(ls) == 3

