File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
tests/apps/migrations/auto Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 55from piccolo .columns .reference import LazyTableReference
66
77
8+ def example_function ():
9+ pass
10+
11+
812class TestSerialiseParams (TestCase ):
913 def test_time (self ):
1014 serialised = serialise_params (params = {"default" : TimeNow ()})
@@ -58,3 +62,31 @@ def test_lazy_table_reference(self):
5862 serialised .extra_definitions [0 ].__str__ (),
5963 'class Manager(Table, tablename="manager"): pass' ,
6064 )
65+
66+ def test_function (self ):
67+ serialised = serialise_params (params = {"default" : example_function })
68+ self .assertTrue (
69+ serialised .params ["default" ].__repr__ () == "example_function"
70+ )
71+
72+ self .assertTrue (len (serialised .extra_imports ) == 1 )
73+ self .assertEqual (
74+ serialised .extra_imports [0 ].__str__ (),
75+ (
76+ "from tests.apps.migrations.auto.test_serialisation import "
77+ "example_function"
78+ ),
79+ )
80+
81+ self .assertTrue (len (serialised .extra_definitions ) == 0 )
82+
83+ def test_lambda (self ):
84+ """
85+ Make sure lambda functions are rejected.
86+ """
87+ with self .assertRaises (ValueError ) as manager :
88+ serialise_params (params = {"default" : lambda x : x + 1 })
89+
90+ self .assertEqual (
91+ manager .exception .__str__ (), "Lambdas can't be serialised"
92+ )
You can’t perform that action at this time.
0 commit comments