Skip to content

Commit

Permalink
Fix test for abaqus_download
Browse files Browse the repository at this point in the history
Return environment variables to the original state after finish test.
  • Loading branch information
ahojukka5 committed Mar 11, 2018
1 parent 918c34a commit 3ab6ce0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
5 changes: 1 addition & 4 deletions src/abaqus_download.jl
Expand Up @@ -25,10 +25,7 @@ Function call will return full path to downloaded file or nothing, if download
is failing because of missing environment variable `ABAQUS_DOWNLOAD_DIR`.
"""
function abaqus_download(model_name; dryrun=false)
path = ""
if haskey(ENV, "ABAQUS_DOWNLOAD_DIR")
path = ENV["ABAQUS_DOWNLOAD_DIR"]
end
path = get(ENV, "ABAQUS_DOWNLOAD_DIR", ".")
fn = joinpath(path, model_name)
if isfile(fn) # already downloaded
return fn
Expand Down
8 changes: 3 additions & 5 deletions test/test_download.jl
Expand Up @@ -5,19 +5,17 @@ using AbaqusReader
using Base.Test

@testset "test abaqus_download" begin
original_ENV = copy(ENV)
delete!(ENV, "ABAQUS_DOWNLOAD_URL")
delete!(ENV, "ABAQUS_DOWNLOAD_DIR")
fn = tempname()
touch(fn)
model_name = basename(fn)
ENV["ABAQUS_DOWNLOAD_DIR"] = dirname(fn)
println("fn = ", fn)
println("isfile(fn) = ", isfile(fn))
println("model_name = ", model_name)
println("ABAQUS_DOWNLOAD_DIR = ", ENV["ABAQUS_DOWNLOAD_DIR"])
@test abaqus_download(model_name) == fn
rm(fn)
isfile(fn) && rm(fn)
@test abaqus_download(model_name) == nothing
ENV["ABAQUS_DOWNLOAD_URL"] = "https://models.com"
@test abaqus_download(model_name; dryrun=true) == fn
merge!(ENV, original_ENV)
end

0 comments on commit 3ab6ce0

Please sign in to comment.