Skip to content

Commit

Permalink
[clojure] fix: image test does not rely on s3 to run (apache#15122)
Browse files Browse the repository at this point in the history
* [clojure] fix: image test does not rely on s3 to run

* rename `with-image` to `with-file`
  • Loading branch information
Chouffe authored and haohuw committed Jun 23, 2019
1 parent ed1a362 commit 8ed2a98
Showing 1 changed file with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,40 @@
(: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-file
"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-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)))
Expand Down

0 comments on commit 8ed2a98

Please sign in to comment.