Skip to content

Commit

Permalink
Fix osfs:/ directory leftover in CWD after tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matrss committed May 16, 2024
1 parent 531cb75 commit e1dd46d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
4 changes: 3 additions & 1 deletion mslib/msui/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
HOME = os.path.expanduser(f"~{os.path.sep}")
MSUI_CONFIG_PATH = os.getenv("MSUI_CONFIG_PATH", os.path.join(HOME, ".config", "msui"))
# Make sure that MSUI_CONFIG_PATH exists
_ = fs.open_fs(MSUI_CONFIG_PATH, create=True)
_fs = fs.open_fs(MSUI_CONFIG_PATH, create=True)
# MSUI does not actually support any PyFilesystem2 fs that is not available as a local path
MSUI_CONFIG_SYSPATH = _fs.getsyspath("")

GRAVATAR_DIR_PATH = fs.path.join(MSUI_CONFIG_PATH, "gravatars")

Expand Down
14 changes: 4 additions & 10 deletions mslib/utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@
See the License for the specific language governing permissions and
limitations under the License.
"""

import sys
from PyQt5 import QtCore

import copy
Expand Down Expand Up @@ -457,7 +455,7 @@ def config_loader(dataset=None, default=False):
return user_options


def save_settings_qsettings(tag, settings, ignore_test=False):
def save_settings_qsettings(tag, settings):
"""
Saves a dictionary settings to disk.
Expand All @@ -467,10 +465,8 @@ def save_settings_qsettings(tag, settings, ignore_test=False):
"""
assert isinstance(tag, str)
assert isinstance(settings, dict)
if not ignore_test and ("pytest" in sys.modules):
return settings
# ToDo we have to verify if we can all switch to this definition, not having 3 different
q_settings = QtCore.QSettings(os.path.join(constants.MSUI_CONFIG_PATH, "msui-core.conf"),
q_settings = QtCore.QSettings(os.path.join(constants.MSUI_CONFIG_SYSPATH, "msui-core.conf"),
QtCore.QSettings.IniFormat)

file_path = q_settings.fileName()
Expand All @@ -482,7 +478,7 @@ def save_settings_qsettings(tag, settings, ignore_test=False):
return settings


def load_settings_qsettings(tag, default_settings=None, ignore_test=False):
def load_settings_qsettings(tag, default_settings=None):
"""
Loads a dictionary of settings from disk. May supply a dictionary of default settings
to return in case the settings file is not present or damaged. The default_settings one will
Expand All @@ -496,12 +492,10 @@ def load_settings_qsettings(tag, default_settings=None, ignore_test=False):
if default_settings is None:
default_settings = {}
assert isinstance(default_settings, dict)
if not ignore_test and "pytest" in sys.modules:
return default_settings

settings = {}

q_settings = QtCore.QSettings(os.path.join(constants.MSUI_CONFIG_PATH, "msui-core.conf"),
q_settings = QtCore.QSettings(os.path.join(constants.MSUI_CONFIG_SYSPATH, "msui-core.conf"),
QtCore.QSettings.IniFormat)
file_path = q_settings.fileName()
logging.debug("loading settings for %s from %s", tag, file_path)
Expand Down
6 changes: 3 additions & 3 deletions tests/_test_utils/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class TestSettingsSave:

def test_save_settings(self):
settings = {'foo': 'bar'}
config.save_settings_qsettings(self.tag, settings, ignore_test=True)
config.save_settings_qsettings(self.tag, settings)

def test_load_settings(self):
settings = {'foo': 'bar'}
config.save_settings_qsettings(self.tag, settings, ignore_test=True)
settings = config.load_settings_qsettings(self.tag, ignore_test=True)
config.save_settings_qsettings(self.tag, settings)
settings = config.load_settings_qsettings(self.tag)
assert isinstance(settings, dict)
assert settings["foo"] == "bar"

Expand Down

0 comments on commit e1dd46d

Please sign in to comment.