def test_regression_bh_539(self): tracadmin = AdminCommandManager(self.env) self.assertTrue(self.env[self.component_class] is None, "Expected component disabled") self.assertFalse( any( isinstance(c, self.component_class) for c in tracadmin.providers), "Component erroneously listed in admin cmd providers") self.assertEqual([], tracadmin.get_command_help(args=['fail'])) # Enable component in both global and product context cmd_args = ['config', 'set', 'components', __name__ + '.*', 'enabled'] AdminCommandManager(self.global_env).execute_command(*cmd_args) tracadmin.execute_command(*cmd_args) self.assertTrue(self.env[self.component_class] is not None, "Expected component enabled") self.assertTrue( any( isinstance(c, self.component_class) for c in tracadmin.providers), "Component not listed in admin cmd providers") self.assertEqual(1, len(tracadmin.get_command_help(args=['fail'])))
def expand_macro(self, formatter, name, content): if content: arg = content.strip().split() doc = getattr(TracAdmin, "_help_" + arg[0], None) if doc is None: cmd_mgr = AdminCommandManager(self.env) doc = cmd_mgr.get_command_help(arg) if not doc: raise TracError('Unknown trac-admin command "%s"' % content) else: doc = TracAdmin.all_docs(self.env) buf = StringIO.StringIO() TracAdmin.print_doc(doc, buf, long=True) return html.PRE(buf.getvalue().decode('utf-8'), class_='wiki')
def expand_macro(self, formatter, name, content): if content: arg = content.strip().split() doc = getattr(TracAdmin, "_help_" + arg[0], None) if doc is None: cmd_mgr = AdminCommandManager(self.env) doc = cmd_mgr.get_command_help(arg) if not doc: raise TracError(_('Unknown trac-admin command "%(command)s"', command=content)) else: doc = TracAdmin.all_docs(self.env) buf = StringIO.StringIO() TracAdmin.print_doc(doc, buf, long=True) return html.PRE(buf.getvalue().decode('utf-8'), class_='wiki')
def expand_macro(self, formatter, name, content, args=None): if content: arg = content.strip().split() doc = getattr(TracAdmin, "_help_" + arg[0], None) if doc is None: cmd_mgr = AdminCommandManager(self.env) doc = cmd_mgr.get_command_help(arg) if not doc: raise MacroError(_('Unknown trac-admin command ' '"%(command)s"', command=content)) else: doc = TracAdmin.all_docs(self.env) buf = io.StringIO() TracAdmin.print_doc(doc, buf, long=True) return html.pre(buf.getvalue(), class_='wiki')
def test_regression_bh_539_concurrent(self): try: # It is necessary to load another environment object to work around # ProductEnvironment class' parametric singleton constraint old_env = self.env # In-memory DB has to be shared self.global_env.__class__.global_databasemanager = \ self.env.global_databasemanager new_global_env = self._setup_test_env(create_folder=True, path=self.global_env.path) self.env = old_env self._setup_test_log(new_global_env) # FIXME: EnvironmentStub config is not bound to a real file # ... so let's reuse one config for both envs to simulate that they # are in sync, a condition verified in another test case new_global_env.config = self.global_env.config new_env = ProductEnvironment(new_global_env, self.default_product) self.assertTrue(new_global_env is not self.global_env) self.assertTrue(new_env is not self.env) self.assertEqual(self.env.path, new_env.path) self.assertEqual(self.env.config._lock_path, new_env.config._lock_path) tracadmin = AdminCommandManager(self.env) new_tracadmin = AdminCommandManager(new_env) # Assertions for self.env self.assertTrue(self.env[self.component_class] is None, "Expected component disabled") self.assertFalse( any( isinstance(c, self.component_class) for c in tracadmin.providers), "Component erroneously listed in admin cmd " "providers") self.assertEqual([], tracadmin.get_command_help(args=['fail'])) # Repeat assertions for new_env self.assertTrue(new_env[self.component_class] is None, "Expected component disabled") self.assertFalse( any( isinstance(c, self.component_class) for c in new_tracadmin.providers), "Component erroneously listed in admin cmd " "providers") self.assertEqual([], new_tracadmin.get_command_help(args=['fail'])) # Enable component in both self.global_env and self.env contexts cmd_args = [ 'config', 'set', 'components', __name__ + '.*', 'enabled' ] AdminCommandManager(self.global_env).execute_command(*cmd_args) tracadmin.execute_command(*cmd_args) # Assert that changes are auto-magically reflected in new_env self.assertTrue(new_env[self.component_class] is not None, "Expected component enabled") self.assertTrue( any( isinstance(c, self.component_class) for c in new_tracadmin.providers), "Component not listed in admin cmd providers") self.assertEqual( 1, len(new_tracadmin.get_command_help(args=['fail']))) finally: self.global_env.__class__.global_databasemanager = None new_global_env = new_env = None