File size: 1,403 Bytes
97fe725
 
 
 
 
5a13ae6
97fe725
 
 
 
8ecada8
97fe725
 
 
 
 
 
 
 
 
 
 
5a13ae6
97fe725
 
5a13ae6
a1efbe8
 
 
 
97fe725
f36740b
97fe725
 
 
 
 
 
 
 
 
 
 
 
 
f36740b
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python

"""Tests for `deep_translator` package."""

import pytest
from deep_translator import exceptions, MyMemoryTranslator


@pytest.fixture
def mymemory():
    return MyMemoryTranslator(source="en", target='fr')


def test_content(mymemory):
    """Sample pytest test function with the pytest fixture as an argument."""
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
    assert mymemory.translate(text='good') is not None


def test_inputs():
    with pytest.raises(exceptions.LanguageNotSupportedException):
        MyMemoryTranslator(source="", target="")

    with pytest.raises(exceptions.LanguageNotSupportedException):
        MyMemoryTranslator(source="auto", target="nothing")
    m1 = MyMemoryTranslator("en", "fr")
    m2 = MyMemoryTranslator("english", "french")
    assert m1._source == m2._source
    assert m1._target == m2._target


def test_payload(mymemory):

    with pytest.raises(exceptions.NotValidPayload):
        mymemory.translate(text="")

    with pytest.raises(exceptions.NotValidPayload):
        mymemory.translate(text=123)

    with pytest.raises(exceptions.NotValidPayload):
        mymemory.translate(text={})

    with pytest.raises(exceptions.NotValidPayload):
        mymemory.translate(text=[])

    with pytest.raises(exceptions.NotValidLength):
        mymemory.translate(text="a"*501)