Skip to content

Commit

Permalink
clean up testing console output (#169)
Browse files Browse the repository at this point in the history
* clean up testing console output
  • Loading branch information
eahenle authored Aug 7, 2022
1 parent ad44c29 commit b47aeb0
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 40 deletions.
5 changes: 3 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ FIGlet = "3064a664-84fe-4d92-92c7-ed492f3d8fae"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
Expand All @@ -35,7 +34,9 @@ julia = "1.6"

[extras]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Documenter"]
test = ["Test", "Documenter", "IOCapture", "Logging"]
16 changes: 8 additions & 8 deletions test/assert_p1_symmetry.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module symmetry_test

using Xtals
using Test
using IOCapture, Test, Xtals

# Test set for making sure simulations meet certain rules
# i.e. frameworks musts be in P1 symmetry to be used in GCMC or Henry
# coefficient test
@testset "P1 Symmetry Tests" begin
non_P1_framework = Crystal("symmetry_test_structure.cif", convert_to_p1=false)
# Test that an assertion is thrown when trying to replicate a non-P1
# structure
@test_throws ErrorException replicate(non_P1_framework, (2, 2, 2))
@test_throws ErrorException replicate(non_P1_framework, (1, 1, 1))

IOCapture.capture() do
non_P1_framework = Crystal("symmetry_test_structure.cif", convert_to_p1=false)
# Test that an assertion is thrown when trying to replicate a non-P1
# structure
@test_throws ErrorException replicate(non_P1_framework, (2, 2, 2))
@test_throws ErrorException replicate(non_P1_framework, (1, 1, 1))
end
end
end
15 changes: 11 additions & 4 deletions test/bonds.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Bonds_test

using Xtals, Graphs, Test, MetaGraphs, LinearAlgebra
import IOCapture.capture

irmof1 = Crystal("IRMOF-1.cif")
cof102 = Crystal("cof-102.cif")
Expand Down Expand Up @@ -147,7 +148,9 @@ end

@test length(rc[:bonding_rules]) == (n + 1)

println([r for r bonding_rules if :C == r.species_j][1])
capture() do
println([r for r bonding_rules if :C == r.species_j][1])
end

@test true

Expand All @@ -165,7 +168,9 @@ end
@testset "etc" begin
temp_vtk_path = tempname()
xtal = Crystal("SBMOF-1.cif")
write_bond_information(xtal, temp_vtk_path, center_at_origin=true)
capture() do
write_bond_information(xtal, temp_vtk_path, center_at_origin=true)
end

@test isfile(temp_vtk_path * ".vtk")

Expand All @@ -174,8 +179,10 @@ end
write_xyz(xtal, tempname())
all_bonds_temppath = tempname()
no_pb_temppath = tempname()
write_bond_information(xtal, all_bonds_temppath)
write_bond_information(xtal, no_pb_temppath, bond_filter=:cross_boundary=>p->!p)
capture() do
write_bond_information(xtal, all_bonds_temppath)
write_bond_information(xtal, no_pb_temppath, bond_filter=:cross_boundary=>p->!p)
end

@test all(isfile.([all_bonds_temppath, no_pb_temppath] .* ".vtk"))
end
Expand Down
13 changes: 8 additions & 5 deletions test/box.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module Box_Test

using Xtals
using LinearAlgebra
using Test
using LinearAlgebra, Test, Xtals
import IOCapture.capture

@testset "Box Tests" begin
box = Box(11.6, 5.5, 22.9, 90.0 * π / 180, 100.8 * π / 180.0, 90.0 * π / 180.0)
Expand Down Expand Up @@ -96,11 +95,15 @@ using Test

xtal = Crystal("SBMOF-1.cif")
vtk_temp = tempname() * ".vtk"
write_vtk(xtal.box, vtk_temp, verbose=true)
capture() do
write_vtk(xtal.box, vtk_temp, verbose=true)
end
@test isfile(vtk_temp)

# effective test of Base.show(io::IO, box::Box)
println(xtal.box)
capture() do
println(xtal.box)
end
@test true
end
end
11 changes: 5 additions & 6 deletions test/crystal.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
module Crystal_Test

using Xtals
using LinearAlgebra
using Test
using MetaGraphs, Graphs
using AtomsBase
using AtomsBase, Graphs, LinearAlgebra, MetaGraphs, Test, Xtals
import IOCapture.capture

# for test only
# if the multi sets are equal, then when you remove duplicates,
Expand Down Expand Up @@ -126,7 +123,9 @@ end
@test true

# test verbose printing in empirical_formula
empirical_formula(sbmof1, verbose=true)
capture() do
empirical_formula(sbmof1, verbose=true)
end
@test true ##! can this be redirected to a string variable for comparison (and to suppress CLI output during testing?)
end

Expand Down
5 changes: 4 additions & 1 deletion test/misc.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
module Misc_Test

using Xtals, Test, DataFrames, Graphs, CSV
import IOCapture.capture

@testset "Misc Tests" begin
xtal = Crystal("SBMOF-1.cif")
infer_bonds!(xtal, true)
@test_throws String view_crystal(xtal) # this function really can't be tested programmatically...
capture() do
@test_throws String view_crystal(xtal) # this function really can't be tested programmatically...
end

am = rc[:atomic_masses]
@test isapprox(am[:H], 1.00794, atol=0.001)
Expand Down
3 changes: 1 addition & 2 deletions test/paths.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module Path_Test

using Xtals
using Test
using IOCapture, Test, Xtals

@testset "Path Tests" begin
@test rc[:atomic_masses][:He] == 4.0026
Expand Down
26 changes: 14 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
testfiles = [
"crystal.jl",
"bonds.jl",
"misc.jl",
"matter.jl",
"distance.jl",
"box.jl",
"assert_p1_symmetry.jl",
"crystal.jl"
"bonds.jl"
"misc.jl"
"matter.jl"
"distance.jl"
"box.jl"
"assert_p1_symmetry.jl"
"paths.jl"
]

@assert VERSION.major == 1
@assert VERSION.minor 6
@assert (VERSION.major == 1) && (VERSION.minor 6) "Minimum Julia version not met."

using Documenter, IOCapture, Logging, Test, Xtals

using Test, Documenter, Xtals, Graphs, MetaGraphs
Xtals.banner()

for testfile testfiles
@info "Running test/$testfile"
@time include(testfile)
with_logger(NullLogger()) do
include(testfile)
end
end

# run doctests unless disabled via environment variable
if "doctest" keys(ENV) || ENV["doctest"] "false"
@time doctest(Xtals)
doctest(Xtals)
end

@info "Done."

0 comments on commit b47aeb0

Please sign in to comment.