Skip to content

Commit 9dc492c

Browse files
johnnychen94timholy
authored andcommitted
Add some docs and tests (#35)
1 parent 4765c88 commit 9dc492c

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

src/TestImages.jl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ remotefiles = [
4444
"woman_darkhair.tif" ,
4545
]
4646

47+
"""
48+
testimage(filename, [ops...])
49+
50+
load test image that partially matches `filename`, the first match is used if there're more than one. If `ops` is specified, it will be passed to `load` function. use `TestImages.remotefiles` to get a full list of available images.
51+
52+
# Example
53+
```julia
54+
julia> using TestImages
55+
julia> testimage("cameraman.tif")
56+
julia> testimage("cameraman")
57+
julia> testimage("c")
58+
```
59+
"""
4760
function testimage(filename, ops...)
4861
isdir(imagedir) || mkpath(imagedir)
4962
imagefile = joinpath(imagedir, filename)
@@ -59,7 +72,7 @@ function testimage(filename, ops...)
5972
end
6073

6174
if !havefile
62-
@info "Could not find "*filename*" in directory. Checking if it exists in the online repository."
75+
@info "Could not find "*filename*" in directory images/ . Checking if it exists in the online repository."
6376
for f in remotefiles
6477
if startswith(f, filename)
6578
@info "Found "*filename*" in the online repository. Downloading to the images directory."
@@ -70,7 +83,7 @@ function testimage(filename, ops...)
7083
end
7184
end
7285
end
73-
havefile || error("$filename not found in the directory or the online repository. Here are the contents of the images/ directory:\n$(join(fls, '\n'))")
86+
havefile || throw(ArgumentError("$filename not found in the directory images/ or the online repository. use `TestImages.remotefiles` to get a full list of test images"))
7487
end
7588
img = load(imagefile, ops...)
7689
if startswith(basename(imagefile), "mri-stack")

test/runtests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ img = testimage("cameraman")
66
img = testimage("mri-stack")
77
@test isa(img, AxisArray)
88
@test map(step, axisvalues(img)) == (1,1,5)
9+
@test_nowarn testimage("c")
10+
@test_throws ArgumentError testimage("nonexistence.png")
911

10-
nothing
12+
@test all([f in TestImages.remotefiles for f in readdir(TestImages.imagedir)])

0 commit comments

Comments
 (0)