def test_save_unable_to_write(mocked_logger): """When a settings object can't be written log an exception""" settings = mu.settings.SettingsBase() settings.filepath = os.curdir # this should fail on every platform settings.save() assert mocked_logger.exception.called
def test_save_unable_to_encode(mocked_logger, mocked_open): """When a settings object can't be written log an exception and exit""" settings = mu.settings.SettingsBase() settings.filepath = rstring() settings[rstring()] = object() settings.save() assert not mocked_open.called assert mocked_logger.exception.called
def test_save_no_filepath(mocked_logger): """When a settings object has no filepath save will warn and exit""" settings = mu.settings.SettingsBase() settings.as_string = mock.Mock() settings.filepath = None # (just in case) settings.save() assert mocked_logger.warn.called assert not settings.as_string.called
def test_save_only_changed(mocked_open): """When a settings object is saved only changed items are written""" settings = mu.settings.SettingsBase() settings.filepath = rstring() settings.as_string = mock.Mock(return_value=rstring()) settings.save() assert settings.as_string.called_with(changed_only=True) assert mocked_open.called_with(settings.filepath, "w")
def test_save_readonly(mocked_logger): """When a settings object is readonly save will warn and exit""" settings = mu.settings.SettingsBase() settings.as_string = mock.Mock() settings.readonly = True settings.save() assert mocked_logger.warn.called assert not settings.as_string.called