Skip to content

Commit ba6d25a

Browse files
committed
add tests for py module and function importing
1 parent 1dd9ee7 commit ba6d25a

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

test/clojure_python/t_core.clj

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,43 @@
2828
(base/init {:libpaths ["test/clojure_python/"]})
2929
(class base/*interp*)))
3030

31+
32+
(defmacro with-test-interp [& body]
33+
`(base/with-interpreter
34+
{:libpaths ["test/clojure_python/"]}
35+
~@body))
36+
3137
(fact "with-interpreter dynamically binds a new interpreter environment"
32-
(base/with-interpreter
33-
{:libpaths ["test/clojure_python/"]}
34-
base/*interp*)
38+
(with-test-interp base/*interp*)
3539
=not=>
36-
(base/with-interpreter
37-
{:libpaths ["test/clojure_python/"]}
38-
base/*interp*))
40+
(with-test-interp base/*interp*))
41+
42+
(fact "importing python modules works"
43+
(with-test-interp
44+
(base/py-import example)
45+
(class example))
46+
=>
47+
org.python.core.PyStringMap)
48+
49+
(fact "importing python functions works"
50+
(with-test-interp
51+
(base/py-import example)
52+
(base/import-fn example hello)
53+
(fn? hello))
54+
=>
55+
true)
56+
57+
(fact "calling python functions works"
58+
(with-test-interp
59+
(base/py-import example)
60+
(base/import-fn example hello)
61+
(hello "world"))
62+
=>
63+
"hello, world how are you."
64+
65+
(with-test-interp
66+
(base/py-import example)
67+
((base/py-fn example hello)
68+
"person"))
69+
=>
70+
"hello, person how are you.")

0 commit comments

Comments
 (0)