Skip to content

Commit 132a879

Browse files
Merge pull request #87 from ProjectTorreyPines/ind_tests
Individual testing without using ArgParse Now to run individual tests, one can use ``` julia --project test/test.jl help ``` to see the options. `test/runtests.jl` can not be called directly from outside now, it must be called through `Pkg.test()`. It directly uses `ARGS` now, so we do not need to use ArgParse anymore. `test/test.jl` uses Standard julia libraries only, so it can be called from project environment directly.
2 parents 7109406 + 56fe359 commit 132a879

File tree

5 files changed

+149
-51
lines changed

5 files changed

+149
-51
lines changed

Project.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
name = "IMASggd"
22
uuid = "b7b5e640-9b39-4803-84eb-376048795def"
33
authors = ["Anchal Gupta <[email protected]>"]
4-
version = "3.3.1"
4+
version = "3.3.2"
55

66
[deps]
7-
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
87
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
98
IMASdd = "c5a45a97-b3f9-491c-b9a7-aa88c3bc0067"
109
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
1110
NearestNeighbors = "b8a86587-4115-5ab1-83bc-aa920d37bbce"
1211
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
1312
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1413
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
15-
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
1614

1715
[compat]
18-
ArgParse = "1"
1916
ColorSchemes = "3"
2017
IMASdd = "2, 3, 4, 5, 6, 7"
2118
Interpolations = "0.15, 0.16"

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,56 @@ For installation:
1515
using Pkg
1616
Pkg.add("IMASggd")
1717
```
18+
19+
## For developers
20+
21+
If you are contributing to this project, you would need to install [dvc](https://dvc.org/) to fetch sample files for testing. Once installed, please configure your ssh so that you can ssh into omega tunneling through cybele without requiring to enter password. This is optional but will make it much easier for you.
22+
23+
Once you have completed above steps, inside the git repo, simply do:
24+
```bash
25+
dvc pull
26+
```
27+
28+
This would download the sample files in the `samples` directory. Then to run tests, you would first need to instantiate the project:
29+
```bash
30+
julia --project
31+
```
32+
Then press `]`:
33+
```julia
34+
_
35+
_ _ _(_)_ | Documentation: https://docs.julialang.org
36+
(_) | (_) (_) |
37+
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
38+
| | | | | | |/ _` | |
39+
| | |_| | | | (_| | | Version 1.11.5 (2025-04-14)
40+
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
41+
|__/ |
42+
43+
julia> ]
44+
```
45+
Then type:
46+
```julia
47+
(IMASggd) pkg> instantiate
48+
```
49+
Once the package has been instantiated, you can run the tests using:
50+
```julia
51+
(IMASggd) pkg> test
52+
```
53+
This would run all the tests though. To run specific tests, you can do following from the command line to see help options (this works after you ahve instantiated the project like mentioned above):
54+
```bash
55+
% julia --project test/test.jl help
56+
Usage (from inside IMASggd.jl):
57+
julia --project test/test.jl [interp] [projection] [in] [subset_tools] [types] [h] [help]
58+
59+
Run tests. Default is all tests.
60+
61+
Optional arguments:
62+
interp Test interp
63+
projection Test project_prop_on_subset!()
64+
in Test ∈
65+
subset_tools Test subset tools
66+
types Test types
67+
h Show this help message and exit
68+
help Show this help message and exit
69+
70+
```

test/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[deps]
2+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

test/runtests.jl

Lines changed: 11 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,18 @@
11
import IMASggd:
22
interp, get_kdtree, project_prop_on_subset!, get_grid_subset, get_grid_ggd,
3-
get_subset_boundary, subset_do, deepcopy_subset, get_TPS_mats, get_space
4-
using IMASdd: IMASdd
5-
import Statistics: mean
3+
get_subset_boundary, subset_do, deepcopy_subset, get_TPS_mats, get_space, IMASdd,
4+
mean
65
using Test
7-
using ArgParse: ArgParse
86

97
allowed_rtol = 1e-4
108

11-
function parse_commandline()
12-
s = ArgParse.ArgParseSettings(; description="Run tests. Default is all tests.")
13-
14-
ArgParse.add_arg_table!(s,
15-
["--interp"],
16-
Dict(:help => "Test interp",
17-
:action => :store_true),
18-
["--projection"],
19-
Dict(:help => "Test project_prop_on_subset!()",
20-
:action => :store_true),
21-
["--in"],
22-
Dict(:help => "Test ∈",
23-
:action => :store_true),
24-
["--interpeqt"],
25-
Dict(:help => "Test interpolation of equilibrium time slice",
26-
:action => :store_true),
27-
["--subset_tools"],
28-
Dict(:help => "Test subset tools",
29-
:action => :store_true),
30-
["--types"],
31-
Dict(:help => "Test types",
32-
:action => :store_true),
33-
)
34-
args = ArgParse.parse_args(s)
35-
if !any(values(args)) # If no flags are set, run all tests
36-
for k keys(args)
37-
args[k] = true
38-
end
39-
end
40-
return args
41-
end
42-
args = parse_commandline()
43-
449
print("json2imas() time: ")
4510
@time ids = IMASdd.json2imas(
4611
"$(@__DIR__)/../samples/time_dep_edge_profiles_last_step_only.json",
4712
)
4813

