summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-08-21 19:15:55 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-08-21 19:15:55 +0000
commitb8e92e6692568476c8bbaa4b27d0e4eace0a3a81 (patch)
tree4554f9bffac6eb062bf0feb96d78d872c209fd0d /test
parent04e70c708f99f4f0b8b6c48e3c631bfa02dcd78f (diff)
downloadsqlalchemy-b8e92e6692568476c8bbaa4b27d0e4eace0a3a81.tar.gz
added first profile tests per [ticket:753]
Diffstat (limited to 'test')
-rw-r--r--test/alltests.py3
-rw-r--r--test/profiling/__init__.py0
-rw-r--r--test/profiling/alltests.py18
-rw-r--r--test/profiling/compiler.py34
-rw-r--r--test/testlib/profiling.py12
5 files changed, 64 insertions, 3 deletions
diff --git a/test/alltests.py b/test/alltests.py
index e3266f563..71fed1965 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 000000000..e69de29bb
--- /dev/null
+++ b/test/profiling/__init__.py
diff --git a/test/profiling/alltests.py b/test/profiling/alltests.py
new file mode 100644
index 000000000..94f7e1fd2
--- /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 000000000..7dbad1703
--- /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 efcc1340f..f2f75f66e 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__