-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rework default_rendermode
and add tests for render
#66
base: jc/test
Are you sure you want to change the base?
Conversation
@@ -1,2 +1,2 @@ | |||
This is a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was used to check CRLF/LF difference, but given that #64 properly handles this test case, we no longer need it.
The new reference is automatically generated by rm -rf test/references
.
The previous `default_rendermode(format, data)` is problematic that the render pipeline is showing the original data instead of the encoded data. That said, `default_rendermode(::SHA256, img)` is wrongly set to `BeforeAfterFull` -- we shoud never print the whole image array.
cc9c3a9
to
2689c14
Compare
- REFERENCE ------------------- | ||
Gray{Normed{UInt8,8}}[Gray{N0f8}(0.0), Gray{N0f8}(0.102), Gray{N0f8}(0.2), Gray{N0f8}(0.298), Gray{N0f8}(0.4), Gray{N0f8}(0.502), Gray{N0f8}(0.6), Gray{N0f8}(0.698), Gray{N0f8}(0.8), Gray{N0f8}(0.902)] | ||
------------------------------- | ||
- ACTUAL ---------------------- | ||
Gray{Normed{UInt8,8}}[Gray{N0f8}(0.902), Gray{N0f8}(0.8), Gray{N0f8}(0.698), Gray{N0f8}(0.6), Gray{N0f8}(0.502), Gray{N0f8}(0.4), Gray{N0f8}(0.298), Gray{N0f8}(0.2), Gray{N0f8}(0.102), Gray{N0f8}(0.0)] | ||
------------------------------- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How each pixel is rendered may change from versions to versions, in that case, the test will fail, but we may just regenerate these.
7b0f356
to
b4347cc
Compare
It seems that images are not properly encoded by ImageInTerminal: I get different results in macOS and Ubuntu
function string_check(ref, actual) | ||
# a over-verbose collection of patterns that we want to ignore during test | ||
patterns = [ | ||
# Julia v1.6 | ||
"Normed{UInt8,8}" => "N0f8", | ||
r"Array{(\w+),2}" => s"Matrix{\1}", | ||
r"Array{(\w+),1}" => s"Vector{\1}", | ||
|
||
# https://github.com/JuliaGraphics/ColorTypes.jl/pull/206 | ||
# r"Gray{\w+}\(([\w\.]+)\)" => s"\1", | ||
# r"RGB{\w+}\(([\w\.,]+)\)" => s"RGB(\1)", | ||
] | ||
|
||
for p in patterns | ||
actual = replace(actual, p) | ||
ref = replace(ref, p) | ||
end | ||
|
||
# Julia v1.4 | ||
ref = join(map(strip, split(ref, "\n")), "\n") | ||
actual = join(map(strip, split(actual, "\n")), "\n") | ||
|
||
isequal(ref, actual) | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can make this the default equality checking function for AbstractArray{<:Number}
types. I'm not sure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't fully support nested parameters, but I think [^,]
is slightly better than \w
.
julia> occursin(r"Array{(\w+),1}", "Array{Base.TwicePrecision{Float32},1}")
false
julia> occursin(r"Array{([^,]+),1}", "Array{Base.TwicePrecision{Float32},1}")
true
Also, \b
may be helpful.
julia> replace("MyLittleArray{Float32,2}", r"Array{(\w+),2}" => s"Matrix{\1}")
"MyLittleMatrix{Float32}"
julia> replace("MyLittleArray{Float32,2}", r"\bArray{(\w+),2}" => s"Matrix{\1}")
"MyLittleArray{Float32,2}"
Of course, since the function is only for testing, my suggestion is not important. TBH, I don't really like modifying "reference"s. I prefer the approach by means of multiple references (#47)
function render_item(::BeforeAfterLimited, item) | ||
show(IOContext(stdout, :limit=>true, :displaysize=>(20,80)), "text/plain", item) | ||
println() | ||
render_item(mode::RenderMode, item) = render_item(stdout, mode, item) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we might not actually need this one anymore (or in the first place)
since render
takes care of making sure we alrways have a IO
arg
render_item(mode::RenderMode, item) = render_item(stdout, mode, item) |
end | ||
|
||
# We set the fallback as limited mode because it is not safe/efficient to fully render anything unless | ||
# * we have prior information that it is not long -- numbers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but if it is not long, then BeforeAfterLimitted
and BeforeAfter
will be the same
if rendermode === nothing | ||
rendermode = default_rendermode(F, raw_actual) | ||
end | ||
rendermode === nothing && (rendermode = default_rendermode(T)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just change line 97 to be:
rendermode = default_rendermode(T)
?
for (x, xname) in ( | ||
# (img1d_1, "img1d_1"), | ||
# (img1d_2, "img1d_2"), | ||
# (img1d_3, "img1d_3"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should leave a comment saying why these are commented out
|
||
end | ||
|
||
# `render_item` is repeatly called by `render` so we can skip it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# `render_item` is repeatly called by `render` so we can skip it | |
# `render_item` is an internal helper called by `render` so we don't test it directly |
using ReferenceTests: Diff, BeforeAfterFull, BeforeAfterImage, BeforeAfterLimited | ||
using ReferenceTests: render, render_item | ||
|
||
refdir = joinpath(refroot, "render") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refdir = joinpath(refroot, "render") | |
const refdir = joinpath(refroot, "render") |
""" | ||
default_rendermode(::DataFormat, actual) | ||
default_rendermode(actual) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It nolonger gets the actual
, only its type?
default_rendermode(actual) | |
default_rendermode(typeof(actual)) |
default_rendermode(::Type) = BeforeAfterLimited() | ||
default_rendermode(::Type{T}) where T<:Number = BeforeAfterFull() | ||
default_rendermode(::Type{T}) where T<:AbstractString = Diff() | ||
default_rendermode(::Type{T}) where T<:AbstractArray{<:AbstractString} = Diff() | ||
default_rendermode(::Type{T}) where T<:AbstractArray{<:Colorant} = BeforeAfterImage() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default_rendermode(::Type) = BeforeAfterLimited() | |
default_rendermode(::Type{T}) where T<:Number = BeforeAfterFull() | |
default_rendermode(::Type{T}) where T<:AbstractString = Diff() | |
default_rendermode(::Type{T}) where T<:AbstractArray{<:AbstractString} = Diff() | |
default_rendermode(::Type{T}) where T<:AbstractArray{<:Colorant} = BeforeAfterImage() | |
default_rendermode(::Type) = BeforeAfterLimited() | |
default_rendermode(::Type{<:Number}) = BeforeAfterFull() | |
default_rendermode(::Type{<:AbstractString}) = Diff() | |
default_rendermode(::Type{<:AbstractArray{<:AbstractString}}) = Diff() | |
default_rendermode(::Type{<:AbstractArray{<:Colorant}}) = BeforeAfterImage() |
This is a sub PR of #61
The previous
default_rendermode(format, data)
is problematic that the render pipeline is showing the original data instead of the encoded data.ReferenceTests.jl/src/test_reference.jl
Line 115 in 30aa43f
For example, setting
default_rendermode(::SHA256, img)
toBeforeAfterLimited
doesn't make much sense to me.