当前位置: 首页>>代码示例>>Python>>正文


Python Environment.shutdown方法代码示例

本文整理汇总了Python中trac.env.Environment.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python Environment.shutdown方法的具体用法?Python Environment.shutdown怎么用?Python Environment.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在trac.env.Environment的用法示例。


在下文中一共展示了Environment.shutdown方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = os.path.join(tempfile.gettempdir(), 'trac-tempenv')
        self.env = Environment(env_path, create=True)
        self.db = self.env.get_db_cnx()

    def tearDown(self):
        self.db.close()
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_get_version(self):
        """Testing env.get_version"""
        assert self.env.get_version() == db_default.db_version

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        cursor = self.db.cursor()
        cursor.executemany("INSERT INTO session VALUES (%s,%s,0)",
                           [('123', 0),('tom', 1), ('joe', 1), ('jane', 1)])
        cursor.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
                           [('123', 0, 'email', '[email protected]'),
                            ('tom', 1, 'name', 'Tom'),
                            ('tom', 1, 'email', '[email protected]'),
                            ('joe', 1, 'email', '[email protected]'),
                            ('jane', 1, 'name', 'Jane')])
        users = {}
        for username,name,email in self.env.get_known_users(self.db):
            users[username] = (name, email)

        assert not users.has_key('anonymous')
        self.assertEqual(('Tom', '[email protected]'), users['tom'])
        self.assertEqual((None, '[email protected]'), users['joe'])
        self.assertEqual(('Jane', None), users['jane'])
开发者ID:gdgkyoto,项目名称:kyoto-gtug,代码行数:37,代码来源:env.py

示例2: TicketTemplateTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class TicketTemplateTestCase(unittest.TestCase):

    def setUp(self):
#        self.env = EnvironmentStub()

        env_path = os.path.join(tempfile.gettempdir(), 'trac-tempenv')
        self.env = Environment(env_path, create=True)
        self.db = self.env.db_transaction
        self.db.__enter__()

        self.compmgr = ComponentManager()

        # init TicketTemplateModule
        self.tt = ttadmin.TicketTemplateModule(self.compmgr)
        setattr(self.tt, "env", self.env)

    def tearDown(self):
        self.db.__exit__(None, None, None)
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_get_active_navigation_item(self):
        req = Mock(path_info='/tickettemplate')
        self.assertEqual('tickettemplate', self.tt.get_active_navigation_item(req))

        req = Mock(path_info='/something')
        self.assertNotEqual('tickettemplate', self.tt.match_request(req))

    def test_get_navigation_items(self):
        req = Mock(href=Mock(tickettemplate=lambda:"/trac-tempenv/tickettemplate"))
        a, b, c= self.tt.get_navigation_items(req).next()
        self.assertEqual('mainnav', a)
        self.assertEqual('tickettemplate', b)

    def test_match_request(self):
        req = Mock(path_info='/tickettemplate')
        self.assertEqual(True, self.tt.match_request(req))

        req = Mock(path_info='/something')
        self.assertEqual(False, self.tt.match_request(req))

    def test_getTicketTypeNames(self):
        options = self.tt._getTicketTypeNames()
        self.assertEqual(["default", "defect", "enhancement", "task"], options)

    def test_loadSaveTemplateText(self):
        for tt_name, tt_text in [("default", "default text"),
                                ("defect", "defect text"),
                                ("enhancement", "enhancement text"),
                                ("task", "task text"),
                                ]:
            self.tt._saveTemplateText(tt_name, tt_text)
            self.assertEqual(tt_name + " text", self.tt._loadTemplateText(tt_name))
开发者ID:SpamExperts,项目名称:trac-tickettemplateplugin,代码行数:55,代码来源:test_tt.py

示例3: _create_env

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
 def _create_env(self, path, dburi):
     env = Environment(path, True,
                       [('trac', 'database', dburi),
                        ('trac', 'base_url', 'http://localhost/'),
                        ('project', 'name', u'Pŕójéćŧ Ńáḿé')])
     @env.with_transaction()
     def fn(db):
         cursor = db.cursor()
         cursor.execute("UPDATE system SET value='21' "
                        "WHERE name='initial_database_version'")
     pages_dir = resource_filename('trac.wiki', 'default-pages')
     WikiAdmin(env).load_pages(pages_dir)
     att = Attachment(env, 'wiki', 'WikiStart')
     att.insert('filename.txt', StringIO('test'), 4)
     env.shutdown()
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:17,代码来源:admin.py

