]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added first profile tests per [ticket:753]
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 21 Aug 2007 19:15:55 +0000 (19:15 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 21 Aug 2007 19:15:55 +0000 (19:15 +0000)
test/alltests.py
test/profiling/__init__.py [new file with mode: 0644]
test/profiling/alltests.py [new file with mode: 0644]
test/profiling/compiler.py [new file with mode: 0644]
test/testlib/profiling.py

index e3266f5632eef95891bda79f562af30420468d32..71fed196593735dddce31c416b733a40e59449a9 100644 (file)
@@ -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 (file)
index 0000000..e69de29
diff --git a/test/profiling/alltests.py b/test/profiling/alltests.py
new file mode 100644 (file)
index 0000000..94f7e1f
--- /dev/null
@@ -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 (file)
index 0000000..7dbad17
--- /dev/null
@@ -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()        
index efcc1340fbafed46942703793e83ddb70f687092..f2f75f66e86a9cdec05711a2137a731c71448484 100644 (file)
@@ -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__