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")
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)
def test_user_input_invalid_option2(input_from_str_invalid_option2):
    tranl_object = GoogleTranslate()
    assert not tranl_object.translate_input_from_user()
def test_user_input_exit(input_from_str_exit):
    tranl_object = GoogleTranslate()
    assert not tranl_object.translate_input_from_user()
def test_user_input_heb_implicit(input_from_str_he_implicit):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "Hey"
def test_translate_no_opt_params_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en", "he") == "Hello"
def test_success_no_assert():
    tranl_object = GoogleTranslate()
    tranl_object.translate("hello", "he")
def test_invalid_token_file():
    with pytest.raises(FileNotFoundError, match="token"):
        GoogleTranslate("../resources/token_invalid.txt")
def test_translate_format_html_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en", None, "html") == "Hello"
def test_translate_format_html_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he", None, "html") == "שלום"
def test_translate_source_explicit_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en", "he") == "Hello"
def test_translate_source_explicit_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he", "en") == "שלום"
def test_translate_auto_detect_heb_to_eng():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("שלום", "en") == "Hello"
def test_translate_auto_detect_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he") == "שלום"
def test_user_input_eng_long_option_explicit(input_from_str_long_option_en):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "היי"
def test_user_input_eng_long_text_explicit(input_from_str_long_string_en):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "שלום עולם"
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")
def test_empty_string():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("", "he", "en") == ""
def test_translate_string_given():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he") == "שלום"
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")
def test_user_input_eng_implicit(input_from_str_en_implicit):
    tranl_object = GoogleTranslate()
    assert tranl_object.translate_input_from_user() == "היי"
def test_success_with_assert():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he") == "שלום"
def test_translate_no_opt_params_en_to_heb():
    tranl_object = GoogleTranslate()
    assert tranl_object.translate("hello", "he", "en") == "שלום"