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
--- /dev/null
+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())
--- /dev/null
+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()
import testbase
from testlib.config import parser, post_configure
import testlib.config
+import os
__all__ = 'profiled',
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)" % (
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__