def mock_config(self): """Return a mocked editConf Both default and user config used the same config-*.def """ conf = config.editConf(_utest=True) for ctype in conf.config_types: conf.defaultCfg[ctype] = config.editConfParser('') conf.defaultCfg[ctype].read_string(self.config_string[ctype]) conf.userCfg[ctype] = config.editUserConfParser('') conf.userCfg[ctype].read_string(self.config_string[ctype]) return conf
def test_load_cfg_files(self): conf = self.new_config(_utest=True) # Borrow test/cfgparser.1 from test_configparser. config_path = findfile('cfgparser.1') conf.defaultCfg['foo'] = config.editConfParser(config_path) conf.userCfg['foo'] = config.editUserConfParser(config_path) # Load all config from path conf.LoadCfgFiles() eq = self.assertEqual # Check defaultCfg is loaded eq(conf.defaultCfg['foo'].Get('Foo Bar', 'foo'), 'newbar') eq(conf.defaultCfg['foo'].GetOptionList('Foo Bar'), ['foo']) # Check userCfg is loaded eq(conf.userCfg['foo'].Get('Foo Bar', 'foo'), 'newbar') eq(conf.userCfg['foo'].GetOptionList('Foo Bar'), ['foo'])
from edit import configdialog from test.support import requires requires('gui') import unittest from unittest import mock from edit.edit_test.mock_edit import Func from tkinter import Tk, StringVar, IntVar, BooleanVar, DISABLED, NORMAL from edit import config from edit.configdialog import editConf, changes, tracers # Tests should not depend on fortuitous user configurations. # They must not affect actual user .cfg files. # Use solution from test_config: empty parsers with no filename. usercfg = editConf.userCfg testcfg = { 'main': config.editUserConfParser(''), 'highlight': config.editUserConfParser(''), 'keys': config.editUserConfParser(''), 'extensions': config.editUserConfParser(''), } root = None dialog = None mainpage = changes['main'] highpage = changes['highlight'] keyspage = changes['keys'] extpage = changes['extensions'] def setUpModule(): global root, dialog
def new_parser(self, path=''): return config.editUserConfParser(path)
import tempfile from test.support import captured_stderr, findfile import unittest from unittest import mock import edit from edit.edit_test.mock_edit import Func # Tests should not depend on fortuitous user configurations. # They must not affect actual user .cfg files. # Replace user parsers with empty parsers that cannot be saved # due to getting '' as the filename when created. editConf = config.editConf usercfg = editConf.userCfg testcfg = {} usermain = testcfg['main'] = config.editUserConfParser('') userhigh = testcfg['highlight'] = config.editUserConfParser('') userkeys = testcfg['keys'] = config.editUserConfParser('') userextn = testcfg['extensions'] = config.editUserConfParser('') def setUpModule(): editConf.userCfg = testcfg edit.testing = True def tearDownModule(): editConf.userCfg = usercfg edit.testing = False