File size: 1,402 Bytes
97fe725
 
 
 
 
7a05cd7
 
97fe725
 
 
 
78d0ff1
97fe725
 
 
 
 
 
78d0ff1
97fe725
 
 
4524f4c
5a13ae6
97fe725
4524f4c
 
 
 
 
97fe725
a1efbe8
 
 
 
 
97fe725
 
 
 
 
 
 
 
 
 
 
f36740b
 
78d0ff1
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
50
51
#!/usr/bin/env python

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

import pytest

from deep_translator import LingueeTranslator, exceptions


@pytest.fixture
def linguee():
    return LingueeTranslator(source="english", target="german")


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


def test_inputs():
    with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
        LingueeTranslator(source="", target="")

    with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
        LingueeTranslator(source="auto", target="")

    with pytest.raises(exceptions.InvalidSourceOrTargetLanguage):
        LingueeTranslator(source="", target="en")

    l1 = LingueeTranslator("en", "fr")
    l2 = LingueeTranslator("english", "french")
    assert l1._source == l2._source
    assert l1._target == l2._target


def test_payload(linguee):

    with pytest.raises(exceptions.NotValidPayload):
        linguee.translate(123)

    with pytest.raises(exceptions.NotValidPayload):
        linguee.translate({})

    with pytest.raises(exceptions.NotValidPayload):
        linguee.translate([])

    with pytest.raises(exceptions.NotValidLength):
        linguee.translate("a" * 51)