Skip to content

Commit

Permalink
rework @test_reference messages - drop lena (#118)
Browse files Browse the repository at this point in the history
* rework test msg (only ci) - drop lena

* update

* update Project - deps

* fix docs build

* update reference files
  • Loading branch information
t-bltg authored Dec 28, 2023
1 parent f71f2d1 commit 895e4be
Show file tree
Hide file tree
Showing 11 changed files with 138 additions and 114 deletions.
13 changes: 6 additions & 7 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ XTermColors = "c8c2cc18-de81-4e68-b407-38a3a0c0491f"
BSON = "0.3"
Colors = "0.10 - 0.12"
CSVFiles = "1"
DataFrames = "0.21 - 0.22"
DeepDiffs = "1.1"
DataFrames = "0.21 - 0.22, 1"
DeepDiffs = "1"
Distances = "0.7 - 0.10"
FileIO = "1"
GR = "= 0.50.1"
ImageCore = "0.8.1, 0.9, 0.10"
ImageMagick = "0.7, 1"
ImageTransformations = "0.8"
ImageTransformations = "0.8 - 0.10"
LazyModules = "0.3"
Plots = "= 1.4.3"
Plots = "= 1.39.0"
TestImages = "0.6, 1"
XTermColors = "0.2"
julia = "1.6"
Expand All @@ -37,12 +36,12 @@ julia = "1.6"
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
CSVFiles = "5d742f6a-9f54-50ce-8119-2520741973ca"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
ImageTransformations = "02fcd773-0e25-5acc-982a-7f6622650795"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"

[targets]
test = ["CSVFiles", "DataFrames", "ImageMagick", "ImageTransformations", "GR", "Plots", "TestImages", "ImageIO", "BSON"]
test = ["BSON", "CSVFiles", "DataFrames", "ImageIO", "ImageMagick", "ImageTransformations", "Logging", "Plots", "TestImages"]
1 change: 1 addition & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ makedocs(
sitename = "ReferenceTests.jl",
authors = "Christof Stocker",
linkcheck = !("skiplinks" in ARGS),
checkdocs = :exports,
pages = Any[
"Home" => "index.md",
]
Expand Down
63 changes: 37 additions & 26 deletions src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,56 @@ struct BeforeAfterLimited <: BeforeAfter end
struct BeforeAfterFull <: BeforeAfter end
struct BeforeAfterImage <: BeforeAfter end

render_item(::RenderMode, item) = println(item)
color_buffer(args...) =
IOContext(PipeBuffer(), :color=>Base.get_have_color(), args...)

function render_item(::RenderMode, item)
io = color_buffer()
print(io, item)
read(io, String)
end
function render_item(::BeforeAfterLimited, item)
show(IOContext(stdout, :limit=>true, :displaysize=>(20,80)), "text/plain", item)
println()
io = color_buffer(
:limit=>true,
:displaysize=>(20,80)
)
show(io, "text/plain", item)
read(io, String)
end
function render_item(::BeforeAfterImage, item)
str_item = @withcolor XTermColors.ascii_show(
io = color_buffer()
println(io, "eltype: ", eltype(item))
println(io, "size: ", map(length, axes(item)))
println(io, "thumbnail:")
strs = @withcolor XTermColors.ascii_show(
item,
Base.invokelatest(XTermColors.TermColor8bit),
:small,
(20, 40)
)
println("eltype: ", eltype(item))
println("size: ", map(length, axes(item)))
println("thumbnail:")
println.(str_item)
print(io, join(strs, '\n'))
read(io, String)
end

## 2 arg form render for comparing
function render(mode::BeforeAfter, reference, actual)
println("- REFERENCE -------------------")
render_item(mode, reference)
println("-------------------------------")
println("- ACTUAL ----------------------")
render_item(mode, actual)
println("-------------------------------")
end
function render(::Diff, reference, actual)
println("- DIFF ------------------------")
@withcolor println(deepdiff(reference, actual))
println("-------------------------------")
end
render(mode::BeforeAfter, reference, actual) = """
- REFERENCE -------------------
$(render_item(mode, reference))
-------------------------------
- ACTUAL ----------------------
$(render_item(mode, actual))
-------------------------------"""

render(mode::Diff, reference, actual) = """
- DIFF ------------------------
$(@withcolor(render_item(mode, deepdiff(reference, actual))))
-------------------------------"""

## 1 arg form render for new content
function render(mode::RenderMode, actual)
println("- NEW CONTENT -----------------")
render_item(mode, actual)
println("-------------------------------")
end
render(mode::RenderMode, actual) = """
- NEW CONTENT -----------------
$(render_item(mode, actual))
-------------------------------"""

"""
default_rendermode(::DataFormat, actual)
Expand Down
25 changes: 9 additions & 16 deletions src/test_reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,11 @@ function test_reference(
if !isfile(reference_path) # when reference file doesn't exists
mkpath(reference_dir)
savefile(reference_file, actual)
@info(
"Reference file for \"$reference_filename\" did not exist. It has been created",
new_reference=reference_path,
)
@info """Reference file for \"$reference_filename\" did not exist. It has been created:
$(render(rendermode, actual))
""" new_reference = reference_path

# TODO: move encoding out from render
render(rendermode, actual)

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

Expand All @@ -161,13 +157,10 @@ function test_reference(
savefile(actual_file, actual)

# Report to user.
@info(
"Reference Test for \"$reference_filename\" failed.",
reference=reference_path,
actual=actual_path,
)
render(rendermode, reference, actual)

@info """Reference Test for \"$reference_filename\" failed:
$(render(rendermode, reference, actual))
""" reference = reference_path actual = actual_path

if !isinteractive() && !force_update()
error("""
To update the reference images either run the tests interactively with 'include(\"test/runtests.jl\")',
Expand All @@ -178,7 +171,7 @@ function test_reference(

if force_update() || input_bool("Replace reference with actual result?")
mv(actual_path, reference_path; force=true) # overwrite old file it
@info("Please run the tests again for any changes to take effect")
@info "Please run the tests again for any changes to take effect"
else
@test false
end
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ common example of such would be a custom `Base.show` method.
# Examples
```jldoctest
```julia-repl
julia> using ReferenceTests
julia> @io2str print(::IO, "Hello World")
Expand Down
Binary file modified test/references/heatmap.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 0 additions & 17 deletions test/references/lena.txt

This file was deleted.

Loading

0 comments on commit 895e4be

Please sign in to comment.