-
Notifications
You must be signed in to change notification settings - Fork 81
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
Adding Retest #1052
Adding Retest #1052
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,101 @@ | ||||||
module PowerSystemsTests | ||||||
|
||||||
import TerminalLoggers: TerminalLogger | ||||||
using ReTest | ||||||
using Logging | ||||||
using DataStructures | ||||||
using Dates | ||||||
using LinearAlgebra | ||||||
using PowerSystemCaseBuilder | ||||||
import TimeSeries | ||||||
import InteractiveUtils | ||||||
import JSON3 | ||||||
import PowerSystemCaseBuilder: PSYTestSystems | ||||||
import InfrastructureSystems | ||||||
const IS = InfrastructureSystems | ||||||
using PowerSystems | ||||||
import PowerSystems: PowerSystemTableData | ||||||
const PSY = PowerSystems | ||||||
const PSB = PowerSystemCaseBuilder | ||||||
|
||||||
import Aqua | ||||||
Aqua.test_unbound_args(PowerSystems) | ||||||
Aqua.test_undefined_exports(PowerSystems) | ||||||
Aqua.test_ambiguities(PowerSystems) | ||||||
Aqua.test_stale_deps(PowerSystems) | ||||||
Aqua.test_deps_compat(PowerSystems) | ||||||
|
||||||
const BASE_DIR = dirname(dirname(Base.find_package("PowerSystems"))) | ||||||
const DATA_DIR = PSB.DATA_DIR | ||||||
const TIME_SERIES_DIR = joinpath(DATA_DIR, "forecasts") | ||||||
const MATPOWER_DIR = joinpath(DATA_DIR, "matpower") | ||||||
const PSSE_RAW_DIR = joinpath(DATA_DIR, "psse_raw") | ||||||
const PSSE_DYR_DIR = joinpath(DATA_DIR, "psse_dyr") | ||||||
const PSSE_TEST_DIR = joinpath(DATA_DIR, "PSSE_test") | ||||||
const RTS_GMLC_DIR = joinpath(DATA_DIR, "RTS_GMLC") | ||||||
const TAMU_DIR = joinpath(DATA_DIR, "ACTIVSg2000") | ||||||
const DESCRIPTORS = joinpath(RTS_GMLC_DIR, "user_descriptors.yaml") | ||||||
const BAD_DATA = joinpath(DATA_DIR, "bad_data_for_tests") | ||||||
|
||||||
LOG_FILE = "power-systems.log" | ||||||
LOG_LEVELS = Dict( | ||||||
"Debug" => Logging.Debug, | ||||||
"Info" => Logging.Info, | ||||||
"Warn" => Logging.Warn, | ||||||
"Error" => Logging.Error, | ||||||
) | ||||||
|
||||||
include("common.jl") | ||||||
|
||||||
function get_logging_level_from_env(env_name::String, default) | ||||||
level = get(ENV, env_name, default) | ||||||
return IS.get_logging_level(level) | ||||||
end | ||||||
|
||||||
logger = global_logger() | ||||||
|
||||||
function run_tests(args...; kwargs...) | ||||||
logger = global_logger() | ||||||
try | ||||||
logging_config_filename = get(ENV, "SIENNA_LOGGING_CONFIG", nothing) | ||||||
if logging_config_filename !== nothing | ||||||
config = IS.LoggingConfiguration(logging_config_filename) | ||||||
else | ||||||
config = IS.LoggingConfiguration(; | ||||||
filename = LOG_FILE, | ||||||
file_level = get_logging_level_from_env("SIENNA_FILE_LOG_LEVEL", "Info"), | ||||||
console_level = get_logging_level_from_env( | ||||||
"SIENNA_CONSOLE_LOG_LEVEL", | ||||||
"Error", | ||||||
), | ||||||
) | ||||||
end | ||||||
console_logger = TerminalLogger(config.console_stream, config.console_level) | ||||||
|
||||||
IS.open_file_logger(config.filename, config.file_level) do file_logger | ||||||
levels = (Logging.Info, Logging.Warn, Logging.Error) | ||||||
multi_logger = | ||||||
IS.MultiLogger([console_logger, file_logger], IS.LogEventTracker(levels)) | ||||||
global_logger(multi_logger) | ||||||
|
||||||
if !isempty(config.group_levels) | ||||||
IS.set_group_levels!(multi_logger, config.group_levels) | ||||||
end | ||||||
|
||||||
@time retest(args...; kwargs...) | ||||||
@test length(IS.get_log_events(multi_logger.tracker, Logging.Error)) == 0 | ||||||
@info IS.report_log_summary(multi_logger) | ||||||
end | ||||||
finally | ||||||
# Guarantee that the global logger is reset. | ||||||
global_logger(logger) | ||||||
nothing | ||||||
end | ||||||
end | ||||||
|
||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tengis-nrl you should learn how to invoke the formatter set up in each Sienna repository so you can deal with these issues proactively. I can help you with that sometime if you need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about during the next time we meet? Thanks! |
||||||
export run_tests | ||||||
@show "hello0" | ||||||
end | ||||||
|
||||||
using .PowerSystemsTests | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,13 @@ | ||||||
using Revise | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copied from the IS PR: Seems like even if the best practice is to install Revise globally, if our tests are going to depend it we ought to have it in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove, we need to remove from IS too. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file is optional. Users don’t have to call it. I say leave it the way it is. The instructions should advise you to install TestEnv.jl and Revise.jl globally. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, that works for me |
||||||
|
||||||
# Copied from https://juliatesting.github.io/ReTest.jl/stable/#Working-with-Revise | ||||||
function recursive_includet(filename) | ||||||
already_included = copy(Revise.included_files) | ||||||
includet(filename) | ||||||
newly_included = setdiff(Revise.included_files, already_included) | ||||||
for (mod, file) in newly_included | ||||||
Revise.track(mod, file) | ||||||
end | ||||||
end | ||||||
|
||||||
recursive_includet("PowerSystemsTests.jl") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,135 +1,4 @@ | ||||||
using Test | ||||||
using Logging | ||||||
using DataStructures | ||||||
using Dates | ||||||
using LinearAlgebra | ||||||
using PowerSystemCaseBuilder | ||||||
import TimeSeries | ||||||
import InteractiveUtils | ||||||
import JSON3 | ||||||
import PowerSystemCaseBuilder: PSYTestSystems | ||||||
import InfrastructureSystems | ||||||
const IS = InfrastructureSystems | ||||||
using PowerSystems | ||||||
import PowerSystems: PowerSystemTableData | ||||||
const PSY = PowerSystems | ||||||
const PSB = PowerSystemCaseBuilder | ||||||
|
||||||
import Aqua | ||||||
Aqua.test_unbound_args(PowerSystems) | ||||||
Aqua.test_undefined_exports(PowerSystems) | ||||||
Aqua.test_ambiguities(PowerSystems) | ||||||
Aqua.test_stale_deps(PowerSystems) | ||||||
Aqua.test_deps_compat(PowerSystems) | ||||||
|
||||||
const BASE_DIR = dirname(dirname(Base.find_package("PowerSystems"))) | ||||||
const DATA_DIR = PSB.DATA_DIR | ||||||
const TIME_SERIES_DIR = joinpath(DATA_DIR, "forecasts") | ||||||
const MATPOWER_DIR = joinpath(DATA_DIR, "matpower") | ||||||
const PSSE_RAW_DIR = joinpath(DATA_DIR, "psse_raw") | ||||||
const PSSE_DYR_DIR = joinpath(DATA_DIR, "psse_dyr") | ||||||
const PSSE_TEST_DIR = joinpath(DATA_DIR, "PSSE_test") | ||||||
const RTS_GMLC_DIR = joinpath(DATA_DIR, "RTS_GMLC") | ||||||
const TAMU_DIR = joinpath(DATA_DIR, "ACTIVSg2000") | ||||||
const DESCRIPTORS = joinpath(RTS_GMLC_DIR, "user_descriptors.yaml") | ||||||
const BAD_DATA = joinpath(DATA_DIR, "bad_data_for_tests") | ||||||
|
||||||
LOG_FILE = "power-systems.log" | ||||||
LOG_LEVELS = Dict( | ||||||
"Debug" => Logging.Debug, | ||||||
"Info" => Logging.Info, | ||||||
"Warn" => Logging.Warn, | ||||||
"Error" => Logging.Error, | ||||||
) | ||||||
|
||||||
include("common.jl") | ||||||
|
||||||
""" | ||||||
Copied @includetests from https://github.com/ssfrr/TestSetExtensions.jl. | ||||||
Ideally, we could import and use TestSetExtensions. Its functionality was broken by changes | ||||||
in Julia v0.7. Refer to https://github.com/ssfrr/TestSetExtensions.jl/pull/7. | ||||||
""" | ||||||
|
||||||
""" | ||||||
Includes the given test files, given as a list without their ".jl" extensions. | ||||||
If none are given it will scan the directory of the calling file and include all | ||||||
the julia files. | ||||||
""" | ||||||
macro includetests(testarg...) | ||||||
if length(testarg) == 0 | ||||||
tests = [] | ||||||
elseif length(testarg) == 1 | ||||||
tests = testarg[1] | ||||||
else | ||||||
error("@includetests takes zero or one argument") | ||||||
end | ||||||
|
||||||
quote | ||||||
tests = $tests | ||||||
rootfile = @__FILE__ | ||||||
if length(tests) == 0 | ||||||
tests = readdir(dirname(rootfile)) | ||||||
tests = filter( | ||||||
f -> | ||||||
startswith(f, "test_") && endswith(f, ".jl") && f != basename(rootfile), | ||||||
tests, | ||||||
) | ||||||
else | ||||||
tests = map(f -> string(f, ".jl"), tests) | ||||||
end | ||||||
println() | ||||||
for test in tests | ||||||
print(splitext(test)[1], ": ") | ||||||
include(test) | ||||||
println() | ||||||
end | ||||||
end | ||||||
end | ||||||
|
||||||
function get_logging_level_from_env(env_name::String, default) | ||||||
level = get(ENV, env_name, default) | ||||||
return IS.get_logging_level(level) | ||||||
end | ||||||
|
||||||
function run_tests() | ||||||
logging_config_filename = get(ENV, "SIIP_LOGGING_CONFIG", nothing) | ||||||
if logging_config_filename !== nothing | ||||||
config = IS.LoggingConfiguration(logging_config_filename) | ||||||
else | ||||||
config = IS.LoggingConfiguration(; | ||||||
filename = LOG_FILE, | ||||||
file_level = get_logging_level_from_env("SIIP_FILE_LOG_LEVEL", "Info"), | ||||||
console_level = get_logging_level_from_env("SIIP_CONSOLE_LOG_LEVEL", "Error"), | ||||||
) | ||||||
end | ||||||
console_logger = ConsoleLogger(config.console_stream, config.console_level) | ||||||
|
||||||
IS.open_file_logger(config.filename, config.file_level) do file_logger | ||||||
levels = (Logging.Info, Logging.Warn, Logging.Error) | ||||||
multi_logger = | ||||||
IS.MultiLogger([console_logger, file_logger], IS.LogEventTracker(levels)) | ||||||
global_logger(multi_logger) | ||||||
|
||||||
if !isempty(config.group_levels) | ||||||
IS.set_group_levels!(multi_logger, config.group_levels) | ||||||
end | ||||||
|
||||||
# Testing Topological components of the schema | ||||||
@time @testset "Begin PowerSystems tests" begin | ||||||
@includetests ARGS | ||||||
end | ||||||
|
||||||
@test length(IS.get_log_events(multi_logger.tracker, Logging.Error)) == 0 | ||||||
@info IS.report_log_summary(multi_logger) | ||||||
end | ||||||
end | ||||||
|
||||||
logger = global_logger() | ||||||
|
||||||
try | ||||||
run_tests() | ||||||
finally | ||||||
# Guarantee that the global logger is reset. | ||||||
global_logger(logger) | ||||||
nothing | ||||||
end | ||||||
include("PowerSystemsTests.jl") | ||||||
run_tests() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [JuliaFormatter] reported by reviewdog 🐶
Suggested change
|
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.
Hi @GabrielKS, this file was added to use ReTest instead of the current testing package. There is a file called InfrastructureSystemsTests.jl in IS that has almost the same code as this one. @daniel-thom was wondering how we can avoid code duplication. Specifically, he asked "Is there a way to avoid that without making the ReTest.jl package a dependency of PSY? Keep in mind that there are dozens of Sienna packages that should use this test pattern." Any suggestion?
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.
Dan and I talked about this a while ago and the options I see are:
I don't think we're going to come up with anything that doesn't have some of those disadvantages. I might not fully appreciate the costs of maintaining a whole separate package, but option 3 looks the most attractive to me. We could also do something like this to remove the duplication of all our formatting scripts.
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.
For the time being we will keep 2. as the option since it also creates a headache to maintain package dependencies to do any of the others.