@@ -54,48 +54,59 @@ tests = testGroup "Callbacks"
5454 except TypeError as e:
5555 pass
5656 |]
57- , testCase " Haskell exception in callback(arity=1)" $ runPy $ do
58- let foo :: Int -> IO Int
59- foo y = pure $ 10 `div` y
60- throwsPy [py_ | foo_hs(0) |]
61- , testCase " Haskell exception in callback(arity=2)" $ runPy $ do
62- let foo :: Int -> Int -> IO Int
63- foo x y = pure $ x `div` y
64- throwsPy [py_ | foo_hs(1, 0) |]
6557 ----------------------------------------
66- , testCase " Call python in callback (arity=1)" $ runPy $ do
67- let foo :: Int -> IO Int
68- foo x = do Just x' <- runPy $ fromPy =<< [pye | 100 // x_hs |]
69- pure x'
70- [py_ |
71- assert foo_hs(5) == 20
72- |]
73- , testCase " Call python in callback (arity=2" $ runPy $ do
74- let foo :: Int -> Int -> IO Int
75- foo x y = do Just x' <- runPy $ fromPy =<< [pye | x_hs // y_hs |]
76- pure x'
77- [py_ |
78- assert foo_hs(100,5) == 20
79- |]
58+ , testCase " Py function(arity 0)" $ do
59+ let fun = [pye | 0 |]
60+ runPy [py_ | assert fun_hs() == 0 |]
61+ , testCase " Py function(arity=1)" $ runPy $ do
62+ let double (n:: Int ) = [pye | n_hs * 2 |]
63+ [py_ | assert double_hs(3) == 6 |]
64+ , testCase " Py function(arity=2)" $ runPy $ do
65+ let foo (x:: Int ) (y:: Int ) = [pye | x_hs * y_hs |]
66+ [py_ | assert foo_hs(3, 100) == 300 |]
8067 ----------------------------------------
81- , testCase " No leaks (arity=1)" $ runPy $ do
82- let foo :: Int -> IO Int
83- foo y = pure $ 10 * y
84- [py_ |
85- import sys
86- x = 123456
87- old_refcount = sys.getrefcount(x)
88- foo_hs(x)
89- assert old_refcount == sys.getrefcount(x)
90- |]
91- , testCase " No leaks (arity=2)" $ runPy $ do
92- let foo :: Int -> Int -> IO Int
93- foo x y = pure $ x * y
94- [py_ |
95- import sys
96- x = 123456
97- old_refcount = sys.getrefcount(x)
98- foo_hs(1,x)
99- assert old_refcount == sys.getrefcount(x)
100- |]
101- ]
68+ , testCase " Haskell exception in callback(arity=1)" $ runPy $ do
69+ let foo :: Int -> IO Int
70+ foo y = pure $ 10 `div` y
71+ throwsPy [py_ | foo_hs(0) |]
72+ , testCase " Haskell exception in callback(arity=2)" $ runPy $ do
73+ let foo :: Int -> Int -> IO Int
74+ foo x y = pure $ x `div` y
75+ throwsPy [py_ | foo_hs(1, 0) |]
76+ ----------------------------------------
77+ , testCase " Call python in callback (arity=1)" $ runPy $ do
78+ let foo :: Int -> IO Int
79+ foo x = do Just x' <- runPy $ fromPy =<< [pye | 100 // x_hs |]
80+ pure x'
81+ [py_ |
82+ assert foo_hs(5) == 20
83+ |]
84+ , testCase " Call python in callback (arity=2" $ runPy $ do
85+ let foo :: Int -> Int -> IO Int
86+ foo x y = do Just x' <- runPy $ fromPy =<< [pye | x_hs // y_hs |]
87+ pure x'
88+ [py_ |
89+ assert foo_hs(100,5) == 20
90+ |]
91+ ----------------------------------------
92+ , testCase " No leaks (arity=1)" $ runPy $ do
93+ let foo :: Int -> IO Int
94+ foo y = pure $ 10 * y
95+ [py_ |
96+ import sys
97+ x = 123456
98+ old_refcount = sys.getrefcount(x)
99+ foo_hs(x)
100+ assert old_refcount == sys.getrefcount(x)
101+ |]
102+ , testCase " No leaks (arity=2)" $ runPy $ do
103+ let foo :: Int -> Int -> IO Int
104+ foo x y = pure $ x * y
105+ [py_ |
106+ import sys
107+ x = 123456
108+ old_refcount = sys.getrefcount(x)
109+ foo_hs(1,x)
110+ assert old_refcount == sys.getrefcount(x)
111+ |]
112+ ]
0 commit comments