MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / test_assorted

Method test_assorted

test/sql/test_functions.py:523–578  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

521 assert isinstance(func.concat("foo", "bar").type, sqltypes.String)
522
523 def test_assorted(self):
524 table1 = table("mytable", column("myid", Integer))
525
526 table2 = table("myothertable", column("otherid", Integer))
527
528 # test an expression with a function
529 self.assert_compile(
530 func.lala(3, 4, literal("five"), table1.c.myid) * table2.c.otherid,
531 "lala(:lala_1, :lala_2, :param_1, mytable.myid) * "
532 "myothertable.otherid",
533 )
534
535 # test it in a SELECT
536 self.assert_compile(
537 select(func.count(table1.c.myid)),
538 "SELECT count(mytable.myid) AS count_1 FROM mytable",
539 )
540
541 # test a "dotted" function name
542 self.assert_compile(
543 select(func.foo.bar.lala(table1.c.myid)),
544 "SELECT foo.bar.lala(mytable.myid) AS lala_1 FROM mytable",
545 )
546
547 # test the bind parameter name with a "dotted" function name is
548 # only the name (limits the length of the bind param name)
549 self.assert_compile(
550 select(func.foo.bar.lala(12)),
551 "SELECT foo.bar.lala(:lala_2) AS lala_1",
552 )
553
554 # test a dotted func off the engine itself
555 self.assert_compile(func.lala.hoho(7), "lala.hoho(:hoho_1)")
556
557 # test None becomes NULL
558 self.assert_compile(
559 func.my_func(1, 2, None, 3),
560 "my_func(:my_func_1, :my_func_2, NULL, :my_func_3)",
561 )
562
563 f1 = func.my_func(1, 2, None, 3)
564 f1._generate_cache_key()
565
566 # test pickling
567 self.assert_compile(
568 pickle.loads(pickle.dumps(f1)),
569 "my_func(:my_func_1, :my_func_2, NULL, :my_func_3)",
570 )
571
572 # assert func raises AttributeError for __bases__ attribute, since
573 # its not a class fixes pydoc
574 try:
575 func.__bases__
576 assert False
577 except AttributeError:
578 assert True
579
580 def test_pickle_over(self):

Callers

nothing calls this directly

Calls 9

tableFunction · 0.90
columnFunction · 0.90
literalFunction · 0.90
selectFunction · 0.90
assert_compileMethod · 0.80
countMethod · 0.45
_generate_cache_keyMethod · 0.45
loadsMethod · 0.45
dumpsMethod · 0.45

Tested by

no test coverage detected