summaryrefslogtreecommitdiff
path: root/test/ext/test_compiler.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2009-11-10 00:43:53 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2009-11-10 00:43:53 +0000
commit55a3e5e30d142ccfb38c3bdf333d632b0177c01c (patch)
tree08285b730e219570c08756ab3620ef4b29ba5ea9 /test/ext/test_compiler.py
parent12a323eb0c4f90230016da8a2bd66928b448c142 (diff)
downloadsqlalchemy-55a3e5e30d142ccfb38c3bdf333d632b0177c01c.tar.gz
- subclassed Function off of new FunctionElement generic base
- removed "key" accessor of Function, Grouping - this doesn't seem to be used for anything - various formatting - documented the four "Element" classes in the compiler extension as per [ticket:1590]
Diffstat (limited to 'test/ext/test_compiler.py')
-rw-r--r--test/ext/test_compiler.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/test/ext/test_compiler.py b/test/ext/test_compiler.py
index 3ee94d027..d625ae0ca 100644
--- a/test/ext/test_compiler.py
+++ b/test/ext/test_compiler.py
@@ -1,6 +1,7 @@
from sqlalchemy import *
from sqlalchemy.types import TypeEngine
-from sqlalchemy.sql.expression import ClauseElement, ColumnClause
+from sqlalchemy.sql.expression import ClauseElement, ColumnClause,\
+ FunctionElement
from sqlalchemy.schema import DDLElement
from sqlalchemy.ext.compiler import compiles
from sqlalchemy.sql import table, column
@@ -151,3 +152,30 @@ class UserDefinedTest(TestBase, AssertsCompiledSQL):
"DROP THINGY",
)
+ def test_functions(self):
+ from sqlalchemy.dialects.postgresql import base as postgresql
+
+ class MyUtcFunction(FunctionElement):
+ pass
+
+ @compiles(MyUtcFunction)
+ def visit_myfunc(element, compiler, **kw):
+ return "utcnow()"
+
+ @compiles(MyUtcFunction, 'postgresql')
+ def visit_myfunc(element, compiler, **kw):
+ return "timezone('utc', current_timestamp)"
+
+ self.assert_compile(
+ MyUtcFunction(),
+ "utcnow()",
+ use_default_dialect=True
+ )
+ self.assert_compile(
+ MyUtcFunction(),
+ "timezone('utc', current_timestamp)",
+ dialect=postgresql.dialect()
+ )
+
+
+ \ No newline at end of file