Skip to content
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

Use dev version for examples when running tests #20

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release notes

## Unversioned

* Use dev version of EMRP for examples when running as part of tests, similar to [PR #33 of EMB](https://github.com/EnergyModelsX/EnergyModelsBase.jl/pull/33).

## Version 0.6.0 (2024-05-28)

* Adjusted to changes introduced in `EnergyModelsBase` v0.7.
Expand Down
36 changes: 20 additions & 16 deletions examples/simple_hydro_power.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Pkg
# Activate the local environment including EnergyModelsRenewableProducers, HiGHS, PrettyTables
Pkg.activate(@__DIR__)
# Use dev version if run as part of tests
haskey(ENV, "EMX_TEST") && Pkg.develop(path=joinpath(@__DIR__,".."))
# Install the dependencies.
Pkg.instantiate()

Expand Down Expand Up @@ -113,19 +115,21 @@ optimizer = optimizer_with_attributes(HiGHS.Optimizer, MOI.Silent() => true)
m = EMB.run_model(case, model, optimizer)

# Display some results
@info "Storage level of the hydro power plant"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:stor_level];
header = [:Node, :TimePeriod, :Level],
),
)
@info "Power production of the two power sources"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:flow_out][case[:nodes][2:3], :, case[:products][2]];
header = [:Node, :TimePeriod, :Production],
),
)
if !haskey(ENV, "EMX_TEST")
@info "Storage level of the hydro power plant"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:stor_level];
header = [:Node, :TimePeriod, :Level],
),
)
@info "Power production of the two power sources"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:flow_out][case[:nodes][2:3], :, case[:products][2]];
header = [:Node, :TimePeriod, :Production],
),
)
end
36 changes: 20 additions & 16 deletions examples/simple_nondisres.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Pkg
# Activate the local environment including EnergyModelsRenewableProducers, HiGHS, PrettyTables
Pkg.activate(@__DIR__)
# Use dev version if run as part of tests
haskey(ENV, "EMX_TEST") && Pkg.develop(path=joinpath(@__DIR__,".."))
# Install the dependencies.
Pkg.instantiate()

Expand Down Expand Up @@ -98,19 +100,21 @@ optimizer = optimizer_with_attributes(HiGHS.Optimizer, MOI.Silent() => true)
m = EMB.run_model(case, model, optimizer)

# Display some results
@info "Curtailment of the wind power source"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:curtailment];
header = [:Node, :TimePeriod, :Curtailment],
),
)
@info "Capacity usage of the power source"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:cap_use][case[:nodes][1],:];
header = [:TimePeriod, :Usage],
),
)
if !haskey(ENV, "EMX_TEST")
@info "Curtailment of the wind power source"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:curtailment];
header = [:Node, :TimePeriod, :Curtailment],
),
)
@info "Capacity usage of the power source"
pretty_table(
JuMP.Containers.rowtable(
value,
m[:cap_use][case[:nodes][1],:];
header = [:TimePeriod, :Usage],
),
)
end
13 changes: 5 additions & 8 deletions test/test_examples.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
ENV["EMX_TEST"] = true # Set flag for example scripts to check if they are run as part of the tests

@testset "Run examples" begin
exdir = joinpath(@__DIR__, "../examples")
files = first(walkdir(exdir))[3]
files = filter(endswith(".jl"), readdir(exdir))
for file ∈ files
if splitext(file)[2] == ".jl"
@testset "Example $file" begin
@info "Run example $file"
include(joinpath(exdir, file))

@test termination_status(m) == MOI.OPTIMAL
end
@testset "Example $file" begin
include(joinpath(exdir, file))
@test termination_status(m) == MOI.OPTIMAL
end
end
Pkg.activate(@__DIR__)
Expand Down
Loading