Skip to content

Commit

Permalink
tests for versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
louisponet committed Jun 9, 2021
1 parent 4ba9610 commit 8623d19
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/job.jl
Expand Up @@ -218,7 +218,7 @@ end
"Finds the input corresponding to the name and returns the full output path."
outpath(job::DFJob, n::String) = outpath(input(job,n))

Base.joinpath(job::DFJob, n::AbstractString) = joinpath(job.local_dir, n)
Base.joinpath(job::DFJob, args...) = joinpath(job.local_dir, args...)

runslocal_assert(job::DFJob) =
@assert runslocal(job) "This only works if the job runs on `localhost`."
Expand Down
20 changes: 9 additions & 11 deletions src/versioning.jl
Expand Up @@ -13,7 +13,7 @@ version(job::DFJob) = job.version

function last_job_version(dir::String)
versions = job_versions(dir)
return isempty(versions) ? 1 : versions[end]
return isempty(versions) ? 0 : versions[end]
end
last_version(job::DFJob) = last_job_version(job.local_dir)

Expand All @@ -26,15 +26,13 @@ function maybe_increment_version(job::DFJob)
versions_path = joinpath(job, VERSION_DIR_NAME)
if !ispath(versions_path)
mkpath(versions_path)
return
else
if ispath(joinpath(job, "job.tt"))
tjob = DFJob(job.local_dir, version = last_version(job)+1)
vpath = version_path(tjob)
mkpath(vpath)
cp(job, vpath)
job.version = last_version(job) + 1
end
end
if ispath(joinpath(job, "job.tt"))
tjob = DFJob(job.local_dir, version = last_version(job) + 1)
vpath = version_path(tjob)
mkpath(vpath)
cp(job, vpath)
job.version = last_version(job) + 1
end
end

Expand All @@ -52,7 +50,7 @@ function switch_version(job::DFJob, version)
maybe_increment_version(job)
out = DFJob(verpath)
curdir = job.local_dir
mv(out, job.local_dir)
mv(out, job.local_dir, force=true)
rm(verpath, recursive=true)
for f in fieldnames(DFJob)
setfield!(job, f, getfield(out,f))
Expand Down
26 changes: 26 additions & 0 deletions test/job_control_tests.jl
Expand Up @@ -310,8 +310,34 @@ set_dataoption!(job, :k_points, :test, print=false)
@test data(job, "scf", :k_points).option == :test

rm.(DFControl.inpath.(job.inputs))
job.inputs = [job.inputs[2]]
set_kpoints!(job["scf"],(6,6,6,1,1,1))
rm(joinpath(job, DFControl.VERSION_DIR_NAME), recursive=true)

@testset "versioning" begin
job[:nbnd] = 30
job.version = 1
save(job)
@test job.version == 2
@test ispath(joinpath(job, DFControl.VERSION_DIR_NAME))
@test ispath(joinpath(job, DFControl.VERSION_DIR_NAME, "1"))
job[:nbnd] = 40
save(job)
@test job.version == 3
@test job["scf"][:nbnd] == 40
switch_version(job, 2)
@test job.version == 2
@test !(2 versions(job))
@test DFControl.last_version(job) == 3
@test job["scf"][:nbnd] == 30
switch_version(job, 3)
@test !ispath(joinpath(job, DFControl.VERSION_DIR_NAME, "3"))
@test ispath(joinpath(job, DFControl.VERSION_DIR_NAME, "1"))
end

rm(joinpath(job, DFControl.VERSION_DIR_NAME), recursive=true)
rm.(DFControl.inpath.(job.inputs))

rm(joinpath(job, "job.tt"))
rm(joinpath(job, "pw2wan_wandn.in"))
rm(joinpath(job, "pw2wan_wanup.in"))
Expand Down

0 comments on commit 8623d19

Please sign in to comment.