def export_json_file(self, settings): while True: try: save_json_file(settings) 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_json_file_empty_name(monkeypatch): name_of_the_file = '\n' monkeypatch.setattr('sys.stdin', StringIO(name_of_the_file)) with pytest.raises(UndefinedFileName): save_json_file(name_of_the_file)
def test_save_json_file_incorrect_name_without_extension(monkeypatch): wrong_file_name = 'text.' monkeypatch.setattr('sys.stdin', StringIO(wrong_file_name)) with pytest.raises(WrongFileName): save_json_file('text')
def test_save_json_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_json_file('text')