def call_set_default_chart_save_location(): """ Calls set_default_chart_save_location(user_set=True) :return: None """ set_default_chart_save_location(user_set=True) print('\n\n')
def test_set_default_chart_save_location_user_set_false(self, mocked_user_set_chart_save_folder, mocked_save_new_default_chart_save_location_setting, mocked_create_chart_save_folder, ): assert set_default_chart_save_location(False) is None mocked_user_set_chart_save_folder.assert_not_called() mocked_save_new_default_chart_save_location_setting.assert_called_once_with( self.app_default_chart_save_folder_path) mocked_create_chart_save_folder.assert_called_once_with(self.app_default_chart_save_folder_path, self.mocked_DEFAULT_CHART_SAVE_FOLDER)
def test_set_default_chart_save_location_user_set_true_location_supplied( self, mocked_user_set_chart_save_folder, mocked_save_new_default_chart_save_location_setting, mocked_create_chart_save_folder, mocked_definitions): mocked_definitions.DEFAULT_CHART_SAVE_FOLDER = self.mocked_DEFAULT_CHART_SAVE_FOLDER mocked_user_set_chart_save_folder.return_value = self.user_supplied_location assert set_default_chart_save_location(True) is None mocked_user_set_chart_save_folder.assert_called_once_with() mocked_save_new_default_chart_save_location_setting.assert_called_once_with( self.user_set_location_fullpath) mocked_create_chart_save_folder.assert_called_once_with(self.user_set_location_fullpath, self.mocked_DEFAULT_CHART_SAVE_FOLDER) assert mocked_definitions.DEFAULT_CHART_SAVE_FOLDER == self.user_set_location_fullpath
def test_set_default_chart_save_location(self, monkeypatch, user_setting_location, user_supplied_location): def mocked_user_set_chart_save_folder(): if not user_setting_location: raise ValueError( 'Should not be called if user input is not expected.') # On no user input, function returns the app default. return user_supplied_location or settings_functions.APP_DEFAULT_CHART_SAVE_DIR def mocked_save_new_default_chart_save_location_setting( new_chart_save_folder_path): if new_chart_save_folder_path != test_new_chart_save_location: raise ValueError( f'Wrong new location path: ' f'new_chart_save_folder_path={new_chart_save_folder_path}!={test_new_chart_save_location}' ) def mocked_create_chart_save_folder(new_chart_save_folder_path, original_location): if new_chart_save_folder_path != test_new_chart_save_location: raise ValueError( f'Wrong new location path: ' f'new_chart_save_folder_path={new_chart_save_folder_path}!={test_new_chart_save_location}' ) if original_location != test_original_chart_save_folder_location: raise ValueError( f'Wrong original chart save folder location: ' f'{original_location}!={settings_functions.definitions.DEFAULT_CHART_SAVE_DIR}' ) # monkeypatch.setattr(settings_functions, 'APP_DEFAULT_CHART_SAVE_DIR', # Path('mock_APP_DEFAULT_CHART_SAVE_DIR')) monkeypatch.setattr(settings_functions, 'CHART_SAVE_DIR_NAME', 'mocked_CHART_SAVE_DIR_NAME') monkeypatch.setattr(settings_functions.definitions, 'DEFAULT_CHART_SAVE_DIR', Path('mock_APP_DEFAULT_CHART_SAVE_DIR')) monkeypatch.setattr(settings_functions, 'user_set_chart_save_folder', mocked_user_set_chart_save_folder) monkeypatch.setattr(settings_functions, 'create_chart_save_folder', mocked_create_chart_save_folder) monkeypatch.setattr( settings_functions, 'save_new_default_chart_save_location_setting', mocked_save_new_default_chart_save_location_setting) # Original chart save folder location: test_original_chart_save_folder_location = Path( 'mock_APP_DEFAULT_CHART_SAVE_DIR') # Pretest definitions. assert settings_functions.definitions.DEFAULT_CHART_SAVE_DIR == test_original_chart_save_folder_location # Expected new location: test_new_chart_save_location = Path( settings_functions.APP_DEFAULT_CHART_SAVE_DIR, settings_functions. CHART_SAVE_DIR_NAME) # App default if no user input. if user_supplied_location: test_new_chart_save_location = Path.joinpath( user_supplied_location, settings_functions.CHART_SAVE_DIR_NAME) assert set_default_chart_save_location(user_setting_location) is None # Runtime setting changed. assert settings_functions.definitions.DEFAULT_CHART_SAVE_DIR == test_new_chart_save_location