本文整理汇总了Python中exe.engine.configparser.ConfigParser.get方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.get方法的具体用法?Python ConfigParser.get怎么用?Python ConfigParser.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类exe.engine.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testFromScratch
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import get [as 别名]
def testFromScratch(self):
"""
Tests adding stuff from nothing
"""
x = ConfigParser()
testing = x.addSection('testing')
assert x.testing is testing
testing.myval = 4
self.assertEquals(x.get('testing', 'myval'), '4')
示例2: TestConfigParser
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import get [as 别名]
#.........这里部分代码省略.........
try:
data = file_.read()
assert data == '[main]\ntesting = de repente', data
finally:
file_.close()
os.remove('temp.ini')
def testWriteFromFileName(self):
"""If we pass write a file name, it should open or create that file
and write or update it"""
if os.path.exists('temp.ini'):
os.remove('temp.ini')
self.c.set('main', 'testing', 'de repente')
self.c.write('temp.ini')
file_ = open('temp.ini')
try:
data = file_.read()
assert data == '[main]\ntesting = de repente', data
finally:
file_.close()
os.remove('temp.ini')
# Test updating an existing file
self.c.set('main', 'testing', 'ok')
self.c.write('temp.ini')
file_ = open('temp.ini')
try:
data = file_.read()
assert data == '[main]\ntesting = ok', data
finally:
file_.close()
os.remove('temp.ini')
def testGet(self):
"""Tests the get method"""
file_ = testFile()
self.c.read(file_)
assert self.c.get('main', 'testing') == 'false'
assert self.c.get('main', 'not exists', 'default') == 'default'
self.failUnlessRaises(ValueError, self.c.get, 'main', 'not exists')
def testSet(self):
"""Test the set method"""
file_ = testFile()
self.c.read(file_)
# An existing option
self.c.set('main', 'testing', 'perhaps')
assert self.c._sections['main']['testing'] == 'perhaps'
# A new and numeric option
self.c.set('main', 'new option', 4.1)
self.assertEquals(self.c._sections['main']['new option'], '4.1')
# A new option in a new section
self.c.set('new section', 'new option', 4.1)
assert self.c._sections['new section']['new option'] == '4.1'
def testDel(self):
"""Should be able to delete a section and/or a value in a section"""
file_ = testFile()
self.c.read(file_)
assert self.c._sections['main']['level'] == '5'
self.c.delete('main', 'level')
assert not self.c._sections['main'].has_key('level')
self.c.delete('main')
assert not self.c._sections.has_key('main')
def testShortening(self):
"""There was a bug (Issue 66) where when a longer name was read
示例3: TestSections
# 需要导入模块: from exe.engine.configparser import ConfigParser [as 别名]
# 或者: from exe.engine.configparser.ConfigParser import get [as 别名]
class TestSections(unittest.TestCase):
"""
Tests Section objects.
Section objects allow an easy way to read and write
"""
def setUp(self):
"""
Creates a ConfigParser to play with and
reads in the test text
"""
self.c = ConfigParser()
file_ = testFile()
self.c.read(file_)
def testSectionCreation(self):
"""
Tests that the configuration object
creates the section objects ok
"""
assert isinstance(self.c.main, Section)
assert isinstance(self.c.second, Section)
self.failUnlessRaises(AttributeError, lambda: self.c.notexist)
def testFromScratch(self):
"""
Tests adding stuff from nothing
"""
x = ConfigParser()
testing = x.addSection('testing')
assert x.testing is testing
testing.myval = 4
self.assertEquals(x.get('testing', 'myval'), '4')
def testAttributeRead(self):
"""
Tests that we can read attributes from sections
"""
assert self.c.main.level == '5'
assert self.c.main.power == 'on'
self.failUnlessRaises(AttributeError, lambda: self.c.main.notexist)
def testAttributeWrite(self):
"""
Tests that we can set attributes with sections
"""
self.c.main.level = 7
# Should be automatically converted to string also :)
self.assertEquals(self.c.get('main', 'level'), '7')
self.c.main.new = 'hello'
assert self.c.get('main', 'new') == 'hello'
def testAttributeDel(self):
"""
Tests that we can remove attributes from the config file
by removing the sections
"""
del self.c.main.level
assert not self.c.has_option('main', 'level')
def testSectionDel(self):
"""
Tests that we can remove whole sections
by deleting them
"""
del self.c.main
assert not self.c.has_section('main')
def delete(): del self.c.notexist
self.failUnlessRaises(AttributeError, delete)
def testParserIn(self):
"""
To test if a section exists, use the in operator
"""
assert 'main' in self.c
assert 'notexist' not in self.c
# Dotted format
assert 'main.level' in self.c
assert 'main.notexist' not in self.c
# And the sections can do it too
assert 'notexist' not in self.c.main
# Also the hasattr should give the same result
assert hasattr(self.c, 'main')
assert not hasattr(self.c, 'notexist')
assert hasattr(self.c, 'main.level')
assert hasattr(self.c.main, 'level')
assert not hasattr(self.c.main, 'notexist')
def testGet(self):
"""
System should have a get section for those funny
names that can't be attributes
"""
assert self.c.second.get('funny-name_mate') == 'crusty the clown'
def testCreation(self):
"""
When one creates a section with the same name
as an existing section the existing section should
just be returned
#.........这里部分代码省略.........