From ba6d25ac5987c4fd67a32e0a8a945f38ae2b6fda Mon Sep 17 00:00:00 2001 From: Robert Levy Date: Wed, 14 Dec 2011 18:50:36 -0500 Subject: [PATCH] add tests for py module and function importing --- test/clojure_python/t_core.clj | 44 +++++++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/test/clojure_python/t_core.clj b/test/clojure_python/t_core.clj index 04c1a91..0e3256a 100644 --- a/test/clojure_python/t_core.clj +++ b/test/clojure_python/t_core.clj @@ -28,11 +28,43 @@ (base/init {:libpaths ["test/clojure_python/"]}) (class base/*interp*))) + +(defmacro with-test-interp [& body] + `(base/with-interpreter + {:libpaths ["test/clojure_python/"]} + ~@body)) + (fact "with-interpreter dynamically binds a new interpreter environment" - (base/with-interpreter - {:libpaths ["test/clojure_python/"]} - base/*interp*) + (with-test-interp base/*interp*) =not=> - (base/with-interpreter - {:libpaths ["test/clojure_python/"]} - base/*interp*)) + (with-test-interp base/*interp*)) + +(fact "importing python modules works" + (with-test-interp + (base/py-import example) + (class example)) + => + org.python.core.PyStringMap) + +(fact "importing python functions works" + (with-test-interp + (base/py-import example) + (base/import-fn example hello) + (fn? hello)) + => + true) + +(fact "calling python functions works" + (with-test-interp + (base/py-import example) + (base/import-fn example hello) + (hello "world")) + => + "hello, world how are you." + + (with-test-interp + (base/py-import example) + ((base/py-fn example hello) + "person")) + => + "hello, person how are you.")