示例4: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
        self.env = Environment(env_path, create=True)
        self.env.config.set('trac', 'base_url',
                            'http://trac.edgewall.org/some/path')
        self.env.config.save()

    def tearDown(self):
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_abs_href(self):
        self.assertEqual('http://trac.edgewall.org/some/path', self.env.abs_href())

    def test_href(self):
        self.assertEqual('/some/path', self.env.href())

    def test_get_version(self):
        """Testing env.get_version"""
        self.assertEqual(db_default.db_version, self.env.get_version())

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        with self.env.db_transaction as db:
            db.executemany("INSERT INTO session VALUES (%s,%s,0)",
                [('123', 0), ('tom', 1), ('joe', 1), ('jane', 1)])
            db.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
                [('123', 0, 'email', '[email protected]'),
                 ('tom', 1, 'name', 'Tom'),
                 ('tom', 1, 'email', '[email protected]'),
                 ('joe', 1, 'email', '[email protected]'),
                 ('jane', 1, 'name', 'Jane')])
        users = {}
        for username, name, email in self.env.get_known_users():
            users[username] = (name, email)

        self.assertTrue('anonymous' not in users)
        self.assertEqual(('Tom', '[email protected]'), users['tom'])
        self.assertEqual((None, '[email protected]'), users['joe'])
        self.assertEqual(('Jane', None), users['jane'])
开发者ID:dafrito,项目名称:trac-mirror,代码行数:44,代码来源:env.py

示例5: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class EnvironmentTestCase(unittest.TestCase):
    def setUp(self):
        env_path = os.path.join(tempfile.gettempdir(), "trac-tempenv")
        self.env = Environment(env_path, create=True)
        self.db = self.env.get_db_cnx()

    def tearDown(self):
        self.db.close()
        self.env.shutdown()  # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_get_version(self):
        """Testing env.get_version"""
        assert self.env.get_version() == db_default.db_version

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        cursor = self.db.cursor()
        cursor.executemany("INSERT INTO session VALUES (%s,%s,0)", [("123", 0), ("tom", 1), ("joe", 1), ("jane", 1)])
        cursor.executemany(
            "INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
            [
                ("123", 0, "email", "[email protected]"),
                ("tom", 1, "name", "Tom"),
                ("tom", 1, "email", "[email protected]"),
                ("joe", 1, "email", "[email protected]"),
                ("jane", 1, "name", "Jane"),
            ],
        )
        users = {}
        for username, name, email in self.env.get_known_users(self.db):
            users[username] = (name, email)

        assert not users.has_key("anonymous")
        self.assertEqual(("Tom", "[email protected]"), users["tom"])
        self.assertEqual((None, "[email protected]"), users["joe"])
        self.assertEqual(("Jane", None), users["jane"])
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:39,代码来源:env.py

