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')
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)
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')
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')