Skip to content

Commit

Permalink
Add a debug option to print name of test (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
odow authored Apr 12, 2021
1 parent 191eaab commit 1eb648f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 17 deletions.
65 changes: 51 additions & 14 deletions src/MINLPTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,43 @@ for directory in ["nlp", "nlp-cvx", "nlp-mi"]
end

"""
test_directory(directory, optimizer; exclude=String[], include=String[])
test_directory(
directory,
optimizer;
debug::Bool = false,
exclude = String[],
include = String[],
objective_tol = OPT_TOL,
primal_tol = PRIMAL_TOL,
dual_tol = DUAL_TOL,
termination_target = TERMINATION_TARGET_LOCAL,
primal_target = PRIMAL_TARGET_LOCAL,
)
Test all of the files in `directory` using `optimizer`.
If `debug`, print the name of the file befor running it.
Use `exclude` and `include` to run a subset of the files in a directory.
Use the remaining args to control tolerances and status targets.
## Example
### Example
Test all but nlp_001_010:
```julia
test_directory("nlp", optimizer; exclude = ["001_010"])
```
optimizer = JuMP.with_optimizer(Ipopt.Optimizer)
# Test all but nlp_001_010.
test_directory("nlp", optimizer; exclude = ["001_010"])
# Test only nlp_001_010.
test_directory("nlp", optimizer; include = ["001_010"])
Test only nlp_001_010:
```julia
test_directory("nlp", optimizer; include = ["001_010"])
```
"""
function test_directory(
directory,
optimizer;
debug::Bool = false,
exclude = String[],
include = String[],
objective_tol = OPT_TOL,
Expand All @@ -116,9 +140,11 @@ function test_directory(
)
@testset "$(directory)" begin
models = _list_of_models(directory, exclude, include)
dir = replace(directory, "-" => "_")
@testset "$(model_name)" for model_name in models
getfield(MINLPTests, Symbol("$(dir)_$(model_name)"))(
if debug
println("Running $(model_name)")
end
getfield(MINLPTests, model_name)(
optimizer,
objective_tol,
primal_tol,
Expand All @@ -135,15 +161,20 @@ function _list_of_models(
exclude::Vector{String},
include::Vector{String},
)
dir = replace(directory, "-" => "_")
if length(include) > 0
return include
return [Symbol("$(dir)_$(i)") for i in include]
else
models = String[]
models = Symbol[]
for file in readdir(joinpath(@__DIR__, directory))
!endswith(file, ".jl") && continue
if !endswith(file, ".jl")
continue
end
file = replace(file, ".jl" => "")
file in exclude && continue
push!(models, file)
if file in exclude
continue
end
push!(models, Symbol("$(dir)_$(file)"))
end
return models
end
Expand All @@ -155,6 +186,7 @@ end

function test_nlp(
optimizer;
debug::Bool = false,
exclude = String[],
objective_tol = OPT_TOL,
primal_tol = PRIMAL_TOL,
Expand All @@ -165,6 +197,7 @@ function test_nlp(
return test_directory(
"nlp",
optimizer;
debug = debug,
exclude = exclude,
objective_tol = objective_tol,
primal_tol = primal_tol,
Expand All @@ -176,6 +209,7 @@ end

function test_nlp_cvx(
optimizer;
debug::Bool = false,
exclude = String[],
objective_tol = OPT_TOL,
primal_tol = PRIMAL_TOL,
Expand All @@ -186,6 +220,7 @@ function test_nlp_cvx(
return test_directory(
"nlp-cvx",
optimizer;
debug = debug,
exclude = exclude,
objective_tol = objective_tol,
primal_tol = primal_tol,
Expand All @@ -197,6 +232,7 @@ end

function test_nlp_mi(
optimizer;
debug::Bool = false,
exclude = String[],
objective_tol = OPT_TOL,
primal_tol = PRIMAL_TOL,
Expand All @@ -207,6 +243,7 @@ function test_nlp_mi(
return test_directory(
"nlp-mi",
optimizer;
debug = debug,
exclude = exclude,
objective_tol = objective_tol,
primal_tol = primal_tol,
Expand Down
9 changes: 6 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ const MIPOLY_SOLVERS = [JUNIPER]

@testset "JuMP Model Tests" begin
@testset "$(solver): nlp" for solver in NLP_SOLVERS
MINLPTests.test_nlp(solver, exclude = [
"005_011", # Uses the function `\`
])
MINLPTests.test_nlp(
solver,
exclude = ["005_011"], # Uses the function `\`
debug = true,
)
MINLPTests.test_directory("nlp", solver, include = ["001_010"])
MINLPTests.test_nlp_cvx(solver)
end
@testset "$(solver): nlp_mi" for solver in MINLP_SOLVERS
Expand Down

2 comments on commit 1eb648f

@odow
Copy link
Member Author

@odow odow commented on 1eb648f Apr 12, 2021

Choose a reason for hiding this comment

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

@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/34067

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 the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.2 -m "<description of version>" 1eb648f43d491e2f00364e284a4438e358fd6bd9
git push origin v0.5.2

Please sign in to comment.