本文整理汇总了Python中b3.config.XmlConfigParser.loadFromString方法的典型用法代码示例。如果您正苦于以下问题:Python XmlConfigParser.loadFromString方法的具体用法?Python XmlConfigParser.loadFromString怎么用?Python XmlConfigParser.loadFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类b3.config.XmlConfigParser
的用法示例。
在下文中一共展示了XmlConfigParser.loadFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PluginTestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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: test_others
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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)
示例4: Test_Client_player_type
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
class Test_Client_player_type(BFHTestCase):
def setUp(self):
BFHTestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration>
</configuration>
""")
self.parser = BfhParser(self.conf)
self.foobar = self.parser.clients.newClient(cid='Foobar', name='Foobar', guid="FoobarGuid")
def test_player_type_player(self):
# GIVEN
when(self.parser).write(('admin.listPlayers', 'player', 'Foobar')).thenReturn(
['10', 'name', 'guid', 'teamId', 'squadId', 'kills', 'deaths', 'score', 'rank', 'ping', 'type', '1',
'Foobar', 'xxxxy', '1', '0', '0', '0', '0', '71', '65535', '0'])
# THEN
self.assertEqual(BFH_PLAYER, self.foobar.player_type)
def test_player_type_spectator(self):
# GIVEN
when(self.parser).write(('admin.listPlayers', 'player', 'Foobar')).thenReturn(
['10', 'name', 'guid', 'teamId', 'squadId', 'kills', 'deaths', 'score', 'rank', 'ping', 'type', '1',
'Foobar', 'xxxxy', '0', '0', '0', '0', '0', '71', '65535', '1'])
# THEN
self.assertEqual(BFH_SPECTATOR, self.foobar.player_type)
示例5: B3TestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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()
示例6: ChatloggerTestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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
示例7: CalladminTestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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()
示例8: Test_patch_b3_Client_isAlive
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
class Test_patch_b3_Client_isAlive(BF3TestCase):
def setUp(self):
BF3TestCase.setUp(self)
self.conf = XmlConfigParser()
self.conf.loadFromString("""
<configuration>
</configuration>
""")
self.parser = Bf3Parser(self.conf)
self.foobar = self.parser.clients.newClient(cid='Foobar', name='Foobar', guid="FoobarGuid")
def test_unknown(self):
# GIVEN
when(self.parser).write(('player.isAlive', 'Foobar')).thenReturn()
# THEN
self.assertEqual(b3.STATE_UNKNOWN, self.foobar.state)
def test_alive(self):
# GIVEN
when(self.parser).write(('player.isAlive', 'Foobar')).thenReturn(['true'])
# THEN
self.assertEqual(b3.STATE_ALIVE, self.foobar.state)
def test_dead(self):
# GIVEN
when(self.parser).write(('player.isAlive', 'Foobar')).thenReturn(['false'])
# THEN
self.assertEqual(b3.STATE_DEAD, self.foobar.state)
def test_exception_InvalidPlayerName(self):
when(self.parser).write(('player.isAlive', 'Foobar')).thenRaise(CommandFailedError(['InvalidPlayerName']))
self.assertEqual(b3.STATE_UNKNOWN, self.foobar.state)
示例9: Test_bf3_events
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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)
示例10: CustomcommandsTestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
class CustomcommandsTestCase(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 = {} # work around known bug in the Admin plugin which makes the _command property shared between all instances
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)
self.console.cron.stop()
def tearDown(self):
self.sleep_patcher.stop()
示例11: AdminTestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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
示例12: Test_getPlayerPings
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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)
示例13: Iourt41TestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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
示例14: Test_cmd_yell
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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'))
示例15: EtTestCase
# 需要导入模块: from b3.config import XmlConfigParser [as 别名]
# 或者: from b3.config.XmlConfigParser import loadFromString [as 别名]
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