Skip to content

Commit

Permalink
Merge pull request #52 from Evizero/ox/noprompttocreate
Browse files Browse the repository at this point in the history
If file does not exist, create it (No Prompt)
  • Loading branch information
oxinabox authored Feb 18, 2020
2 parents 24cafe2 + 6791818 commit 712f30f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ReferenceTests"
uuid = "324d217c-45ce-50fc-942e-d289b448e8cf"
authors = ["Christof Stocker <stocker.christof@gmail.com>", "Lyndon White <oxinabox@ucc.asn.au>"]
version = "0.8.4"
version = "0.9.0"

[deps]
DeepDiffs = "ab62b9b5-e342-54a8-a765-a90f495de1a6"
Expand Down
16 changes: 4 additions & 12 deletions src/test_reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,14 @@ 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)

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

5 comments on commit 712f30f

@oxinabox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/9711

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.0 -m "<description of version>" 712f30fb7f38395b4cd96045ac15e5b5a3c21148
git push origin v0.9.0

@johnnychen94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- If file does not exist, create it (No Prompt) (#52)(@oxinabox) was not presented in the release log, I just manually added it

cc: @christopher-dG

@christopher-dG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I'll look into this.

@christopher-dG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.