runtests.jl 1.79 KB
Newer Older
1
2
using COBREXA, Test

Sylvain Arreckx's avatar
Sylvain Arreckx committed
3
using Clp
Taneli Pusa's avatar
Taneli Pusa committed
4
using Distributed
5
using Downloads
6
7
using GLPK
using JSON
Laurent Heirendt's avatar
Laurent Heirendt committed
8
using JuMP
9
10
11
using LinearAlgebra
using MAT
using OrderedCollections
St. Elmo's avatar
St. Elmo committed
12
using OSQP
13
14
using SHA
using SparseArrays
St. Elmo's avatar
format    
St. Elmo committed
15
using Statistics
16
using Tulip
Sylvain Arreckx's avatar
Sylvain Arreckx committed
17

18
19
20
21
# tolerance for comparing analysis results (should be a bit bigger than the
# error tolerance in computations)
TEST_TOLERANCE = 10 * COBREXA._constants.tolerance

22
function run_test_file(path...)
23
24
25
    fn = joinpath(path...)
    t = @elapsed include(fn)
    @info "$(fn) done in $(round(t; digits = 2))s"
Sylvain Arreckx's avatar
Sylvain Arreckx committed
26
end
Sylvain Arreckx's avatar
Sylvain Arreckx committed
27

28
function run_test_dir(dir, comment = "Directory $dir/")
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
29
    @testset "$comment" begin
30
        run_test_file.(joinpath.(dir, filter(fn -> endswith(fn, ".jl"), readdir(dir))))
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
31
32
33
    end
end

34
function check_data_file_hash(path, expected_checksum)
35
36
37
38
39
40
    actual_checksum = bytes2hex(sha256(open(path)))
    if actual_checksum != expected_checksum
        @error "The downloaded data file `$path' seems to be different from the expected one. Tests will likely fail." actual_checksum expected_checksum
    end
end

41
function download_data_file(url, path, hash)
42
    if isfile(path)
43
        check_data_file_hash(path, hash)
44
        @info "using cached `$path'"
45
46
47
        return path
    end

48
    Downloads.download(url, path)
49
    check_data_file_hash(path, hash)
50
51
52
    return path
end

Sylvain Arreckx's avatar
Sylvain Arreckx committed
53
# load the test models
54
run_test_file("data", "test_models.jl")
Sylvain Arreckx's avatar
Sylvain Arreckx committed
55

Sylvain Arreckx's avatar
Sylvain Arreckx committed
56
# import base files
57
@testset "COBREXA test suite" begin
cylon-x's avatar
cylon-x committed
58
59
    run_test_dir(joinpath("base", "types", "abstract"), "Abstract types")
    run_test_dir(joinpath("base", "types"), "Base model types")
Miroslav Kratochvil's avatar
Miroslav Kratochvil committed
60
    run_test_dir(joinpath("base", "logging"), "Logging")
St. Elmo's avatar
St. Elmo committed
61
62
63
64
    run_test_dir("base", "Base functionality")
    run_test_dir("io", "I/O functions")
    run_test_dir("reconstruction")
    run_test_dir("analysis")
65
    run_test_dir(joinpath("analysis", "sampling"), "Sampling")
66
end