本文整理汇总了Python中exe.engine.configparser.ConfigParser.set方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.set方法的具体用法?Python ConfigParser.set怎么用?Python ConfigParser.set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testShortening
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import set [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', '')
示例2: TestConfigParser
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import set [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')
#.........这里部分代码省略.........