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) # 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._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 setUp(self): with logging_disabled(): # 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 = Iourt42Parser(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.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) # prepare a few players from b3.fake import FakeClient self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0) self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0) self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0) self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0) self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0) self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
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) # 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) self.console.screen = Mock() self.console.time = time.time self.console.upTime = Mock(return_value=3)
def setUp(self): # create a Iourt42 parser self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString( """<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""" ) self.console = Iourt42Parser(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._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) # prepare a few players self.joe = FakeClient(self.console, name="Joe", guid="Joe_guid", groupBits=1, team=TEAM_UNKNOWN) self.simon = FakeClient(self.console, name="Simon", guid="Simon_guid", groupBits=0, team=TEAM_UNKNOWN) self.reg = FakeClient(self.console, name="Reg", guid="Reg_guid", groupBits=4, team=TEAM_UNKNOWN) self.moderator = FakeClient(self.console, name="Moderator", guid="Moderator_guid", groupBits=8, team=TEAM_UNKNOWN) self.admin = FakeClient(self.console, name="Level-40-Admin", guid="Admin_guid", groupBits=16, team=TEAM_UNKNOWN) self.superadmin = FakeClient(self.console, name="Superadmin", guid="Superadmin_guid", groupBits=128, team=TEAM_UNKNOWN) logging.getLogger('output').setLevel(logging.DEBUG)
def _check_plugin_version(p_data: PluginData) -> None: if ( p_data.clazz.requiresVersion and B3version(p_data.clazz.requiresVersion) > B3version(b3_version) ): raise b3.config.MissingRequirement( f'plugin {p_data.name} requires B3 version ' f'{p_data.clazz.requiresVersion} (you have version {b3_version}) ' ': please update your B3 if you want to run this plugin' )
def _get_plugin_data(p_data): """ Return a list of PluginData of plugins needed by the current one :param p_data: A PluginData containing plugin information :return: list[PluginData] a list of PluginData of plugins needed by the current one """ # check for correct B3 version if p_data.clazz.requiresVersion and B3version( p_data.clazz.requiresVersion) > B3version( currentVersion): raise MissingRequirement( 'plugin %s requires B3 version %s (you have version %s) : please update your ' 'B3 if you want to run this plugin' % (p_data.name, p_data.clazz.requiresVersion, currentVersion)) # check if the current game support this plugin (this may actually exclude more than one plugin # in case a plugin is built on top of an incompatible one, due to plugin dependencies) if p_data.clazz.requiresParsers and self.console.gameName not in p_data.clazz.requiresParsers: raise MissingRequirement( 'plugin %s is not compatible with %s parser : supported games are : %s' % (p_data.name, self.console.gameName, ', '.join( p_data.clazz.requiresParsers))) # check if the plugin needs a particular storage protocol to work if p_data.clazz.requiresStorage and self.console.storage.protocol not in p_data.clazz.requiresStorage: raise MissingRequirement( 'plugin %s is not compatible with the storage protocol being used (%s) : ' 'supported protocols are : %s' % (p_data.name, self.console.storage.protocol, ', '.join( p_data.clazz.requiresStorage))) if p_data.clazz.requiresPlugins: collection = [] for r in p_data.requiresPlugins: if r not in self.console._plugins and r not in plugin_required: try: # missing requirement, try to load it self.warning( 'plugin %s has unmet dependency : %s : trying to load plugin %s...' % (p_data.name, r, r)) collection += _get_plugin_data( PluginData(name=r)) self.debug( 'plugin %s dependency satisfied: %s' % r) except Exception, err: raise MissingRequirement( 'missing required plugin: %s' % r, err) return collection
def update_innosetup_scripts(innosetup_scripts, current_b3_version): """\ for all scripts of innosetup_scripts, update the version to current_b3_version if necessary """ def extract_full_version_from_innosetup_script(str_content): """Return the full version string found in given string as expected in a InnoSetup script""" version_number = version_suffix = '' m_number = re_iss_b3_version_number.search(str_content) if m_number: version_number = m_number.group('number') m_suffix = re_iss_b3_version_suffix.search(str_content) if m_suffix: version_suffix = m_suffix.group('suffix') return version_number + version_suffix current_b3_version_number = current_b3_version.version current_b3_version_suffix = current_b3_version.prerelease for file_name in innosetup_scripts: data = '' with open(os.path.join(script_dir, file_name), 'r') as f: data = f.read() script_version = B3version( extract_full_version_from_innosetup_script(data)) if script_version != current_b3_version: data = re_iss_b3_version_number.sub( "\g<part1>%s\g<part2>" % '.'.join(map(str, current_b3_version_number)), data) data = re_iss_b3_version_suffix.sub( "\g<part1>%s\g<part2>" % ''.join(map(str, current_b3_version_suffix)), data) with open(os.path.join(script_dir, file_name), 'w') as f: f.write(data)
def test_exception(self): for version in ("1", "0", "24", '1.x', '1.5.2.1', '1.4alpha', '1.5.4beta', '1.6d'): try: B3version(version) self.fail("should have raised a ValueError for version '%s'" % version) except ValueError: pass
def test_exception(self): for version in ('1.x', '1.6d'): try: B3version(version) self.fail("should have raised a ValueError for version '%s'" % version) except ValueError: pass
def setUp(self): # less logging self.logger = logging.getLogger('output') self.logger.setLevel(logging.ERROR) self.logger.propagate = False from b3.fake import FakeConsole, FakeClient # create a Fake parser self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString( """<configuration><settings name="server"><set name="game_log"></set></settings></configuration>""" ) self.console = FakeConsole(self.parser_conf) self.console.startup() # load the admin plugin # 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.onLoadConfig() 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) # load our plugin self.conf = CfgConfigParser() self.p = ServermonitorPlugin(self.console, self.conf) self.superadmin = FakeClient(self.console, name="Superadmin", guid="Superadmin_guid", groupBits=128) self.logger.propagate = True
def setUp(self): # create a BF4 parser self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString("""<configuration />""") with logging_disabled(): self.console = Bf4Parser(self.parser_conf) # alter a few settings to speed up the tests self.console.sayqueue_get_timeout = 0 self.console._settings['message_delay'] = 0 with logging_disabled(): 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 def getPlugin(name): if name == 'admin': return self.adminPlugin else: return self.console.getPlugin(name) self.console.getPlugin = getPlugin self.console.patch_b3_admin_plugin() # prepare a few players with logging_disabled(): from b3.fake import FakeClient self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0) self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0) self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0) self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0) self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0) self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
def console(): with logging_disabled(): from b3.fake import FakeConsole fake_console = FakeConsole('@b3/conf/b3.distribution.xml') # 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(): admin_plugin = AdminPlugin(fake_console, admin_plugin_conf_file) admin_plugin._commands = { } # work around known bug in the Admin plugin which makes the _command property shared between all instances admin_plugin.onStartup() # make sure the admin plugin obtained by other plugins is our admin plugin when(fake_console).getPlugin('admin').thenReturn(admin_plugin) return fake_console
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 get_innosetup_script_version(innosetup_scripts): """\ For all given file names, extract the B3version found in the file content. Returns result as a dict where file names are the keys and B3version the values. """ innosetup_scripts_versions = dict() for file_name in innosetup_scripts: with open(os.path.join(script_dir, file_name), 'r') as f: version_number = version_suffix = '' map = mmap.mmap(f.fileno(), length=0, access=mmap.ACCESS_READ) m_number = re_iss_b3_version_number.search(map) if m_number: version_number = m_number.group('number') m_suffix = re_iss_b3_version_suffix.search(map) if m_suffix: version_suffix = m_suffix.group('suffix') map.close() innosetup_scripts_versions[file_name] = B3version(version_number + version_suffix) return innosetup_scripts_versions
def test_less(self): self.assertLess(B3version('1.0'), B3version('1.0.1')) self.assertLess(B3version('1.0'), B3version('1.1')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1dev6')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1a')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1a5')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1b')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1b5')) self.assertLess(B3version('2.5.1dev'), B3version('2.5.2')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.2')) self.assertLess(B3version('2.5.1a'), B3version('2.5.2')) self.assertLess(B3version('2.5.1a2'), B3version('2.5.2')) self.assertLess(B3version('2.5.1b'), B3version('2.5.2')) self.assertLess(B3version('2.5.1b4'), B3version('2.5.2')) self.assertLess(B3version("1.9.0dev7.daily5-20120904"), B3version("1.9dev7.daily19-20121001"))
def test_greater(self): self.assertGreater(B3version('1.0'), B3version('1.0dev')) self.assertGreater(B3version('1.0'), B3version('1.0dev1')) self.assertGreater(B3version('1.0'), B3version('1.0.0dev')) self.assertGreater(B3version('1.0'), B3version('1.0.0dev2')) self.assertGreater(B3version('1.0'), B3version('1.0a')) self.assertGreater(B3version('1.0'), B3version('1.0a5')) self.assertGreater(B3version('1.0'), B3version('1.0b')) self.assertGreater(B3version('1.0'), B3version('1.0b5')) self.assertGreater(B3version('1.0'), B3version('0.5')) self.assertGreater(B3version('1.0'), B3version('0.5dev')) self.assertGreater(B3version('1.0'), B3version('0.5a')) self.assertGreater(B3version('1.0'), B3version('0.5b')) self.assertGreater(B3version("1.9.0dev7.daily21-20121004"), B3version("1.9dev7.daily19-20121001"))
def test_equals(self): self.assertEqual(B3version("1.1.0"), B3version('1.1')) self.assertEqual(B3version("1.1dev"), B3version('1.1dev0')) self.assertEqual(B3version("1.1.0dev"), B3version('1.1.0dev0')) self.assertEqual(B3version("1.1.0dev"), B3version('1.1dev0')) self.assertEqual(B3version("1.1a"), B3version('1.1a0')) self.assertEqual(B3version("1.1.0a"), B3version('1.1.0a0')) self.assertEqual(B3version("1.1b"), B3version('1.1b')) self.assertEqual(B3version("1.1.0b"), B3version('1.1.0b0')) self.assertEqual(B3version("1.1.0b"), B3version('1.1b0')) self.assertEqual(B3version("1.9.0dev7.daily21-20121004"), B3version("1.9dev7.daily21"))
def test_less(self): self.assertLess(B3version('1.0'), B3version('1.0.1')) self.assertLess(B3version('1.0'), B3version('1.1'))
def test_no_exception(self): B3version("1.4") B3version("1.4.2") B3version("0.7dev") B3version("0.7dev0") B3version("0.7dev4") B3version("1.8a") B3version("1.8a0") B3version("1.8a1") B3version("1.8a45") B3version("1.8b") B3version("1.8b0") B3version("1.8b78") B3version("0.7.2dev") B3version("0.7.2dev0") B3version("0.7.2dev4") B3version("1.8.2a") B3version("1.8.2a0") B3version("1.8.2a1") B3version("1.8.2a45") B3version("1.8.2b") B3version("1.8.2b0") B3version("1.8.2b78") B3version("1.9.0dev7.daily21-20121004")
def test_no_exception(self): B3version("1.4") B3version("1.4.2") B3version("0.7dev") B3version("0.7dev0") B3version("0.7dev4") B3version("1.8a") B3version("1.8a0") B3version("1.8a1") B3version("1.8a45") B3version("1.8b") B3version("1.8b0") B3version("1.8b78") B3version("0.7.2dev") B3version("0.7.2dev0") B3version("0.7.2dev4") B3version("1.8.2a") B3version("1.8.2a0") B3version("1.8.2a1") B3version("1.8.2a45") B3version("1.8.2b") B3version("1.8.2b0") B3version("1.8.2b78")
CONFIG_FILE = 'build.yaml' script_dir = os.path.abspath(os.path.dirname(__file__)) try: # make sure to import the b3 module from the parent directory # (in case an other b3 module was installed system wide with an egg) sys.path.insert(0, os.path.abspath(os.path.join(script_dir, '..'))) from b3 import __version__ as b3_version from b3.update import B3version except ImportError: print "Could not import b3" raise current_b3_version = B3version(b3_version) egg_pkginfo_file = os.path.abspath( os.path.join(script_dir, '../b3.egg-info/PKG-INFO')) config = None re_iss_b3_version_number = re.compile( '^(?P<part1>#define B3_VERSION_NUMBER ")(?P<number>(\d+(\.\d+)+)?)(?P<part2>"\s*)$', re.MULTILINE) re_iss_b3_version_suffix = re.compile( '^(?P<part1>#define B3_VERSION_SUFFIX ")(?P<suffix>((a|b|dev)\d+)?)(?P<part2>"\s*)$', re.MULTILINE) def load_config(): global config
def setUp(self): if B3version(b3_version) >= B3version("1.10dev"): from b3.config import MainConfig self.parser_conf = MainConfig(CfgConfigParser(allow_no_value=True)) self.parser_conf.loadFromString(dedent(r"""""")) admin_plugin_conf_file = '@b3/conf/plugin_admin.ini' else: self.parser_conf = XmlConfigParser() self.parser_conf.loadFromString( dedent(r"""<configuration></configuration>""")) admin_plugin_conf_file = '@b3/conf/plugin_admin.xml' self.console = FakeConsole(self.parser_conf) self.console.gameName = 'f00' self.console.startup() with logging_disabled(): self.adminPlugin = AdminPlugin(self.console, admin_plugin_conf_file) self.adminPlugin.onLoadConfig() self.adminPlugin.onStartup() self.evt_queue = [] # make sure the admin plugin obtained by other plugins is our admin plugin when(self.console).getPlugin('admin').thenReturn(self.adminPlugin) with logging_disabled(): from b3.fake import FakeClient # prepare a few players self.mike = FakeClient(self.console, name="Mike", exactName="Mike", guid="MIKEGUID", groupBits=16, ip='1.1.1.1') self.paul = FakeClient(self.console, name="Paul", exactName="Paul", guid="PAULGUID", groupBits=1, ip='2.2.2.2') self.john = FakeClient(self.console, name="John", exactName="John", guid="JOHNGUID", groupBits=0, ip='3.3.3.3') self.mary = FakeClient(self.console, name="Mary", exactName="Mary", guid="MARYGUID", groupBits=0, ip='4.4.4.4') self.conf = CfgConfigParser() self.p = IpbanPlugin(self.console, self.conf) # return some mock data when(self.p).getBanIps().thenReturn(['2.2.2.2', '6.6.6.6', '7.7.7.7']) when(self.p).getTempBanIps().thenReturn( ['3.3.3.3', '8.8.8.8', '9.9.9.9'])
def __init__(self): self.nested = logging_disabled.DISABLED def __enter__(self): if not self.nested: logging.getLogger('output').propagate = False logging_disabled.DISABLED = True def __exit__(self, exc_type, exc_val, exc_tb): if not self.nested: logging.getLogger('output').propagate = True logging_disabled.DISABLED = False @unittest.skipIf(B3version(bf4_version) < B3version(MIN_BF4_PARSER_VERSION), "plugin requires B3 BF4 parser v%s or above (current is %s)" % (MIN_BF4_PARSER_VERSION, bf4_version)) class Bf4TestCase(unittest.TestCase): """ Test case that is suitable for testing BF4 parser specific features """ @classmethod def setUpClass(cls): # less logging logging.getLogger('output').setLevel(logging.WARNING) with logging_disabled(): from b3.parsers.frostbite2.abstractParser import AbstractParser from b3.fake import FakeConsole AbstractParser.__bases__ = (FakeConsole,)
def test_less(self): self.assertLess(B3version('1.0'), B3version('1.0.1')) self.assertLess(B3version('1.0'), B3version('1.1')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1dev6')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1a')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1a5')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1b')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.1b5')) self.assertLess(B3version('2.5.1dev'), B3version('2.5.2')) self.assertLess(B3version('2.5.1dev5'), B3version('2.5.2')) self.assertLess(B3version('2.5.1a'), B3version('2.5.2')) self.assertLess(B3version('2.5.1a2'), B3version('2.5.2')) self.assertLess(B3version('2.5.1b'), B3version('2.5.2')) self.assertLess(B3version('2.5.1b4'), B3version('2.5.2'))
def setUp(self): with logging_disabled(): # 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.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) # when starting the PoweradminurtPlugin expects the game server to provide a few cvar values when(self.console).getCvar('timelimit').thenReturn( Cvar('timelimit', value=20)) when(self.console).getCvar('g_maxGameClients').thenReturn( Cvar('g_maxGameClients', value=16)) when(self.console).getCvar('sv_maxclients').thenReturn( Cvar('sv_maxclients', value=16)) when(self.console).getCvar('sv_privateClients').thenReturn( Cvar('sv_privateClients', value=0)) when(self.console).getCvar('g_allowvote').thenReturn( Cvar('g_allowvote', value=0)) # prepare a few players self.joe = FakeClient(self.console, name="Joe", exactName="Joe", guid="zaerezarezar", groupBits=1, team=TEAM_UNKNOWN, teamId=0, squad=0) self.simon = FakeClient(self.console, name="Simon", exactName="Simon", guid="qsdfdsqfdsqf", groupBits=0, team=TEAM_UNKNOWN, teamId=0, squad=0) self.reg = FakeClient(self.console, name="Reg", exactName="Reg", guid="qsdfdsqfdsqf33", groupBits=4, team=TEAM_UNKNOWN, teamId=0, squad=0) self.moderator = FakeClient(self.console, name="Moderator", exactName="Moderator", guid="sdf455ezr", groupBits=8, team=TEAM_UNKNOWN, teamId=0, squad=0) self.admin = FakeClient(self.console, name="Level-40-Admin", exactName="Level-40-Admin", guid="875sasda", groupBits=16, team=TEAM_UNKNOWN, teamId=0, squad=0) self.superadmin = FakeClient(self.console, name="God", exactName="God", guid="f4qfer654r", groupBits=128, team=TEAM_UNKNOWN, teamId=0, squad=0)
def test_equals(self): self.assertEqual(B3version("1.1.0"), B3version('1.1')) self.assertEqual(B3version("1.1dev"), B3version('1.1dev0')) self.assertEqual(B3version("1.1.0dev"), B3version('1.1.0dev0')) self.assertEqual(B3version("1.1.0dev"), B3version('1.1dev0')) self.assertEqual(B3version("1.1a"), B3version('1.1a0')) self.assertEqual(B3version("1.1.0a"), B3version('1.1.0a0')) self.assertEqual(B3version("1.1b"), B3version('1.1b')) self.assertEqual(B3version("1.1.0b"), B3version('1.1.0b0')) self.assertEqual(B3version("1.1.0b"), B3version('1.1b0'))
def _get_plugin_data(p_data): """ Return a list of PluginData of plugins needed by the current one :param p_data: A PluginData containing plugin information :return: list[PluginData] a list of PluginData of plugins needed by the current one """ # check for correct B3 version if p_data.clazz.requiresVersion and B3version( p_data.clazz.requiresVersion) > B3version( currentVersion): raise MissingRequirement( 'plugin %s requires B3 version %s (you have version %s) : please update your ' 'B3 if you want to run this plugin' % (p_data.name, p_data.clazz.requiresVersion, currentVersion)) # check if the current game support this plugin (this may actually exclude more than one plugin # in case a plugin is built on top of an incompatible one, due to plugin dependencies) if p_data.clazz.requiresParsers and self.console.gameName not in p_data.clazz.requiresParsers: raise MissingRequirement( 'plugin %s is not compatible with %s parser : supported games are : %s' % (p_data.name, self.console.gameName, ', '.join( p_data.clazz.requiresParsers))) # check if the plugin needs a particular storage protocol to work if p_data.clazz.requiresStorage and self.console.storage.protocol not in p_data.clazz.requiresStorage: raise MissingRequirement( 'plugin %s is not compatible with the storage protocol being used (%s) : ' 'supported protocols are : %s' % (p_data.name, self.console.storage.protocol, ', '.join( p_data.clazz.requiresStorage))) if p_data.clazz.requiresPlugins: collection = [] for r in p_data.requiresPlugins: if r not in self.console._plugins and r not in plugin_required: try: # missing requirement, try to load it self.warning( 'plugin %s has unmet dependency : %s : trying to load plugin %s...' % (p_data.name, r, r)) collection += _get_plugin_data( PluginData(name=r)) self.debug( 'plugin %s dependency satisfied: %s' % r) except Exception as err: raise MissingRequirement( 'missing required plugin: %s' % r, err) return collection # plugin has not been loaded manually nor a previous automatic load attempt has been done if p_data.name not in self.console._plugins and p_data.name not in plugin_required: # we are at the bottom step where we load a new requirement by importing the # plugin module, class and configuration file. If the following generate an exception, recursion # will catch it here above and raise it back so we can exclude the first plugin in the list from load self.debug( 'looking for plugin %s module and configuration file...' % p_data.name) p_data.module = self.console.pluginImport(p_data.name) p_data.clazz = getattr(p_data.module, '%sPlugin' % p_data.name.title()) p_data.conf = _get_plugin_config(p_data.name, p_data.clazz) plugin_required.append(p_data.name) # load just once return [p_data]
def test_no_exception(self): B3version("1.4") B3version("1.4.2")
def test_greater(self): self.assertGreater(B3version('1.0'), B3version('1.0dev')) self.assertGreater(B3version('1.0'), B3version('1.0dev1')) self.assertGreater(B3version('1.0'), B3version('1.0.0dev')) self.assertGreater(B3version('1.0'), B3version('1.0.0dev2')) self.assertGreater(B3version('1.0'), B3version('1.0a')) self.assertGreater(B3version('1.0'), B3version('1.0a5')) self.assertGreater(B3version('1.0'), B3version('1.0b')) self.assertGreater(B3version('1.0'), B3version('1.0b5')) self.assertGreater(B3version('1.0'), B3version('0.5')) self.assertGreater(B3version('1.0'), B3version('0.5dev')) self.assertGreater(B3version('1.0'), B3version('0.5a')) self.assertGreater(B3version('1.0'), B3version('0.5b'))
# along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import logging import unittest2 from textwrap import dedent from mockito import when from b3.cvar import Cvar from b3.config import XmlConfigParser from b3.plugins.admin import AdminPlugin from b3 import __version__ as b3_version from b3.parsers.iourt42 import Iourt42Parser from b3.update import B3version if B3version(b3_version) >= B3version("1.10dev"): HAS_CALLVOTE_EVENT = True else: HAS_CALLVOTE_EVENT = False class logging_disabled(object): """ Context manager that temporarily disable logging. USAGE: with logging_disabled(): # do stuff """ DISABLED = False