Skip to content

Commit d81c785

Browse files
authored
Merge pull request #32 from bgctw/dev
SafeTestsets
2 parents 91cbb95 + c5f06c9 commit d81c785

File tree

8 files changed

+101
-53
lines changed

8 files changed

+101
-53
lines changed

.github/workflows/CI.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,14 @@ on:
77
pull_request:
88
jobs:
99
test:
10-
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
10+
name: ${{ matrix.group }} - Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
fail-fast: false
1414
matrix:
15+
group:
16+
- Basic
17+
- JET
1518
version:
1619
- '1.6'
1720
- '1'
@@ -20,7 +23,7 @@ jobs:
2023
arch:
2124
- x64
2225
steps:
23-
- uses: actions/checkout@v2
26+
- uses: actions/checkout@v4
2427
- uses: julia-actions/setup-julia@v1
2528
with:
2629
version: ${{ matrix.version }}
@@ -37,6 +40,8 @@ jobs:
3740
${{ runner.os }}-
3841
- uses: julia-actions/julia-buildpkg@v1
3942
- uses: julia-actions/julia-runtest@v1
43+
env:
44+
GROUP: ${{ matrix.group }}
4045
- uses: julia-actions/julia-processcoverage@v1
4146
- uses: codecov/codecov-action@v1
4247
with:
@@ -45,7 +50,7 @@ jobs:
4550
name: Documentation
4651
runs-on: ubuntu-latest
4752
steps:
48-
- uses: actions/checkout@v2
53+
- uses: actions/checkout@v4
4954
- uses: julia-actions/setup-julia@v1
5055
with:
5156
version: '1'

src/univariate/continuous/logitnormal.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# TODO: think of type piracy
2+
# this is not in Distributions (which owns LogitNormal) because of dependency on optimize
13
mean(d::LogitNormal{T}; kwargs...) where {T} = T(estimateMean(d, kwargs...))
24

35
function mode(d::LogitNormal{T}) where {T}

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
[deps]
2+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
23
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
34
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
45
LoggingExtras = "e6f89c97-d47a-5376-807f-9c37f3926c36"
56
Optim = "429524aa-4258-5aef-a3af-852621145aeb"
67
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
78
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
9+
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
810
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
911
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 22 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,26 @@
1-
using DistributionFits
2-
using Test
3-
using Random: Random
4-
using LoggingExtras
5-
6-
#using Aqua; Aqua.test_all(DistributionFits) # ambiguities from other packages
7-
#using JET; JET.report_package(DistributionFits) #
8-
#invalid possible error due to quantile may accept/return an Array (we pass a scalar)
9-
#only report problems in this module:
10-
#using JET; JET.report_package(DistributionFits; target_modules=(@__MODULE__,)) #
11-
12-
@testset "optimize error" begin
13-
@test_throws Exception DistributionFits.optimize(x -> x * x, -1, 1)
14-
end
15-
# Optim package for interactive testing
16-
i_loadlibs = () -> begin
17-
push!(LOAD_PATH, expanduser("~/julia/scimltools/")) # access local package repo
18-
push!(LOAD_PATH, expanduser("~/julia/18_tools/scimltools/")) # access local package repo
1+
tmpf = () -> begin
2+
push!(LOAD_PATH, expanduser("~/julia/devtools/")) # access local pack
3+
push!(LOAD_PATH, joinpath(pwd(), "test/")) # access local pack
194
end
20-
using Optim: Optim, optimize
215

22-
DistributionFitsOptimExt = isdefined(Base, :get_extension) ?
23-
Base.get_extension(DistributionFits, :DistributionFitsOptimExt) :
24-
DistributionFits.DistributionFitsOptimExt
25-
26-
@testset "optimize set in __init__ after using Optim" begin
27-
# set in __init__
28-
@test DistributionFits.df_optimizer isa DistributionFitsOptimExt.OptimOptimizer
6+
using Test, SafeTestsets
7+
const GROUP = get(ENV, "GROUP", "All") # defined in in CI.yml
8+
@show GROUP
9+
10+
@time begin
11+
if GROUP == "All" || GROUP == "Basic"
12+
#@safetestset "Tests" include("test/test_optim.jl")
13+
@time @safetestset "test_optim" include("test_optim.jl")
14+
#@safetestset "Tests" include("test/fitstats.jl")
15+
@time @safetestset "fitstats" include("fitstats.jl")
16+
#@safetestset "Tests" include("test/univariate/test_univariate.jl")
17+
@time @safetestset "test_univariate" include("univariate/test_univariate.jl")
18+
end
19+
if GROUP == "All" || GROUP == "JET"
20+
#@safetestset "Tests" include("test/test_JET.jl")
21+
@time @safetestset "test_JET" include("test_JET.jl")
22+
#@safetestset "Tests" include("test/test_aqua.jl")
23+
@time @safetestset "test_Aqua" include("test_aqua.jl")
24+
end
2925
end
3026