49-
if args["interp"]
14+
if isempty(ARGS) || "interp" in ARGS
5015
@testset "interp" begin
51-
# ids = h5i2imas("$(@__DIR__)/../samples/edge_profiles.h5")
5216
b2gmtry = "$(@__DIR__)/../samples/b2fgmtry"
5317
b2output = "$(@__DIR__)/../samples/b2time.nc"
5418
gsdesc = "$(@__DIR__)/../samples/gridspacedesc.yml"
@@ -156,8 +120,8 @@ if args["interp"]
156120
end
157121
end
158122

159-
if args["projection"]
160-
@testset "project_prop_on_subset!" begin
123+
if isempty(ARGS) || "projection" in ARGS
124+
@testset "Test project_prop_on_subset!" begin
161125
prop = ids.edge_profiles.ggd[1].electrons.density
162126
# All cells
163127
from_subset = get_grid_subset(ids.edge_profiles.grid_ggd[1], -5)
@@ -205,8 +169,8 @@ if args["projection"]
205169
end
206170
end
207171

208-
if args["subset_tools"]
209-
@testset "test subset_tools" begin
172+
if isempty(ARGS) || "subset_tools" in ARGS
173+
@testset "Test subset tools" begin
210174
grid_ggd = ids.edge_profiles.grid_ggd[1]
211175
space = grid_ggd.space[1]
212176

@@ -280,8 +244,8 @@ if args["subset_tools"]
280244
end
281245
end
282246

283-
if args["in"]
284-
@testset "test" begin
247+
if isempty(ARGS) || "in" in ARGS
248+
@testset "Test" begin
285249
grid_ggd = ids.edge_profiles.grid_ggd[1]
286250
space = grid_ggd.space[1]
287251
subset_corebnd = get_grid_subset(grid_ggd, 15)
@@ -297,8 +261,8 @@ if args["in"]
297261
end
298262
end
299263

300-
if args["types"]
301-
@testset "test types" begin
264+
if isempty(ARGS) || "types" in ARGS
265+
@testset "Test types" begin
302266
grid_ggd = ids.edge_profiles.grid_ggd[1]
303267
resize!(ids.radiation.grid_ggd, 1)
304268
ids.radiation.grid_ggd[1].path = "edge_profiles/grid_ggd(1)"

test/test.jl

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
2+
using Pkg
3+
using Printf
4+
5+
pkg_name = "IMASggd"
6+
7+
valid_arguments = [
8+
("interp", "Test interp"),
9+
("projection", "Test project_prop_on_subset!()"),
10+
("in", "Test ∈"),
11+
("subset_tools", "Test subset tools"),
12+
("types", "Test types"),
13+
("h", "Show this help message and exit"),
14+
("help", "Show this help message and exit"),
15+
]
16+
17+
function get_options_string(
18+
valid_arguments::Vector{Tuple{String, String}};
19+
indent::Int=4,
20+
)
21+
keys_arr = [k for (k, v) valid_arguments]
22+
values_arr = [v for (k, v) valid_arguments]
23+
24+
# Determine the maximum width of each column (keys and values)
25+
max_width_keys = maximum(length.(string.(keys_arr)))
26+
max_width_values = maximum(length.(string.(values_arr)))
27+
28+
# Create the format string with indentation
29+
format_str = repeat(" ", indent) * "%-$(max_width_keys)s %-$(max_width_values)s\n"
30+
31+
# Create a Format object
32+
fmt = Printf.Format(format_str)
33+
34+
# Build the combined string
35+
combined_string = ""
36+
for (key, value) valid_arguments
37+
combined_string *= Printf.format(fmt, string(key), string(value))
38+
end
39+
40+
return combined_string
41+
end
42+
43+
function check_args(
44+
args::Vector{String},
45+
valid_arguments::Vector{Tuple{String, String}},
46+
)
47+
valid_keys = Set(t[1] for t valid_arguments)
48+
49+
any_valid = false
50+
for arg args
51+
if arg in valid_keys
52+
any_valid = true
53+
else
54+
println("Error: Invalid argument found: \"", arg, "\"")
55+
println()
56+
return false
57+
end
58+
end
59+
60+
if !any_valid && !isempty(args)
61+
println("Error: No valid arguments found.")
62+
return false
63+
end
64+
return true
65+
end
66+
67+
usage_string = "Usage (from inside $(pkg_name).jl): \njulia --project test/test.jl "
68+
usage_string *= "[" * join([k for (k, v) valid_arguments], "] [") * "]\n\n"
69+
usage_string *= "Run tests. Default is all tests.\n\nOptional arguments:\n"
70+
usage_string *= get_options_string(valid_arguments)
71+
72+
if "h" in ARGS || "help" in ARGS || !check_args(ARGS, valid_arguments)
73+
println(usage_string)
74+
exit()
75+
end
76+
try
77+
Pkg.test("$(pkg_name)"; test_args=ARGS)
78+
catch e
79+
println("Error occured.")
80+
println(e)
81+
println(usage_string)
82+
end

0 commit comments

Comments
 (0)