def export_txt_file(self, message_to_save):
     while True:
         try:
             save_txt_file(message_to_save)
             break
         except UndefinedFileName as Message:
             print(f'{Message}. Insert proper name for the file')
         except WrongFileName as Message:
             print(f'{Message}. Give your file a different name')
Example #2
0
def test_save_txt_file_empty_name(monkeypatch):
    name_of_the_file = '\n'
    monkeypatch.setattr('sys.stdin', StringIO(name_of_the_file))
    with pytest.raises(UndefinedFileName):
        save_txt_file(name_of_the_file)
Example #3
0
def test_save_txt_file_incorrect_name_without_extension(monkeypatch):
    wrong_file_name = 'text.'
    monkeypatch.setattr('sys.stdin', StringIO(wrong_file_name))
    with pytest.raises(WrongFileName):
        save_txt_file('text')
Example #4
0
def test_save_txt_file_incorrect_name(monkeypatch):
    wrong_file_name = 'text_'
    # Monkey patch input() function
    monkeypatch.setattr('sys.stdin', StringIO(wrong_file_name))
    with pytest.raises(WrongFileName):
        save_txt_file('text')