31-
#include("test/testutils.jl")
32-
include("testutils.jl")
33-
34-
#include("test/fitstats.jl")
35-
include("fitstats.jl")
36-
37-
#include("test/univariate/test_univariate.jl")
38-
include("univariate/test_univariate.jl")
39-
40-
# test coverage of set_optimize (already called in init)
41-
42-
# print method ambiguities
43-
println("Potentially stale exports: ")
44-
display(Test.detect_ambiguities(DistributionFits))
45-
println()
46-
47-
using JET: JET
48-
@testset "JET" begin
49-
@static if VERSION v"1.9.2"
50-
JET.test_package(DistributionFits; target_modules=(@__MODULE__,)) #
51-
end
52-
end;
53-

test/test_JET.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using DistributionFits
2+
using Test
3+
using JET: JET
4+
5+
@testset "JET" begin
6+
@static if VERSION v"1.9.2"
7+
JET.test_package(DistributionFits; target_modules = (@__MODULE__,))
8+
end
9+
end;
10+
# JET.report_package(DistributionFits) # to debug the errors
11+
# JET.report_package(DistributionFits; target_modules=(@__MODULE__,)) # to debug the errors

test/test_aqua.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using DistributionFits
2+
using Test
3+
using Aqua
4+
5+
@testset "DistributionFits.jl" begin
6+
@testset "Code quality (Aqua.jl)" begin
7+
Aqua.test_all(
8+
DistributionFits;
9+
#unbound_args = false, # does not recognize NamedTuple{K, NTuple{N,E}}
10+
stale_deps = (ignore = [:Requires],),
11+
ambiguities = false, # ambiguities in StatsBase
12+
piracies = false
13+
)
14+
end;
15+
@testset "ambiguities package" begin
16+
Aqua.test_ambiguities(DistributionFits;)
17+
end;
18+
@testset "pircacy" begin
19+
Aqua.test_piracies(DistributionFits;
20+
treat_as_own = [LogitNormal] # TODO
21+
)
22+
end;
23+
end

test/test_optim.jl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using DistributionFits
2+
using Test
3+
4+
# before loading Optim
5+
@testset "optimize error" begin
6+
@test_throws Exception DistributionFits.optimize(x -> x * x, -1, 1)
7+
end
8+
9+
# after loading Optim
10+
using Optim: Optim, optimize
11+
12+
DistributionFitsOptimExt = isdefined(Base, :get_extension) ?
13+
Base.get_extension(DistributionFits, :DistributionFitsOptimExt) :
14+
DistributionFits.DistributionFitsOptimExt
15+
16+
@testset "optimize set in __init__ after using Optim" begin
17+
# set in __init__
18+
@test DistributionFits.df_optimizer isa DistributionFitsOptimExt.OptimOptimizer
19+
end
20+
21+

test/univariate/test_univariate.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
using DistributionFits
2+
using Test
3+
using Random: Random
4+
using LoggingExtras
5+
using Optim
6+
7+
pkgdir = dirname(dirname(pathof(DistributionFits)))
8+
testdir = joinpath(pkgdir, "test")
9+
include(joinpath(testdir,"testutils.jl"))
10+
111
function test_univariate_fits(d, D = typeof(d))
212
@testset "fit moments" begin
313
if !occursin("fit(::Type{D}",
@@ -110,6 +120,7 @@ function test_univariate_fits(d, D = typeof(d))
110120
end
111121
end
112122

123+
113124
const tests = [
114125
"weibull",
115126
"normal",
@@ -124,6 +135,6 @@ const tests = [
124135
for t in tests
125136
@testset "Test $t" begin
126137
Random.seed!(345679)
127-
include("continuous/$t.jl")
138+
include(joinpath(testdir,"univariate","continuous","$t.jl"))
128139
end
129140
end

0 commit comments

Comments
 (0)