From ed0c2ae0cfa5a3ecab0942576ed90100b01cef61 Mon Sep 17 00:00:00 2001 From: Chouffe Date: Sat, 1 Jun 2019 22:09:12 +0200 Subject: [PATCH 1/2] [clojure] fix: image test does not rely on s3 to run --- .../org/apache/clojure_mxnet/image_test.clj | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj b/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj index 23b88d07e896..0cd74c666d3f 100644 --- a/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj +++ b/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj @@ -19,27 +19,35 @@ (:require [org.apache.clojure-mxnet.image :as image] [org.apache.clojure-mxnet.ndarray :as ndarray] [clojure.java.io :as io] - [clojure.test :refer :all]) + [clojure.test :refer [deftest is use-fixtures]]) (:import (javax.imageio ImageIO) (java.io File))) (def tmp-dir (System/getProperty "java.io.tmpdir")) (def image-path (.getAbsolutePath (io/file tmp-dir "Pug-Cookie.jpg"))) +(def image-src-path "test/test-images/Pug-Cookie.jpg") -(defn download-image [] - (with-open [in (io/input-stream "https://s3.amazonaws.com/model-server/inputs/Pug-Cookie.jpg") - out (io/output-stream (io/file image-path))] +(defn- cp + "Copy from filepath `from` to filepath `to`." + [from to] + (with-open [in (io/input-stream (io/file from)) + out (io/output-stream (io/file to))] (io/copy in out))) -(defn delete-image [] - (io/delete-file image-path)) +(defn- rm + "Removes `filepath`." + [filepath] + (io/delete-file filepath)) -(defn with-downloaded-image [f] - (download-image) - (f) - (delete-image)) +(defn- with-image + "Provides `src-path` in `dest-path` for the test function `f` to use." + [src-path dest-path] + (fn [f] + (cp src-path dest-path) + (f) + (rm dest-path))) -(use-fixtures :once with-downloaded-image) +(use-fixtures :once (with-image image-src-path image-path)) (deftest test-decode-image (let [img-arr (image/decode-image From 501e30ecf5fae737c9cbe9a95c12f4cf66ff6e02 Mon Sep 17 00:00:00 2001 From: Chouffe Date: Sat, 1 Jun 2019 22:12:05 +0200 Subject: [PATCH 2/2] rename `with-image` to `with-file` --- .../test/org/apache/clojure_mxnet/image_test.clj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj b/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj index 0cd74c666d3f..b543b2d6acf8 100644 --- a/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj +++ b/contrib/clojure-package/test/org/apache/clojure_mxnet/image_test.clj @@ -39,7 +39,7 @@ [filepath] (io/delete-file filepath)) -(defn- with-image +(defn- with-file "Provides `src-path` in `dest-path` for the test function `f` to use." [src-path dest-path] (fn [f] @@ -47,12 +47,12 @@ (f) (rm dest-path))) -(use-fixtures :once (with-image image-src-path image-path)) +(use-fixtures :once (with-file image-src-path image-path)) (deftest test-decode-image - (let [img-arr (image/decode-image + (let [img-arr (image/decode-image (io/input-stream image-path)) - img-arr-2 (image/decode-image + img-arr-2 (image/decode-image (io/input-stream image-path) {:color-flag image/GRAYSCALE})] (is (= [576 1024 3] (ndarray/shape-vec img-arr)))