示例6: MigrationTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class MigrationTestCase(unittest.TestCase):

    def setUp(self):
        self.stdout = sys.stdout
        self.stderr = sys.stderr
        sys.stdout = sys.stderr = DummyOut()
        self.path = tempfile.mkdtemp(prefix='trac-migrate-')
        self.src_path = os.path.join(self.path, 'src')
        self.dst_path = os.path.join(self.path, 'dst')
        self.src_env = None
        self.dst_env = None
        self._destroy_db()

    def tearDown(self):
        sys.stdout = self.stdout
        sys.stderr = self.stderr
        if self.src_env:
            self.src_env.shutdown()
        if self.dst_env:
            self.dst_env.shutdown()
        shutil.rmtree(self.path)

    def _create_env(self, path, dburi):
        env = Environment(path, True,
                          [('trac', 'database', dburi),
                           ('trac', 'base_url', 'http://localhost/'),
                           ('project', 'name', u'Pŕójéćŧ Ńáḿé')])
        @env.with_transaction()
        def fn(db):
            cursor = db.cursor()
            cursor.execute("UPDATE system SET value='21' "
                           "WHERE name='initial_database_version'")
        pages_dir = resource_filename('trac.wiki', 'default-pages')
        WikiAdmin(env).load_pages(pages_dir)
        att = Attachment(env, 'wiki', 'WikiStart')
        att.insert('filename.txt', StringIO('test'), 4)
        env.shutdown()

    if 'destroying' in inspect.getargspec(EnvironmentStub.__init__)[0]:
        def _destroy_db(self):
            EnvironmentStub(destroying=True).destroy_db()
    else:
        def _destroy_db(self):
            EnvironmentStub().destroy_db()

    def _get_all_records(self, env):
        def primary(row, columns):
            if len(columns) == 1:
                return row[columns[0]]
            else:
                return tuple(row[col] for col in columns)

        db = env.get_read_db()
        cursor = db.cursor()
        records = {}
        for table in db_default.schema:
            primary_cols = ','.join(db.quote(col) for col in table.key)
            query = "SELECT * FROM %s ORDER BY %s" % (db.quote(table.name),
                                                      primary_cols)
            cursor.execute(query)
            columns = get_column_names(cursor)
            rows = {}
            for row in cursor:
                row = dict(zip(columns, row))
                rows[primary(row, table.key)] = row
            records[table.name] = rows
        return records

    def _generate_module_name(self):
        return 'tracmigratetest_' + hex_entropy(16)

    def _build_egg_file(self):
        module_name = self._generate_module_name()
        plugin_src = os.path.join(self.path, 'plugin_src')
        os.mkdir(plugin_src)
        os.mkdir(os.path.join(plugin_src, module_name))
        create_file(os.path.join(plugin_src, 'setup.py'),
                    _setup_py % {'name': module_name})
        create_file(os.path.join(plugin_src, module_name, '__init__.py'),
                    _plugin_py)
        proc = Popen((sys.executable, 'setup.py', 'bdist_egg'), cwd=plugin_src,
                     stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=close_fds)
        stdout, stderr = proc.communicate(input='')
        for f in (proc.stdin, proc.stdout, proc.stderr):
            f.close()
        for filename in glob(os.path.join(plugin_src, 'dist', '*-*.egg')):
            return filename

    def _migrate(self, env, path, dburi):
        TracMigrationCommand(env)._do_migrate(path, dburi)

    def _migrate_inplace(self, env, dburi):
        self._migrate(env, '--in-place', dburi)

    def _compare_records(self, expected, actual):
        self.assertEqual(expected.keys(), actual.keys())
        for table in db_default.schema:
            name = table.name
            if name == 'report':
                self.assertEqual(expected[name].keys(), actual[name].keys())
#.........这里部分代码省略.........
开发者ID:jun66j5,项目名称:tracmigrateplugin,代码行数:103,代码来源:admin.py

示例7: _create_env

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
 def _create_env(self):
     env = Environment(self.env_path, create=True)
     env.shutdown()
开发者ID:exocad,项目名称:exotrac,代码行数:5,代码来源:sqlite_test.py

示例8: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
        self.env = Environment(env_path, create=True)
        self.env.config.set('trac', 'base_url',
                            'http://trac.edgewall.org/some/path')
        self.env.config.save()

    def tearDown(self):
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_db_exc(self):
        db_exc = self.env.db_exc
        self.assertTrue(hasattr(db_exc, 'IntegrityError'))
        self.assertIs(db_exc, self.env.db_exc)

    def test_abs_href(self):
        abs_href = self.env.abs_href
        self.assertEqual('http://trac.edgewall.org/some/path', abs_href())
        self.assertIs(abs_href, self.env.abs_href)

    def test_href(self):
        href = self.env.href
        self.assertEqual('/some/path', href())
        self.assertIs(href, self.env.href)

    def test_get_version(self):
        """Testing env.get_version"""
        self.assertEqual(db_default.db_version, self.env.get_version())
        self.assertEqual(db_default.db_version, self.env.database_version)
        self.assertEqual(db_default.db_version, self.env.database_initial_version)

    def test_get_known_users(self):
        """Testing env.get_known_users"""
        with self.env.db_transaction as db:
            db.executemany("INSERT INTO session VALUES (%s,%s,0)",
                [('123', 0), ('tom', 1), ('joe', 1), ('jane', 1)])
            db.executemany("INSERT INTO session_attribute VALUES (%s,%s,%s,%s)",
                [('123', 0, 'email', '[email protected]'),
                 ('tom', 1, 'name', 'Tom'),
                 ('tom', 1, 'email', '[email protected]'),
                 ('joe', 1, 'email', '[email protected]'),
                 ('jane', 1, 'name', 'Jane')])
        users = {}
        for username, name, email in self.env.get_known_users():
            users[username] = (name, email)

        self.assertTrue('anonymous' not in users)
        self.assertEqual(('Tom', '[email protected]'), users['tom'])
        self.assertEqual((None, '[email protected]'), users['joe'])
        self.assertEqual(('Jane', None), users['jane'])

    def test_is_component_enabled(self):
        self.assertEqual(True, Environment.required)
        self.assertEqual(True, self.env.is_component_enabled(Environment))
        self.assertEqual(False, EnvironmentStub.required)
        self.assertEqual(None, self.env.is_component_enabled(EnvironmentStub))

    def test_dumped_values_in_tracini(self):
        parser = RawConfigParser()
        filename = self.env.config.filename
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))

    def test_dumped_values_in_tracini_sample(self):
        parser = RawConfigParser()
        filename = self.env.config.filename + '.sample'
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))
        self.assertTrue(parser.has_option('logging', 'log_format'))
        self.assertEqual('', parser.get('logging', 'log_format'))
