本文整理汇总了Python中b3.config.XmlConfigParser类的典型用法代码示例。如果您正苦于以下问题:Python XmlConfigParser类的具体用法?Python XmlConfigParser怎么用?Python XmlConfigParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlConfigParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PluginTestCase
class PluginTestCase(unittest.TestCase):
def setUp(self):
# less logging
logging.getLogger('output').setLevel(logging.ERROR)
# create a parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""<configuration></configuration>""")
self.console = DummyParser(self.parser_conf)
self.console.startup()
# load the admin plugin
if B3version(b3_version) >= B3version("1.10dev"):
admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
else:
admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
# prepare a few players
self.joe = FakeClient(self.console, name="Joe", guid="joe_guid", groupBits=1)
self.simon = FakeClient(self.console, name="Simon", guid="simon_guid", groupBits=0)
self.moderator = FakeClient(self.console, name="Moderator", guid="moderator_guid", groupBits=8)
logging.getLogger('output').setLevel(logging.DEBUG)
def tearDown(self):
self.console.working = False
示例2: Test_cmd_serverreboot
class Test_cmd_serverreboot(Bf3TestCase):
def setUp(self):
super(Test_cmd_serverreboot, self).setUp()
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration plugin="poweradminbf3">
<settings name="commands">
<set name="serverreboot">100</set>
</settings>
</configuration>
""")
self.p = Poweradminbf3Plugin(self.console, self.conf)
self.p.onLoadConfig()
self.p.onStartup()
def test_nominal(self, sleep_mock):
self.console.write.expect(('admin.shutDown',))
self.superadmin.connects("god")
self.superadmin.says("!serverreboot")
self.console.write.verify_expected_calls()
def test_frostbite_error(self, sleep_mock):
self.console.write.expect(('admin.shutDown',)).thenRaise(CommandFailedError(['fOO']))
self.superadmin.connects("god")
self.superadmin.message_history = []
self.superadmin.says("!serverreboot")
self.console.write.verify_expected_calls()
self.assertEqual(['Error: fOO'], self.superadmin.message_history)
示例3: B3TestCase
class B3TestCase(unittest.TestCase):
def setUp(self):
testcase_lock.acquire()
flush_console_streams()
# create a FakeConsole parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
self.console.screen = Mock()
self.console.time = time.time
self.console.upTime = Mock(return_value=3)
self.console.cron.stop()
def myError(msg, *args, **kwargs):
print(("ERROR: %s" % msg) % args)
self.console.error = myError
def tearDown(self):
flush_console_streams()
testcase_lock.release()
示例4: CalladminTestCase
class CalladminTestCase(unittest2.TestCase):
def setUp(self):
self.sleep_patcher = patch("time.sleep")
self.sleep_mock = self.sleep_patcher.start()
# create a FakeConsole parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin._commands = {}
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getCvar('sv_hostname').thenReturn(Cvar(name='sv_hostname', value='Test Server'))
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
when(time).time().thenReturn(60)
def tearDown(self):
self.sleep_patcher.stop()
示例5: test_others
class test_others(Arma2TestCase):
def setUp(self):
self.conf = XmlConfigParser()
self.conf.loadFromString("""<configuration></configuration>""")
self.parser = Arma2Parser(self.conf)
self.parser.output = Mock()
self.parser.startup()
self.player = self.parser.clients.newClient(cid="4", guid="theGuid", name="theName", ip="11.22.33.44")
def test_getBanlist(self):
# GIVEN
self.maxDiff = 1024
when(self.parser.output).write("bans").thenReturn("""\
GUID Bans:
[#] [GUID] [Minutes left] [Reason]
----------------------------------------
0 b57c222222a76f458893641000000005 perm Script Detection: Gerk
1 8ac61111111cd2ff4235140000000026 perm Script Detection: setVehicleInit DoThis;""")
# WHEN
rv = self.parser.getBanlist()
# THEN
self.assertDictEqual({
'b57c222222a76f458893641000000005': {'ban_index': '0', 'guid': 'b57c222222a76f458893641000000005', 'reason': 'Script Detection: Gerk', 'min_left': 'perm'},
'8ac61111111cd2ff4235140000000026': {'ban_index': '1', 'guid': '8ac61111111cd2ff4235140000000026', 'reason': 'Script Detection: setVehicleInit DoThis;', 'min_left': 'perm'},
}, rv)
示例6: CensorurtTestCase
class CensorurtTestCase(B3TestCase):
"""
Ease testcases that need an working B3 console and need to control the censorurt plugin config
"""
def setUp(self):
# Timer needs to be patched or the Censor plugin would schedule a 2nd check one minute after
# penalizing a player.
self.timer_patcher = patch('threading.Timer')
self.timer_patcher.start()
self.log = logging.getLogger('output')
self.log.propagate = False
B3TestCase.setUp(self)
self.console.startup()
self.log.propagate = True
self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=b3.TEAM_UNKNOWN)
self.conf = XmlConfigParser()
self.p = CensorurtPlugin(self.console, self.conf)
def tearDown(self):
B3TestCase.tearDown(self)
self.timer_patcher.stop()
def init_plugin(self, config_content):
self.conf.setXml(config_content)
self.log.setLevel(logging.DEBUG)
self.log.info("============================= Censor plugin: loading config ============================")
self.p.onLoadConfig()
self.log.info("============================= Censor plugin: starting =================================")
self.p.onStartup()
示例7: setUp
def setUp(self):
BF3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration>
</configuration>
""")
self.console = Bf3Parser(self.conf)
from b3 import __file__ as b3_module__file__
admin_config_file = os.path.normpath(os.path.join(os.path.dirname(b3_module__file__), "conf/plugin_admin.xml"))
admin_config = XmlConfigParser()
admin_config.load(admin_config_file)
self.adminPlugin = AdminPlugin(self.console, admin_config)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
# monkeypatch the admin plugin
self.console.patch_b3_admin_plugin()
self.changeMap_patcher = patch.object(self.console, "changeMap")
self.changeMap_mock = self.changeMap_patcher.start()
self.player = FakeClient(self.console, name="Player1", guid="Player1GUID", groupBits=128)
self.player.connects("p1")
# GIVEN
self.console.game.gameType = 'ConquestLarge0'
when(self.console).write(('mapList.list', 0)).thenReturn(['4', '3', 'MP_001', 'RushLarge0', '1', 'MP_003',
'ConquestSmall0', '2', 'XP5_001', 'ConquestSmall0',
'2', 'MP_007', 'SquadDeathMatch0', '3'])
when(self.console).write(('mapList.getMapIndices',)).thenReturn(['0', '0'])
示例8: Test_bf3_events
class Test_bf3_events(BF3TestCase):
def setUp(self):
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration>
</configuration>
""")
self.parser = Bf3Parser(self.conf)
self.parser.startup()
def test_cmd_rotateMap_generates_EVT_GAME_ROUND_END(self):
# prepare fake BF3 server responses
def fake_write(data):
if data == ('mapList.getMapIndices', ):
return [0, 1]
else:
return []
self.parser.write = Mock(side_effect=fake_write)
self.parser.getFullMapRotationList = Mock(return_value=MapListBlock(['4', '3', 'MP_007', 'RushLarge0', '4', 'MP_011', 'RushLarge0', '4', 'MP_012',
'SquadRush0', '4', 'MP_013', 'SquadRush0', '4']))
# mock parser queueEvent method so we can make assertions on it later on
self.parser.queueEvent = Mock(name="queueEvent method")
self.parser.rotateMap()
self.assertEqual(1, self.parser.queueEvent.call_count)
self.assertEqual(self.parser.getEventID("EVT_GAME_ROUND_END"), self.parser.queueEvent.call_args[0][0].type)
self.assertIsNone(self.parser.queueEvent.call_args[0][0].data)
示例9: AdminTestCase
class AdminTestCase(unittest.TestCase):
"""
Test case that is suitable for testing EtPro parser specific features with the B3 admin plugin available
"""
@classmethod
def setUpClass(cls):
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# EtproParser -> AbstractParser -> FakeConsole -> Parser
def setUp(self):
self.status_response = None # defaults to STATUS_RESPONSE module attribute
self.conf = XmlConfigParser()
self.conf.loadFromString("""<configuration></configuration>""")
self.parser = EtproParser(self.conf)
self.parser.output = Mock()
self.parser.output.write = Mock(wraps=sys.stdout.write)
adminPlugin_conf = CfgConfigParser()
adminPlugin_conf.load(ADMIN_CONFIG_FILE)
adminPlugin = AdminPlugin(self.parser, adminPlugin_conf)
adminPlugin.onLoadConfig()
adminPlugin.onStartup()
when(self.parser).getPlugin('admin').thenReturn(adminPlugin)
when(self.parser).getCvar('b_privatemessages').thenReturn(Cvar('b_privatemessages', value='1'))
self.parser.startup()
def tearDown(self):
if hasattr(self, "parser"):
del self.parser.clients
self.parser.working = False
示例10: Test_getPlayerPings
class Test_getPlayerPings(BF3TestCase):
def setUp(self):
BF3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration>
</configuration>
""")
self.parser = Bf3Parser(self.conf)
self.p1 = FakeClient(self.parser, name="Player1")
self.p2 = FakeClient(self.parser, name="Player2")
def test_no_player(self):
# WHEN
actual_result = self.parser.getPlayerPings()
# THEN
self.assertDictEqual({}, actual_result)
def test_one_player(self):
# GIVEN
self.p1.connects("Player1")
when(self.parser).write(('player.ping', self.p1.cid)).thenReturn(['140'])
# WHEN
actual_result = self.parser.getPlayerPings()
# THEN
self.assertDictEqual({self.p1.cid: 140}, actual_result)
def test_two_player(self):
# GIVEN
self.p1.connects("Player1")
self.p2.connects("Player2")
when(self.parser).write(('player.ping', self.p1.cid)).thenReturn(['140'])
when(self.parser).write(('player.ping', self.p2.cid)).thenReturn(['450'])
# WHEN
actual_result = self.parser.getPlayerPings()
# THEN
self.assertDictEqual({self.p1.cid: 140, self.p2.cid: 450}, actual_result)
def test_bad_data(self):
# GIVEN
self.p1.connects("Player1")
self.p2.connects("Player2")
when(self.parser).write(('player.ping', self.p1.cid)).thenReturn(['140'])
when(self.parser).write(('player.ping', self.p2.cid)).thenReturn(['f00'])
# WHEN
actual_result = self.parser.getPlayerPings()
# THEN
self.assertDictEqual({self.p1.cid: 140}, actual_result)
def test_exception(self):
# GIVEN
self.p1.connects("Player1")
self.p2.connects("Player2")
when(self.parser).write(('player.ping', self.p1.cid)).thenReturn(['140'])
when(self.parser).write(('player.ping', self.p2.cid)).thenRaise(Exception)
# WHEN
actual_result = self.parser.getPlayerPings()
# THEN
self.assertDictEqual({self.p1.cid: 140}, actual_result)
示例11: Iourt41TestCase
class Iourt41TestCase(Iourt41_TestCase_mixin):
"""
Test case that is suitable for testing Iourt41 parser specific features
"""
def setUp(self):
# create a Iourt41 parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""")
self.console = Iourt41Parser(self.parser_conf)
self.console.write = Mock(name="write", side_effect=write)
self.console.startup()
# load the admin plugin
if B3version(b3_version) >= B3version("1.10dev"):
admin_plugin_conf_file = '@b3/conf/plugin_admin.ini'
else:
admin_plugin_conf_file = '@b3/conf/plugin_admin.xml'
self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file)
self.adminPlugin.onLoadConfig()
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
def tearDown(self):
self.console.working = False
示例12: Test_cmd_yell
class Test_cmd_yell(Bf3TestCase):
def setUp(self):
Bf3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration plugin="poweradminbf3">
<settings name="commands">
<set name="yell">20</set>
</settings>
<settings name="preferences">
<set name="yell_duration">2</set>
</settings>
</configuration>
""")
self.p = Poweradminbf3Plugin(self.console, self.conf)
self.p.onLoadConfig()
self.p.onStartup()
def test_no_argument(self):
self.moderator.connects("moderator")
self.moderator.message_history = []
self.moderator.says("!yell")
self.assertEqual(1, len(self.moderator.message_history))
self.assertEqual('missing parameter, try !help yell', self.moderator.message_history[0])
def test_nominal(self):
self.moderator.connects("moderator")
self.moderator.says("!yell changing map soon !")
self.console.write.assert_called_once_with(('admin.yell', 'changing map soon !', '2'))
示例13: EtTestCase
class EtTestCase(unittest.TestCase):
"""
Test case that is suitable for testing et parser specific features
"""
@classmethod
def setUpClass(cls):
from b3.parsers.q3a.abstractParser import AbstractParser
from b3.fake import FakeConsole
AbstractParser.__bases__ = (FakeConsole,)
# Now parser inheritance hierarchy is :
# EtParser -> AbstractParser -> FakeConsole -> Parser
logging.getLogger('output').setLevel(logging.ERROR)
def setUp(self):
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString("""<configuration>
<settings name="server">
<set name="game_log"/>
</settings>
</configuration>""")
self.console = EtParser(self.parser_conf)
self.console.write = Mock()
self.console.PunkBuster = None # no Punkbuster support in that game
def tearDown(self):
if hasattr(self, "parser"):
del self.parser.clients
self.parser.working = False
示例14: ChatloggerTestCase
class ChatloggerTestCase(unittest.TestCase):
def setUp(self):
testcase_lock.acquire()
self.addCleanup(cleanUp)
flush_console_streams()
# create a FakeConsole parser
self.parser_conf = XmlConfigParser()
self.parser_conf.loadFromString(r"""<configuration/>""")
with logging_disabled():
from b3.fake import FakeConsole
self.console = FakeConsole(self.parser_conf)
with logging_disabled():
self.adminPlugin = AdminPlugin(self.console, '@b3/conf/plugin_admin.ini')
self.adminPlugin.onStartup()
# make sure the admin plugin obtained by other plugins is our admin plugin
when(self.console).getPlugin('admin').thenReturn(self.adminPlugin)
self.console.screen = Mock()
self.console.time = time.time
self.console.upTime = Mock(return_value=3)
def tearDown(self):
try:
self.console.storage.shutdown()
except:
pass
示例15: test_nominal
def test_nominal(self):
conf = XmlConfigParser()
conf.setXml("""
<configuration plugin="teamspeakbf">
<settings name="teamspeakServer">
<set name="host">foo_host</set>
<set name="queryport">foo_queryport</set>
<set name="id">1</set>
<set name="login">foo_login</set>
<set name="password">foo_password</set>
</settings>
<settings name="teamspeakChannels">
<set name="B3">channel name</set>
<set name="team1">Team 1 name</set>
<set name="team2">Team 2 name</set>
<set name="DefaultTarget">team</set>
</settings>
</configuration>
""")
p = TeamspeakbfPlugin(fakeConsole, conf)
p.readConfig()
self.assertEqual('channel name', p.TS3ChannelB3)
self.assertEqual('Team 1 name', p.TS3ChannelTeam1)
self.assertEqual('Team 2 name', p.TS3ChannelTeam2)
self.assertEqual('team', p.autoswitchDefaultTarget)