def test_saveload(tmpdir, monkeypatch, sound): import copy import os tcfg = xindir(tmpdir, 'new.cfg') monkeypatch.syspath_prepend('.') import appconfig appconf = appconfig.appconfig(TESTAPPNAME, TESTAPPVER, tcfg) conf = appconf.config assert equaldicts(conf, {'sounds': {}, 'profiles': {}, 'active_profile': None}) sfile = xindir(tmpdir, sound['file']) conf['sounds'][sound['name']] = sfile # every sound file has to exist for the load to happen touch(sfile) assert os.path.isfile(sfile) refconf = copy.deepcopy(conf) appconf.writeconfig() assert os.path.isfile(tcfg) appconf2 = appconfig.appconfig(TESTAPPNAME, TESTAPPVER, tcfg) appconf2.readconfig() newconf = appconf2.config assert equaldicts(newconf, refconf) assert newconf['sounds'][sound['name']] == sfile del newconf, refconf, appconf, appconf2, conf, tcfg monkeypatch.undo()
def test_loadinexistent(tmpdir, monkeypatch): tcfg = str(tmpdir) + 'inexistent' monkeypatch.syspath_prepend('.') import appconfig appconf = appconfig.appconfig('TestApp', TESTAPPVER, tcfg) from ConfigParser import NoSectionError pytest.raises(IOError, "appconf.readconfig()") monkeypatch.undo()
def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) # TODO: add profiles self.ui = Ui_MainWindow() self._soundcontainer = soundContainer() self._profilecontainer = profileContainer(self._soundcontainer) self.ui.setupUi(self) appconf = appconfig(appname, appver) appconf.readconfig() config = appconf.config self.dict_loadConfig(config) #self.dict_updateActiveProfileUi() self.dict_initSlots()
def test_defaultconfigload(tmpdir,monkeypatch,cfgfile, soundfilesdict): import shutil import os os.path.isfile(cfgfile) monkeypatch.syspath_prepend('.') monkeypatch.setenv("XDG_CONFIG_HOME", tmpdir) monkeypatch.setenv("XDG_DATA_HOME", tmpdir) expectcfgdir = xindir(tmpdir, TESTAPPNAME) from miscutil import mkdir_p mkdir_p(expectcfgdir) os.path.isdir(expectcfgdir) tcfg = xindir(expectcfgdir, 'config.ini') shutil.copyfile(cfgfile,tcfg) makesoundsindir(expectcfgdir, soundfilesdict) import appconfig appconf = appconfig.appconfig(TESTAPPNAME, TESTAPPVER) appconf.readconfig() conf = appconf.config assert len(conf) == 3 assert len(conf['sounds']) == 2 assert len(conf['profiles']) == 1 monkeypatch.undo()