From 1c631e0d044153010bfd0a36be942c9e0c6f4fa4 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Tue, 18 Feb 2020 14:32:28 +0000 Subject: [PATCH 1/3] If file does not exist, create it --- src/test_reference.jl | 16 ++++------------ test/runtests.jl | 29 +++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/test_reference.jl b/src/test_reference.jl index 1955010..f67046c 100644 --- a/src/test_reference.jl +++ b/src/test_reference.jl @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index b750d61..8b8821c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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.""" @@ -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 @@ -111,7 +110,6 @@ 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 @@ -119,8 +117,31 @@ 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 From c06c1432c935eb31afb555b14d5a4ce651d5fecf Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Tue, 18 Feb 2020 15:41:22 +0000 Subject: [PATCH 2/3] mention in message that it will be created --- src/test_reference.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test_reference.jl b/src/test_reference.jl index f67046c..211f510 100644 --- a/src/test_reference.jl +++ b/src/test_reference.jl @@ -110,13 +110,13 @@ function test_reference( actual = _convert(F, raw_actual; kw...) # preprocessing when reference file doesn't exists if !isfile(path) - println("Reference file for \"$filename\" does not exist.") + @info("Reference file for \"$filename\" does not exist. It will be created") # TODO: move encoding out from render render(rendermode, raw_actual) mkpath(dir) savefile(file, actual) - + @info("Please run the tests again for any changes to take effect") return nothing # skip current test case end From 6791818a446f9c3594d851add0afc398d4ac0130 Mon Sep 17 00:00:00 2001 From: Lyndon White Date: Tue, 18 Feb 2020 15:44:31 +0000 Subject: [PATCH 3/3] bump version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index abe4830..8f3e74b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ReferenceTests" uuid = "324d217c-45ce-50fc-942e-d289b448e8cf" authors = ["Christof Stocker ", "Lyndon White "] -version = "0.8.4" +version = "0.9.0" [deps] DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"