Exemplo n.º 1
0
def test_invalid_token(test_file_token):
    with open(test_file_path_token, "w") as token_file:
        token_file.write("InvalidToken")

    tranl_object = GoogleTranslate(test_file_path_token)
    with pytest.raises(requests.exceptions.HTTPError, match=r"401"):
        tranl_object.translate("Hello", "he")
Exemplo n.º 2
0
def test_token_file_multiple_lines(test_file_token):
    with open(test_file_path_token, "w") as token_file:
        token_file.write("InvalidToken\n")
        token_file.write("InvalidToken2")

    with pytest.raises(ValueError,
                       match=r"There are more than 1 lines in token file"):
        GoogleTranslate(test_file_path_token)
Exemplo n.º 3
0
def test_user_input_invalid_option2(input_from_str_invalid_option2):
    tranl_object = GoogleTranslate()
    assert not tranl_object.translate_input_from_user()
Exemplo n.º 4
0
def test_user_input_exit(input_from_str_exit):
    tranl_object = GoogleTranslate()
    assert not tranl_object.translate_input_from_user()
Exemplo n.º 5
0
def test_user_input_heb_implicit(input_from_str_he_implicit):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "Hey"
Exemplo n.º 6
0
def test_translate_no_opt_params_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en", "he") == "Hello"
Exemplo n.º 7
0
def test_success_no_assert():
    tranl_object = GoogleTranslate()
    tranl_object.translate("hello", "he")
Exemplo n.º 8
0
def test_invalid_token_file():
    with pytest.raises(FileNotFoundError, match="token"):
        GoogleTranslate("../resources/token_invalid.txt")
Exemplo n.º 9
0
def test_translate_format_html_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en", None, "html") == "Hello"
Exemplo n.º 10
0
def test_translate_format_html_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he", None, "html") == "שלום"
Exemplo n.º 11
0
def test_translate_source_explicit_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en", "he") == "Hello"
Exemplo n.º 12
0
def test_translate_source_explicit_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he", "en") == "שלום"
Exemplo n.º 13
0
def test_translate_auto_detect_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en") == "Hello"
Exemplo n.º 14
0
def test_translate_auto_detect_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he") == "שלום"
Exemplo n.º 15
0
def test_user_input_eng_long_option_explicit(input_from_str_long_option_en):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "היי"
Exemplo n.º 16
0
def test_user_input_eng_long_text_explicit(input_from_str_long_string_en):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "שלום עולם"
Exemplo n.º 17
0
def test_invalid_format():
    tranl_object = GoogleTranslate()
    with pytest.raises(requests.exceptions.HTTPError,
                       match="400 Client Error: Bad Request"):
        tranl_object.translate("Hello", "he", "en", "invalid_format")
Exemplo n.º 18
0
def test_empty_string():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("", "he", "en") == ""
Exemplo n.º 19
0
def test_translate_string_given():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he") == "שלום"
Exemplo n.º 20
0
def test_invalid_url():
    tranl_object = GoogleTranslate(GoogleTranslate.token_file_path,
                                   GoogleTranslate.translate_url + "_")
    with pytest.raises(requests.exceptions.HTTPError,
                       match="404 Client Error: Not Found for url"):
        tranl_object.translate("Hello", "he")
Exemplo n.º 21
0
def test_user_input_eng_implicit(input_from_str_en_implicit):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "היי"
Exemplo n.º 22
0
def test_success_with_assert():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he") == "שלום"
Exemplo n.º 23
0
def test_translate_no_opt_params_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he", "en") == "שלום"