MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_assorted

Method test_assorted

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

Source from the content-addressed store, hash-verified

578 assert isinstance(func.concat("foo", "bar").type, sqltypes.String)
579
580 def test_assorted(self):
581 table1 = table("mytable", column("myid", Integer))
582
583 table2 = table("myothertable", column("otherid", Integer))
584
585 # test an expression with a function
586 self.assert_compile(
587 func.lala(3, 4, literal("five"), table1.c.myid) * table2.c.otherid,
588 "lala(:lala_1, :lala_2, :param_1, mytable.myid) * "
589 "myothertable.otherid",
590 )
591
592 # test it in a SELECT
593 self.assert_compile(
594 select(func.count(table1.c.myid)),
595 "SELECT count(mytable.myid) AS count_1 FROM mytable",
596 )
597
598 # test a "dotted" function name
599 self.assert_compile(
600 select(func.foo.bar.lala(table1.c.myid)),
601 "SELECT foo.bar.lala(mytable.myid) AS lala_1 FROM mytable",
602 )
603
604 # test the bind parameter name with a "dotted" function name is
605 # only the name (limits the length of the bind param name)
606 self.assert_compile(
607 select(func.foo.bar.lala(12)),
608 "SELECT foo.bar.lala(:lala_2) AS lala_1",
609 )
610
611 # test a dotted func off the engine itself
612 self.assert_compile(func.lala.hoho(7), "lala.hoho(:hoho_1)")
613
614 # test None becomes NULL
615 self.assert_compile(
616 func.my_func(1, 2, None, 3),
617 "my_func(:my_func_1, :my_func_2, NULL, :my_func_3)",
618 )
619
620 f1 = func.my_func(1, 2, None, 3)
621 f1._generate_cache_key()
622
623 # test pickling
624 self.assert_compile(
625 pickle.loads(pickle.dumps(f1)),
626 "my_func(:my_func_1, :my_func_2, NULL, :my_func_3)",
627 )
628
629 # assert func raises AttributeError for __bases__ attribute, since
630 # its not a class fixes pydoc
631 try:
632 func.__bases__
633 assert False
634 except AttributeError:
635 assert True
636
637 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