本文整理汇总了Python中exe.engine.configparser.ConfigParser.write方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.write方法的具体用法?Python ConfigParser.write怎么用?Python ConfigParser.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.write方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testUpgradeAppDir
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import write [as 别名]
def testUpgradeAppDir(self):
"""
Tests that config files with
'appDataDir' are upgraded to 'configDir'
"""
# Write the old style config file
configPath = Path(u'test.exe.conf')
if configPath.exists():
configPath.remove()
oldParser = ConfigParser()
system = oldParser.addSection('system')
system.appDataDir = 'my old app data dir'
oldParser.write(configPath)
del system
del oldParser
# Make the config instance load it
Config._getConfigPathOptions = lambda self: ['test.exe.conf']
myconfig = Config()
myconfig.loadSettings()
# Check if it reads the old value into the new variable
assert not hasattr(myconfig, 'appDataDir')
self.assertEquals(myconfig.configPath, 'test.exe.conf')
self.assertEquals(myconfig.configDir, 'my old app data dir')
# Check if it has upgraded the file and added in some nice default values
newParser = ConfigParser()
newParser.read(configPath)
self.assertEquals(newParser.system.configDir, 'my old app data dir')
示例2: setUp
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import write [as 别名]
def setUp(self):
"""
Creates an application and
almost launches it.
"""
# Make whatever config class that application uses only look for our
# Set up our customised config file
logFileName = Path('tmp/app data/test.conf')
sys.argv[0] = 'exe/exe'
Config._getConfigPathOptions = lambda s: [logFileName]
if not logFileName.dirname().exists():
logFileName.dirname().makedirs()
confParser = ConfigParser()
self._setupConfigFile(confParser)
confParser.write(logFileName)
# Start up the app and friends
if G.application is None:
G.application = Application()
self.app = G.application
G.application = self.app
self.app.loadConfiguration()
self.app.preLaunch()
self.client = FakeClient()
self.package = Package('temp')
self.session = FakeSession()
self.app.webServer.root.bindNewPackage(self.package, self.session)
self.mainpage = self.app.webServer.root.mainpages[self.session.uid]['temp']
self.mainpage.idevicePane.client = self.client
示例3: testShortening
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import write [as 别名]
def testShortening(self):
"""There was a bug (Issue 66) where when a longer name was read
and a shorter name was written, the extra characters of the
longer name would remain in the entry"""
file_ = open('temp.ini', 'w')
file_.write(TEST_TEXT)
file_.close()
self.c.read('temp.ini')
self.c.set('second', 'available', 'abcdefghijklmnop')
self.c.write('temp.ini')
c2 = ConfigParser()
c2.read('temp.ini')
c2.set('second', 'available', 'short')
c2.write('temp.ini')
self.c.read('temp.ini')
assert self.c.get('second', 'available', '') == 'short', \
self.c.get('second', 'available', '')
示例4: check_application_for_test
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import write [as 别名]
def check_application_for_test(cls):
logFileName = Path('tmp/app data/test.conf')
sys.argv[0] = 'exe/exe'
Config._getConfigPathOptions = lambda s: [logFileName]
if not logFileName.dirname().exists():
logFileName.dirname().makedirs()
confParser = ConfigParser()
SuperTestCase.update_config_parser(confParser)
confParser.write(logFileName)
if G.application is None:
G.application = Application()
G.application.loadConfiguration()
SuperTestCase.update_config_parser(G.application.config.configParser)
G.application.config.loadSettings()
G.application.preLaunch()
示例5: setUp
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import write [as 别名]
def setUp(self):
"""
Creates an application and
almost launches it.
"""
logFileName = Path('tmp/app data/test.conf')
Config._getConfigPathOptions = lambda s: [logFileName]
if not logFileName.dirname().exists():
logFileName.dirname().makedirs()
confParser = ConfigParser()
self._setupConfigFile(confParser)
confParser.write(logFileName)
self.app = Application()
self.app.loadConfiguration()
self.app.preLaunch()
self.client = FakeClient()
self.package = Package('temp')
self.app.webServer.root.bindNewPackage(self.package)
self.mainpage = self.app.webServer.root.children['temp']
示例6: TestConfigParser
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import write [as 别名]
class TestConfigParser(unittest.TestCase):
"""
Tests the main ConfigParser class
"""
def setUp(self):
"""
Creates a ConfigParser to play with
"""
self.c = ConfigParser()
def testRead(self):
"""Ensures that it can read from a file correctly"""
file_ = testFile()
self.c.read(file_)
assert self.c._sections == {'second':
{'good': 'yes',
'bad': 'no',
'available': 'yes',
'funny-name_mate': 'crusty the clown'},
'main':
{'running': u'on\t\u0100\u01100',
'testing': 'false',
'two words': 'are better than one',
'no_value': '',
'power': 'on', 'level': '5'}
}, self.c._sections
def testReadFileName(self):
"""Can read text"""
goodDict = {'second':
{'good': 'yes',
'bad': 'no',
'available': 'yes',
'funny-name_mate': 'crusty the clown'},
'main':
{'running': u'on\t\u0100\u01100',
'testing': 'false',
'two words': 'are better than one',
'no_value': '',
'power': 'on',
'level': '5'}}
file_ = open('temp.ini', 'w')
file_.write(TEST_TEXT)
file_.close()
self.c.read('temp.ini')
assert self.c._sections == goodDict, self.c._sections
# Can read unicode filenames
self.c = ConfigParser()
self.c.read(u'temp.ini')
assert self.c._sections == goodDict, self.c._sections
# Can read funny string object filenames
class MyStr(str):
"""Simply overrides string to make it a different type"""
self.c.read(MyStr('temp.ini'))
assert self.c._sections == goodDict, self.c._sections
def testWrite(self):
"""Test that it writes the file nicely"""
file_ = testFile()
self.c.read(file_)
# Remove an option
del self.c._sections['main']['testing']
# Change an option
self.c._sections['second']['bad'] = 'definately not! '
# Add an option
self.c._sections['second']['squishy'] = 'Indeed'
# Add a section at the end
self.c._sections['middle'] = {'is here': 'yes'}
# write the file
file_.seek(0)
self.c.write(file_)
file_.seek(0)
result = file_.readlines()
result = map(unicode, result, ['utf8']*len(result))
goodResult = ['nosection=here\n',
'[main]\n',
'level=5\n',
'power : on\n',
u'running =on\t\u0100\u01100\n',
'two words = \tare better than one\n',
'no_value = \n',
'\n', '\n',
'[second]\n',
'good :yes\n',
'bad:\tdefinately not! \n',
'# comment=1\n',
'~comment2=2\n',
'available\t= yes\n',
'funny-name_mate: crusty the clown\n',
'squishy = Indeed\n',
'\n',
'[middle]\n',
'is here = yes']
if result != goodResult:
print
for good, got in zip(goodResult, result):
if good != got:
print 'Different', repr(good), repr(got)
self.fail('See above printout')
#.........这里部分代码省略.........