开发者ID:exocad,项目名称:exotrac,代码行数:79,代码来源:env.py

示例9: EnvironmentTestCase

# 需要导入模块: from trac.env import Environment [as 别名]
# 或者: from trac.env.Environment import shutdown [as 别名]
class EnvironmentTestCase(unittest.TestCase):

    def setUp(self):
        env_path = tempfile.mkdtemp(prefix='trac-tempenv-')
        self.env = Environment(env_path, create=True)
        self.env.config.set('trac', 'base_url',
                            'http://trac.edgewall.org/some/path')
        self.env.config.save()

    def tearDown(self):
        self.env.shutdown() # really closes the db connections
        shutil.rmtree(self.env.path)

    def test_db_exc(self):
        db_exc = self.env.db_exc
        self.assertTrue(hasattr(db_exc, 'IntegrityError'))
        self.assertIs(db_exc, self.env.db_exc)

    def test_abs_href(self):
        abs_href = self.env.abs_href
        self.assertEqual('http://trac.edgewall.org/some/path', abs_href())
        self.assertIs(abs_href, self.env.abs_href)

    def test_href(self):
        href = self.env.href
        self.assertEqual('/some/path', href())
        self.assertIs(href, self.env.href)

    def test_get_version(self):
        """Testing env.get_version"""
        self.assertEqual(db_default.db_version, self.env.get_version())
        self.assertEqual(db_default.db_version, self.env.database_version)
        self.assertEqual(db_default.db_version, self.env.database_initial_version)

    def test_is_component_enabled(self):
        self.assertEqual(True, Environment.required)
        self.assertEqual(True, self.env.is_component_enabled(Environment))
        self.assertEqual(False, EnvironmentStub.required)
        self.assertEqual(None, self.env.is_component_enabled(EnvironmentStub))

    def test_dumped_values_in_tracini(self):
        parser = RawConfigParser()
        filename = self.env.config.filename
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))

    def test_dumped_values_in_tracini_sample(self):
        parser = RawConfigParser()
        filename = self.env.config.filename + '.sample'
        self.assertEqual([filename], parser.read(filename))
        self.assertEqual('#cc0,#0c0,#0cc,#00c,#c0c,#c00',
                         parser.get('revisionlog', 'graph_colors'))
        self.assertEqual('disabled', parser.get('trac', 'secure_cookies'))
        self.assertTrue(parser.has_option('logging', 'log_format'))
        self.assertEqual('', parser.get('logging', 'log_format'))

    def test_needs_upgrade_legacy_participant(self):
        """For backward compatibility with plugin, environment_needs_upgrade
        with a `db` argument is deprecated but still allowed."""
        participants = self.env.setup_participants
        needs_upgrade = self.env.needs_upgrade()

        class LegacyParticipant(Component):
            implements(IEnvironmentSetupParticipant)
            def environment_created(self):
                pass
            def environment_needs_upgrade(self, db):
                return True
            def upgrade_environment(self, db):
                pass

        self.env.enable_component(LegacyParticipant)

        self.assertFalse(needs_upgrade)
        self.assertEqual(len(participants) + 1,
                         len(self.env.setup_participants))
        self.assertTrue(self.env.needs_upgrade())

    def test_upgrade_legacy_participant(self):
        """For backward compatibility with plugin, upgrade with a `db`
        argument is deprecated but still allowed."""
        participants = self.env.setup_participants

        class LegacyParticipant(Component):
            implements(IEnvironmentSetupParticipant)
            def environment_created(self):
                pass
            def environment_needs_upgrade(self, db):
                return True
            def upgrade_environment(self, db):
                pass

        self.env.enable_component(LegacyParticipant)

        self.assertEqual(len(participants) + 1,
                         len(self.env.setup_participants))
        self.assertTrue(self.env.needs_upgrade())
        self.assertTrue(self.env.upgrade())
#.........这里部分代码省略.........
开发者ID:pkdevbox,项目名称:trac,代码行数:103,代码来源:env.py


注:本文中的trac.env.Environment.shutdown方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。