Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

If file does not exist, create it (No Prompt) #52

Merged
merged 3 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions src/test_reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,18 +114,10 @@ function test_reference(
# TODO: move encoding out from render
render(rendermode, raw_actual)

if !isinteractive()
error("You need to run the tests interactively with 'include(\"test/runtests.jl\")' to create new reference images")
end

if !input_bool("Create reference file with above content (path: $path)?")
@test false
else
mkpath(dir)
savefile(file, actual)
@info("Please run the tests again for any changes to take effect")
end

mkpath(dir)
savefile(file, actual)

@info("Please run the tests again for any changes to take effect")
return nothing # skip current test case
end

Expand Down
29 changes: 25 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ end
"""

@test_throws ErrorException @test_reference "references/string1.txt" "intentionally wrong to check that this message prints"
@test_throws ErrorException @test_reference "references/wrong.txt" "intentional error to check that this message prints"
@test_throws ErrorException @test_reference "references/string5.txt" """
This is an incorrect
multiline string that does not end with a new line."""
Expand All @@ -77,7 +76,7 @@ end

@testset "images as txt using ImageInTerminal" begin
#@test_throws MethodError @test_reference "references/fail.txt" rand(2,2)
@test_throws ErrorException @test_reference "references/camera_new.txt" camera size=(5,10)

@test_reference "references/camera.txt" camera size=(5,10)
@test_reference "references/lena.txt" lena
end
Expand Down Expand Up @@ -111,16 +110,38 @@ end
@testset "images as PNG" begin
@test_reference "references/camera.png" imresize(camera, (64,64))
@test_reference "references/camera.png" imresize(camera, (64,64)) by=psnr_equality(25)
@test_throws Exception @test_reference "references/wrongfilename.png" imresize(camera, (64,64))
@test_throws ErrorException @test_reference "references/camera.png" imresize(lena, (64,64))
@test_throws Exception @test_reference "references/camera.png" camera # unequal size
end

using DataFrames, CSVFiles
@testset "DataFrame as CSV" begin
@test_reference "references/dataframe.csv" DataFrame(v1=[1,2,3], v2=["a","b","c"])
@test_throws ErrorException @test_reference "references/wrongfilename.csv" DataFrame(v1=[1,2,3], v2=["a","b","c"])
@test_throws ErrorException @test_reference "references/dataframe.csv" DataFrame(v1=[1,2,3], v2=["c","b","c"])

end

@testset "Create new $ext" for (ext, val) in (
(".csv", DataFrame(v1=[1,2,3], v2=["c","b","c"])),
(".png", imresize(camera, (64,64))),
(".txt", "Lorem ipsum dolor sit amet, labore et dolore magna aliqua."),
)
newfilename = "references/newfilename.$ext"
@assert !isfile(newfilename)
@test_reference newfilename val # this should create it
@test isfile(newfilename) # Was created
@test_reference newfilename val # Matches expected content
rm(newfilename, force=true)
end

@testset "Create new image as txt" begin
# This is a sperate testset as need to use the `size` argument to ``@test_reference`
newfilename = "references/new_camera.txt"
@assert !isfile(newfilename)
@test_reference newfilename camera size=(5,10) # this should create it
@test isfile(newfilename) # Was created
@test_reference newfilename camera size=(5,10) # Matches expected content
rm(newfilename, force=true)
end

end # top level testset