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')
Example #2
0
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)
Example #3
0
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')
Example #4
0
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')