Mercurial > bitten > bitten-test
changeset 322:0c60c69f10c3 0.5.x
Ported [333] and [334] to 0.5.x.
author | cmlenz |
---|---|
date | Wed, 04 Jan 2006 18:49:34 +0000 |
parents | 053abf910d01 |
children | c19689cf3534 |
files | bitten/tests/model.py bitten/tests/queue.py bitten/trac_ext/compat.py bitten/trac_ext/summarizers.py bitten/trac_ext/tests/charts.py bitten/trac_ext/tests/web_ui.py bitten/trac_ext/web_ui.py bitten/upgrades.py setup.py |
diffstat | 9 files changed, 76 insertions(+), 42 deletions(-) [+] |
line wrap: on
line diff
--- a/bitten/tests/model.py +++ b/bitten/tests/model.py @@ -12,16 +12,18 @@ from trac.test import EnvironmentStub from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, \ BuildLog, Report, schema +from bitten.trac_ext.compat import schema_to_sql class BuildConfigTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -153,10 +155,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in TargetPlatform._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -207,10 +210,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in Build._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -313,10 +317,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildStep._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -412,10 +417,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in BuildLog._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit() @@ -526,10 +532,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in Report._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit()
--- a/bitten/tests/queue.py +++ b/bitten/tests/queue.py @@ -16,6 +16,7 @@ from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, schema from bitten.queue import BuildQueue, collect_changes from bitten.util import archive +from bitten.trac_ext.compat import schema_to_sql class CollectChangesTestCase(unittest.TestCase): @@ -29,7 +30,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) self.config = BuildConfig(self.env, name='test', path='somepath') self.config.insert(db=db) @@ -125,7 +126,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) db.commit()
new file mode 100644 --- /dev/null +++ b/bitten/trac_ext/compat.py @@ -0,0 +1,20 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2006 Christopher Lenz <cmlenz@gmx.de> +# All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://bitten.cmlenz.net/wiki/License. + +"""Various methods for backwards compatibility with older Trac versions.""" + +def schema_to_sql(env, db, table): + try: + # Trac >= 0.10 + from trac.db import DatabaseManager + connector, _ = DatabaseManager(env)._get_connector() + return connector.to_sql(table) + except ImportError: + # Trac 0.9.x + return db.to_sql(table)
--- a/bitten/trac_ext/summarizers.py +++ b/bitten/trac_ext/summarizers.py @@ -61,7 +61,7 @@ hdf = HDFWrapper(loadpaths=Chrome(self.env).get_all_templates_dirs()) hdf['data'] = data hdf['totals'] = {'success': total_success, 'failure': total_failure, - 'error': total_error} + 'error': total_error} return hdf.render('bitten_summary_tests.cs')
--- a/bitten/trac_ext/tests/charts.py +++ b/bitten/trac_ext/tests/charts.py @@ -13,16 +13,18 @@ from trac.web.clearsilver import HDFWrapper from bitten.model import * from bitten.trac_ext.charts import * +from bitten.trac_ext.compat import schema_to_sql class TestResultsChartGeneratorTestCase(unittest.TestCase): def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) def test_supported_categories(self): @@ -98,10 +100,11 @@ def setUp(self): self.env = EnvironmentStub() + self.env.path = '' db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) def test_supported_categories(self):
--- a/bitten/trac_ext/tests/web_ui.py +++ b/bitten/trac_ext/tests/web_ui.py @@ -18,6 +18,7 @@ from trac.web.clearsilver import HDFWrapper from trac.web.main import Request, RequestDone from bitten.model import BuildConfig, TargetPlatform, Build, schema +from bitten.trac_ext.compat import schema_to_sql from bitten.trac_ext.main import BuildSystem from bitten.trac_ext.web_ui import BuildConfigController @@ -32,7 +33,7 @@ db = self.env.get_db_cnx() cursor = db.cursor() for table in schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(self.env, db, table): cursor.execute(stmt) # Set up permissions
--- a/bitten/trac_ext/web_ui.py +++ b/bitten/trac_ext/web_ui.py @@ -19,8 +19,8 @@ import pkg_resources from trac.core import * from trac.Timeline import ITimelineEventProvider -from trac.util import escape, pretty_timedelta, format_date, format_datetime, \ - shorten_line +from trac.util import escape, pretty_timedelta, format_datetime, shorten_line, \ + Markup from trac.web import IRequestHandler from trac.web.chrome import INavigationContributor, ITemplateProvider, \ add_link, add_stylesheet @@ -356,7 +356,7 @@ chgset = repos.get_changeset(rev) req.hdf[prefix + '.youngest_rev'] = { 'id': rev, 'href': self.env.href.changeset(rev), - 'author': escape(chgset.author) or 'anonymous', + 'author': chgset.author or 'anonymous', 'date': format_datetime(chgset.date), 'message': wiki_to_oneliner( shorten_line(chgset.message), self.env) @@ -366,11 +366,11 @@ prev_rev = rev if build: build_hdf = _build_to_hdf(self.env, req, build) - build_hdf['platform'] = escape(platform.name) + build_hdf['platform'] = platform.name req.hdf[prefix + '.builds.%d' % platform.id] = build_hdf else: req.hdf[prefix + '.builds.%d' % platform.id] = { - 'platform': escape(platform.name), 'status': 'pending' + 'platform': platform.name, 'status': 'pending' } req.hdf['page.mode'] = 'overview' @@ -381,7 +381,7 @@ config = BuildConfig.fetch(self.env, config_name, db=db) req.hdf['title'] = 'Build Configuration "%s"' \ - % escape(config.label or config.name) + % config.label or config.name add_link(req, 'up', self.env.href.build(), 'Build Status') description = config.description if description: @@ -417,7 +417,7 @@ ] charts_license = self.config.get('bitten', 'charts_license') if charts_license: - req.hdf['config.charts_license'] = escape(charts_license) + req.hdf['config.charts_license'] = charts_license page = max(1, int(req.args.get('page', 1))) more = False @@ -441,7 +441,7 @@ db=db): req.hdf['%s.%s.steps.%s' % (prefix, platform.id, step.name)] = { - 'description': escape(step.description), + 'description': step.description, 'duration': datetime.fromtimestamp(step.stopped) - \ datetime.fromtimestamp(step.started), 'failed': not step.successful, @@ -464,7 +464,7 @@ req.perm.assert_permission('BUILD_DELETE') config = BuildConfig.fetch(self.env, config_name) req.hdf['title'] = 'Delete Build Configuration "%s"' \ - % escape(config.label or config.name) + % config.label or config.name req.hdf['config'] = {'name': config.name} req.hdf['page.mode'] = 'delete_config' @@ -481,7 +481,7 @@ } req.hdf['title'] = 'Edit Build Configuration "%s"' \ - % escape(config.label or config.name) + % config.label or config.name for idx, platform in enumerate(TargetPlatform.select(self.env, config_name)): req.hdf['config.platforms.%d' % idx] = { @@ -497,8 +497,7 @@ def _render_platform_form(self, req, platform): req.perm.assert_permission('BUILD_MODIFY') if platform.exists: - req.hdf['title'] = 'Edit Target Platform "%s"' \ - % escape(platform.name) + req.hdf['title'] = 'Edit Target Platform "%s"' % platform.name else: req.hdf['title'] = 'Add Target Platform' req.hdf['platform'] = { @@ -621,12 +620,11 @@ for step in BuildStep.select(self.env, build=id, status=BuildStep.FAILURE, db=db): - errors += [(escape(step.name), escape(error)) for error + errors += [(step.name, error) for error in step.errors] - title = 'Build of <em>%s [%s]</em> on %s %s' \ - % (escape(label), escape(rev), escape(platform), - _status_label[status]) + title = Markup('Build of <em>%s [%s]</em> on %s %s', label, rev, + platform, _status_label[status]) message = '' if req.args.get('format') == 'rss': href = self.env.abs_href.build(config, id) @@ -637,7 +635,8 @@ if step != prev_step: if prev_step is not None: buf.write('</ul>') - buf.write('<p>Step %s failed:</p><ul>' % step) + buf.write('<p>Step %s failed:</p><ul>' % \ + escape(step)) prev_step = step buf.write('<li>%s</li>' % escape(error)) buf.write('</ul>') @@ -649,16 +648,17 @@ for step, error in errors: if step not in steps: steps.append(step) - steps = ['<em>%s</em>' % step for step in steps] + steps = [Markup('<em>%s</em>', step) for step in steps] if len(steps) < 2: message = steps[0] elif len(steps) == 2: - message = ' and '.join(steps) + message = Markup(' and ').join(steps) elif len(steps) > 2: - message = ', '.join(steps[:-1]) + ', and ' + \ - steps[-1] - message = 'Step%s ' % (len(steps) != 1 and 's' or '') \ - + message + ' failed' + message = Markup(', ').join(steps[:-1]) + ', and ' \ + + steps[-1] + message = Markup('Step%s %s failed', + len(steps) != 1 and 's' or '', + message) yield event_kinds[status], href, title, stopped, None, message # Internal methods
--- a/bitten/upgrades.py +++ b/bitten/upgrades.py @@ -10,13 +10,15 @@ import os import sys +from bitten.trac_ext.compat import schemaschema_to_sql + def add_log_table(env, db): """Add a table for storing the builds logs.""" from bitten.model import BuildLog, BuildStep cursor = db.cursor() for table in BuildLog._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) cursor.execute("SELECT build,name,log FROM bitten_step " @@ -29,7 +31,7 @@ cursor.execute("CREATE TEMP TABLE old_step AS SELECT * FROM bitten_step") cursor.execute("DROP TABLE bitten_step") for table in BuildStep._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) cursor.execute("INSERT INTO bitten_step (build,name,description,status," "started,stopped) SELECT build,name,description,status," @@ -46,7 +48,7 @@ "SELECT * FROM bitten_config") cursor.execute("DROP TABLE bitten_config") for table in BuildConfig._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) cursor.execute("INSERT INTO bitten_config (name,path,active,recipe,min_rev," "max_rev,label,description) SELECT name,path,0,'',NULL," @@ -106,7 +108,7 @@ cursor.execute("CREATE TEMP TABLE old_log AS " "SELECT * FROM bitten_log") cursor.execute("DROP TABLE bitten_log") - for stmt in db.to_sql(BuildLog._schema[0]): + for stmt in schema_to_sql(env, db, BuildLog._schema[0]): cursor.execute(stmt) cursor.execute("INSERT INTO bitten_log (id,build,step,generator,orderno) " "SELECT id,build,step,type,0 FROM old_log") @@ -117,7 +119,7 @@ cursor = db.cursor() for table in Report._schema: - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) def xmldb_to_db(env, db): @@ -261,7 +263,7 @@ Column('orderno', type='int') ] cursor = db.cursor() - for stmt in db.to_sql(table): + for stmt in schema_to_sql(env, db, table): cursor.execute(stmt) map = {
--- a/setup.py +++ b/setup.py @@ -21,7 +21,7 @@ description='Framework for collecting software metrics via continuous ' 'integration', license='BSD', - packages=find_packages(exclude=['ez_setup', '*.tests*']), + packages=find_packages(exclude=['*.tests*']), package_data={ 'bitten.trac_ext': ['htdocs/*.*', 'htdocs/charts_library/*.swf',