@@ -69,44 +69,59 @@ tests = testGroup "Callbacks"
6969 let foo :: Int -> IO Int
7070 foo y = pure $ 10 `div` y
7171 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- ]
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 " runPyInMain in runPyInMain (arity=1)" $ do
93+ let foo :: Int -> IO Int
94+ foo x = do Just x' <- runPyInMain $ fromPy =<< [pye | 100 // x_hs |]
95+ pure x'
96+ runPyInMain [py_ |
97+ assert foo_hs(5) == 20
98+ |]
99+ , testCase " runPyInMain in runPy (arity=1)" $ do
100+ let foo :: Int -> IO Int
101+ foo x = do Just x' <- runPyInMain $ fromPy =<< [pye | 100 // x_hs |]
102+ pure x'
103+ runPy [py_ |
104+ assert foo_hs(5) == 20
105+ |]
106+ ----------------------------------------
107+ , testCase " No leaks (arity=1)" $ runPy $ do
108+ let foo :: Int -> IO Int
109+ foo y = pure $ 10 * y
110+ [py_ |
111+ import sys
112+ x = 123456
113+ old_refcount = sys.getrefcount(x)
114+ foo_hs(x)
115+ assert old_refcount == sys.getrefcount(x)
116+ |]
117+ , testCase " No leaks (arity=2)" $ runPy $ do
118+ let foo :: Int -> Int -> IO Int
119+ foo x y = pure $ x * y
120+ [py_ |
121+ import sys
122+ x = 123456
123+ old_refcount = sys.getrefcount(x)
124+ foo_hs(1,x)
125+ assert old_refcount == sys.getrefcount(x)
126+ |]
127+ ]
0 commit comments