Skip to content
Snippets Groups Projects
Commit 51eb4aae authored by Florian Atteneder's avatar Florian Atteneder
Browse files

dg1d: make `main` accept paths to output directories...

dg1d: make `main` accept paths to output directories (!196)
parent 29cf7e97
No related branches found
No related tags found
1 merge request!196dg1d: make `main` accept paths to output directories
Pipeline #7110 passed
...@@ -19,16 +19,22 @@ function testparfiles() ...@@ -19,16 +19,22 @@ function testparfiles()
end end
function normalize_parfile(filename) function normalize_parfile(path::AbstractString)
filename = if isdir(path)
name = basename(path)
fname = joinpath(path, string(name, ".toml"))
else
path
end
if !isfile(filename) if !isfile(filename)
error("Cannot locate parameter file '$filename'") error("Cannot locate a parameter file at $path")
end end
return filename return filename
end end
function normalize_parfile(nr::Integer) function normalize_parfile(nr::Integer)
testpars = get_testparfiles() testpars = get_testparfiles()
if !(1 <= nr <= length(testpars)) if !(1 <= nr <= length(testpars))
error("there is no test parfile with nr $nr") error("There is no test parfile with nr $nr, see testparfiles() for available parfiles")
end end
parfile = testpars[nr] parfile = testpars[nr]
path = normpath(joinpath(@__DIR__, "..", "test", "IntegrationTests", "refs", parfile, "$parfile.toml")) path = normpath(joinpath(@__DIR__, "..", "test", "IntegrationTests", "refs", parfile, "$parfile.toml"))
...@@ -41,7 +47,7 @@ end ...@@ -41,7 +47,7 @@ end
Run program specified by a `parfile` in TOML format. Run program specified by a `parfile` in TOML format.
""" """
function main(parfile, parameter_overrides::Pair{String,String}...) function the_main(parfile::String, parameter_overrides::Pair{String,String}...)
parfile = abspath(parfile) parfile = abspath(parfile)
prms = TOML.parsefile(parfile) prms = TOML.parsefile(parfile)
...@@ -107,8 +113,9 @@ function main(parfile, parameter_overrides::Pair{String,String}...) ...@@ -107,8 +113,9 @@ function main(parfile, parameter_overrides::Pair{String,String}...)
return return
end end
main(id::Integer, parameter_overrides::Pair{String,String}...) =
main(normalize_parfile(id); parameter_overrides) main(p::Union{Integer,AbstractString}, parameter_overrides::Pair{String,String}...) =
the_main(normalize_parfile(p), parameter_overrides...)
load_parameters(parfile::AbstractString) = parse_parameters(TOML.parsefile(parfile)) load_parameters(parfile::AbstractString) = parse_parameters(TOML.parsefile(parfile))
......
...@@ -199,8 +199,6 @@ function make_outputdir(path) ...@@ -199,8 +199,6 @@ function make_outputdir(path)
lastext == "toml" || error("Only accept parameter files in .toml format, received '$path'") lastext == "toml" || error("Only accept parameter files in .toml format, received '$path'")
isfile(path) || error("Parameter file '$path' not found")
outputdirname = basename outputdirname = basename
if length(firstexts) > 0 if length(firstexts) > 0
outputdirname = "$basename.$(join(firstexts, '.'))" outputdirname = "$basename.$(join(firstexts, '.'))"
......
...@@ -347,7 +347,8 @@ end ...@@ -347,7 +347,8 @@ end
end end
nofilethere = joinpath(dir, "nofilethere.toml") nofilethere = joinpath(dir, "nofilethere.toml")
@test_throws ErrorException dg1d.make_outputdir(nofilethere) dg1d.make_outputdir(nofilethere)
@test isdir(first(splitext(nofilethere)))
wrongextensionfile = joinpath(dir, "wrongextension.toml.blabla") wrongextensionfile = joinpath(dir, "wrongextension.toml.blabla")
touch(wrongextensionfile) touch(wrongextensionfile)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment