From: Mike Bayer Date: Tue, 21 Aug 2007 19:15:55 +0000 (+0000) Subject: added first profile tests per [ticket:753] X-Git-Tag: rel_0_4beta4~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8e92e6692568476c8bbaa4b27d0e4eace0a3a81;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git added first profile tests per [ticket:753] --- diff --git a/test/alltests.py b/test/alltests.py index e3266f5632..71fed19659 100644 --- a/test/alltests.py +++ b/test/alltests.py @@ -8,10 +8,11 @@ import engine.alltests as engine import dialect.alltests as dialect import ext.alltests as ext import zblog.alltests as zblog +import profiling.alltests as profiling def suite(): alltests = unittest.TestSuite() - for suite in (base, engine, sql, dialect, orm, ext, zblog): + for suite in (base, engine, sql, dialect, orm, ext, zblog, profiling): alltests.addTest(suite.suite()) return alltests diff --git a/test/profiling/__init__.py b/test/profiling/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/profiling/alltests.py b/test/profiling/alltests.py new file mode 100644 index 0000000000..94f7e1fd20 --- /dev/null +++ b/test/profiling/alltests.py @@ -0,0 +1,18 @@ +import testbase +import unittest + + +def suite(): + modules_to_test = ( + 'profiling.compiler', + ) + alltests = unittest.TestSuite() + for name in modules_to_test: + mod = __import__(name) + for token in name.split('.')[1:]: + mod = getattr(mod, token) + alltests.addTest(unittest.findTestCases(mod, suiteClass=None)) + return alltests + +if __name__ == '__main__': + testbase.main(suite()) diff --git a/test/profiling/compiler.py b/test/profiling/compiler.py new file mode 100644 index 0000000000..7dbad1703f --- /dev/null +++ b/test/profiling/compiler.py @@ -0,0 +1,34 @@ +import testbase +from sqlalchemy import * +from testlib import * + + +class CompileTest(AssertMixin): + def setUpAll(self): + global t1, t2, metadata + metadata = MetaData() + t1 = Table('t1', metadata, + Column('c1', Integer, primary_key=True), + Column('c2', String(30))) + + t2 = Table('t2', metadata, + Column('c1', Integer, primary_key=True), + Column('c2', String(30))) + + @profiling.profiled('ctest_insert', call_range=(50, 60), always=True) + def test_insert(self): + t1.insert().compile() + + @profiling.profiled('ctest_update', call_range=(50, 60), always=True) + def test_update(self): + t1.update().compile() + + # TODO: this is alittle high + @profiling.profiled('ctest_select', call_range=(190, 210), always=True) + def test_select(self): + s = select([t1], t1.c.c2==t2.c.c1) + s.compile() + + +if __name__ == '__main__': + testbase.main() diff --git a/test/testlib/profiling.py b/test/testlib/profiling.py index efcc1340fb..f2f75f66e8 100644 --- a/test/testlib/profiling.py +++ b/test/testlib/profiling.py @@ -3,6 +3,7 @@ import testbase from testlib.config import parser, post_configure import testlib.config +import os __all__ = 'profiled', @@ -52,9 +53,9 @@ def profiled(target, **target_opts): if not testlib.config.options.quiet: print "Profiled target '%s', wall time: %.2f seconds" % ( target, ended - began) - + report = target_opts.get('report', profile_config['report']) - if report: + if report and testlib.config.options.verbose: sort_ = target_opts.get('sort', profile_config['sort']) limit = target_opts.get('limit', profile_config['limit']) print "Profile report for target '%s' (%s)" % ( @@ -66,6 +67,13 @@ def profiled(target, **target_opts): stats.print_stats(limit) else: stats.print_stats() + + assert_range = target_opts.get('call_range') + if assert_range: + stats = hotshot.stats.load(filename) + assert stats.total_calls >= assert_range[0] and stats.total_calls <= assert_range[1], stats.total_calls + + os.unlink(filename) return result try: profiled.__name__ = fn.__name__