Skip to content

Commit

Permalink
Made tests directory-independent; added ordering for block output.
Browse files Browse the repository at this point in the history
Added simple file for precompiling system image.
  • Loading branch information
James.Hester committed Nov 11, 2021
1 parent 2b8e977 commit 43ac364
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 14 deletions.
3 changes: 3 additions & 0 deletions extra/precompile_routines.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Precompile everything needed
import CrystalInfoFramework
include(joinpath(pkgdir(CrystalInfoFramework),"test","runtests.jl"))
18 changes: 13 additions & 5 deletions src/cif_output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -846,18 +846,26 @@ show(io::IO,::MIME"text/cif",c::Cif) = begin
end
end

Base.show(io::IO,::MIME"text/cif",c::CifContainer) = begin
Base.show(io::IO,::MIME"text/cif",c::CifContainer;ordering=[]) = begin
write(io,"\n")
key_vals = setdiff(collect(keys(c)),get_loop_names(c)...)
for k in ordering
if k in key_vals
item = format_for_cif(first(c[k]))
write(io,"$k\t$item\n")
end
end
# now write out the rest
for k in key_vals
item = format_for_cif(first(c[k]))
write(io,"$k\t$item\n")
if !(k in ordering)
item = format_for_cif(first(c[k]))
write(io,"$k\t$item\n")
end
end

# now go through the loops
for one_loop in get_loop_names(c)
a_loop = get_loop(c,first(one_loop))
write(io,format_for_cif(a_loop))
write(io,format_for_cif(a_loop,order=Symbol.(ordering)))
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/dc_base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ using Test

# Test a plain CIF as data source

const cif_test_file = p"nick1.cif"
const multi_block_test_file = p"cif_img_1.7.11.dic"
const core_dic = p"cif_core.dic"
const cif_test_file = joinpath(@__PATH__,"nick1.cif")
const multi_block_test_file = joinpath(@__PATH__,"cif_img_1.7.11.dic")
const core_dic = joinpath(@__PATH__,"cif_core.dic")

prepare_files() = begin
c = Cif(cif_test_file)
Expand Down
8 changes: 4 additions & 4 deletions test/dictionaries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ end
@test "_atom_site.label" in get_keys_for_cat(t,"atom_site")
@test "_atom_site_moment_crystalaxis" in get_names_in_cat(t,"atom_site_moment",aliases=true)
# Test child names
t = DDLm_Dictionary(p"cif_core.dic")
t = DDLm_Dictionary(joinpath(@__PATH__,"cif_core.dic"))
@test lowercase(find_name(t,"atom_site","matrix_U")) == "_atom_site_aniso.matrix_u"
@test Set(get_keys_for_cat(t,"atom_site",aliases=true)) == Set(["_atom_site.label","_atom_site_label"])
@test length(get_linked_names_in_cat(t,"geom_bond")) == 2
Expand All @@ -44,7 +44,7 @@ end
end

@testset "Function-related tests for DDLm" begin
t = DDLm_Dictionary(p"cif_core.dic")
t = DDLm_Dictionary(joinpath(@__PATH__,"cif_core.dic"))
ff = get_dict_funcs(t)
@test ff[1] == "function"
@test "atomtype" in ff[2]
Expand Down Expand Up @@ -102,7 +102,7 @@ end
@test "revision" in get_objs_in_cat(t,"dictionary_history")
@test get_dic_name(t) == "mmcif_ddl.dic"
@test get_dic_namespace(t) == "ddl2"
t = DDL2_Dictionary("cif_img_1.7.11.dic")
t = DDL2_Dictionary(joinpath(@__PATH__,"cif_img_1.7.11.dic"))
@test list_aliases(t,"_diffrn_detector.details") == ["_diffrn_detector_details"]
@test length(intersect(list_aliases(t,"_diffrn_detector.details",include_self=true),
["_diffrn_detector_details","_diffrn_detector.details"])) == 2
Expand All @@ -124,7 +124,7 @@ end
new_t = DDLm_Dictionary(p"testout.dic")
@test t["_atom_site_moment.Cartn"][:definition][!,:update][] == new_t["_atom_site_moment.Cartn"][:definition][!,:update][]
#
t = DDL2_Dictionary(p"cif_img_1.7.11.dic")
t = DDL2_Dictionary(joinpath(@__PATH__,"cif_img_1.7.11.dic"))
testout = open("testout.dic","w")
show(testout,MIME("text/cif"),t)
close(testout)
Expand Down
4 changes: 2 additions & 2 deletions test/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@ end
end

@testset "Straight in and out" begin
@test begin show(stdout,MIME("text/cif"),Cif(p"nick1.cif"));true end
@test begin show(stdout,MIME("text/cif"),Cif(p"nick1.cif",native=true));true end
@test begin show(stdout,MIME("text/cif"),Cif(joinpath(@__PATH__,"nick1.cif")));true end
@test begin show(stdout,MIME("text/cif"),Cif(joinpath(@__PATH__,"nick1.cif"),native=true));true end
end

0 comments on commit 43ac364

Please sign in to comment.