Skip to content

Commit 1ae249d

Browse files
committed
Add testet_name
1 parent 6925da1 commit 1ae249d

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/testers.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ at input point `z` to confirm that there are correct `frule` and `rrule`s provid
1212
- `fdm`: the finite differencing method to use.
1313
- `fkwargs` are passed to `f` as keyword arguments.
1414
- If `check_inferred=true`, then the inferrability (type-stability) of the `frule` and `rrule` are checked.
15+
- `testset_name`: if provided, the name of the testset used to wrap the tests.
1516
- All remaining keyword arguments are passed to `isapprox`.
1617
"""
17-
function test_scalar(f, z; rtol=1e-9, atol=1e-9, fdm=_fdm, fkwargs=NamedTuple(), check_inferred=true, kwargs...)
18+
function test_scalar(f, z; rtol=1e-9, atol=1e-9, fdm=_fdm, fkwargs=NamedTuple(), check_inferred=true, testset_name=nothing, kwargs...)
1819
# To simplify some of the calls we make later lets group the kwargs for reuse
1920
rule_test_kwargs = (; rtol=rtol, atol=atol, fdm=fdm, fkwargs=fkwargs, check_inferred=check_inferred, kwargs...)
2021
isapprox_kwargs = (; rtol=rtol, atol=atol, kwargs...)
22+
testset_name = isnothing(testset_name) ? "test_scalar: $f at $z" : testset_name
2123

22-
@testset "test_scalar: $f at $z" begin
24+
@testset "$(testset_name)" begin
2325
# z = x + im * y
2426
# Ω = u(x, y) + im * v(x, y)
2527
Ω = f(z; fkwargs...)
@@ -89,6 +91,7 @@ end
8991
- If `check_inferred=true`, then the inferrability (type-stability) of the `frule` is checked,
9092
as long as `f` is itself inferrable.
9193
- `fkwargs` are passed to `f` as keyword arguments.
94+
- `testset_name`: if provided, the name of the testset used to wrap the tests.
9295
- All remaining keyword arguments are passed to `isapprox`.
9396
"""
9497
function test_frule(args...; kwargs...)
@@ -106,15 +109,16 @@ function test_frule(
106109
fkwargs::NamedTuple=NamedTuple(),
107110
rtol::Real=1e-9,
108111
atol::Real=1e-9,
112+
testset_name=nothing,
109113
kwargs...,
110114
)
111115
# To simplify some of the calls we make later lets group the kwargs for reuse
112116
isapprox_kwargs = (; rtol=rtol, atol=atol, kwargs...)
113-
117+
testset_name = isnothing(testset_name) ? "test_frule: $f on $(_string_typeof(args))" : testset_name
114118
# and define a helper closure
115119
call_on_copy(f, xs...) = deepcopy(f)(deepcopy(xs)...; deepcopy(fkwargs)...)
116120

117-
@testset "test_frule: $f on $(_string_typeof(args))" begin
121+
@testset "$(testset_name)" begin
118122

119123
primals_and_tangents = auto_primal_and_tangent.((f, args...))
120124
primals = primal.(primals_and_tangents)
@@ -164,6 +168,7 @@ end
164168
- If `check_inferred=true`, then the inferrability (type-stability) of the `rrule` is checked
165169
— if `f` is itself inferrable — along with the inferrability of the pullback it returns.
166170
- `fkwargs` are passed to `f` as keyword arguments.
171+
- `testset_name`: if provided, the name of the testset used to wrap the tests.
167172
- All remaining keyword arguments are passed to `isapprox`.
168173
"""
169174
function test_rrule(args...; kwargs...)
@@ -182,11 +187,12 @@ function test_rrule(
182187
fkwargs::NamedTuple=NamedTuple(),
183188
rtol::Real=1e-9,
184189
atol::Real=1e-9,
190+
testset_name=nothing,
185191
kwargs...,
186192
)
187193
# To simplify some of the calls we make later lets group the kwargs for reuse
188194
isapprox_kwargs = (; rtol=rtol, atol=atol, kwargs...)
189-
195+
testset_name = isnothing(testset_name) ? "test_rrule: $f on $(_string_typeof(args))" : testset_name
190196
# and define helper closure over fkwargs
191197
call(f, xs...) = f(xs...; fkwargs...)
192198

0 commit comments

Comments
 (0)