Skip to content

Commit 266bee3

Browse files
committed
Update tests documentation and break down into smaller components
1 parent b73c9df commit 266bee3

14 files changed

+346
-68
lines changed

tests/testthat/test-audit_safe_people.R

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ test_that("rocrate method validates RO-Crate object", {
2222
expect_no_error(
2323
audit_safe_people(crate)
2424
)
25+
26+
# close connection to OBiBa's Opal demo server
27+
opalr::opal.logout(opal_con)
2528
})
2629

2730
test_that("rocrate method fails for invalid object", {
@@ -44,6 +47,9 @@ test_that("opal method returns RO-Crate with expected attributes", {
4447

4548
expect_equal(attr(crate, "audit_type"), "Safe People")
4649
expect_true("project" %in% names(attributes(crate)))
50+
51+
# close connection to OBiBa's Opal demo server
52+
opalr::opal.logout(opal_con)
4753
})
4854

4955
test_that("opal method works with specific project", {
@@ -61,6 +67,12 @@ test_that("opal method works with specific project", {
6167

6268
expect_s3_class(crate, "rocrate")
6369
expect_equal(attr(crate, "project"), attr(opal_con, "PROJECT"))
70+
71+
# close connection to OBiBa's Opal demo server
72+
opalr::opal.logout(opal_con)
73+
74+
# close connection to OBiBa's Opal demo server
75+
opalr::opal.logout(opal_con)
6476
})
6577

6678
test_that("opal method errors for unknown project", {
@@ -92,4 +104,7 @@ test_that("path argument is stored as attribute", {
92104
)
93105

94106
expect_equal(attr(crate, "path"), tempdir())
107+
108+
# close connection to OBiBa's Opal demo server
109+
opalr::opal.logout(opal_con)
95110
})

tests/testthat/test-audit_safe_project.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ test_that("opal method returns RO-Crate with expected attributes", {
4040

4141
expect_equal(attr(crate, "audit_type"), "Safe Project")
4242
expect_true("project" %in% names(attributes(crate)))
43+
44+
# close connection to OBiBa's Opal demo server
45+
opalr::opal.logout(opal_con)
4346
})
4447

4548
test_that("opal method works with specific project", {
@@ -56,6 +59,9 @@ test_that("opal method works with specific project", {
5659

5760
expect_s3_class(crate, "rocrate")
5861
expect_equal(attr(crate, "project"), attr(opal_con, "PROJECT"))
62+
63+
# close connection to OBiBa's Opal demo server
64+
opalr::opal.logout(opal_con)
5965
})
6066

6167
test_that("opal method errors for unknown project", {
@@ -67,6 +73,9 @@ test_that("opal method errors for unknown project", {
6773
"No data details were found",
6874
fixed = TRUE
6975
)
76+
77+
# close connection to OBiBa's Opal demo server
78+
opalr::opal.logout(opal_con)
7079
})
7180

7281
test_that("path argument is stored as attribute", {
@@ -82,4 +91,7 @@ test_that("path argument is stored as attribute", {
8291
)
8392

8493
expect_equal(attr(crate, "path"), tempdir())
94+
95+
# close connection to OBiBa's Opal demo server
96+
opalr::opal.logout(opal_con)
8597
})

tests/testthat/test-audit_study.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ test_that("list method returns list with expected attributes", {
3333
expect_equal(attr(crate, "audit_type"), "Study")
3434
expect_true("demo" %in% names(crate))
3535
expect_true(length(crate) == 1)
36+
37+
# close connection to OBiBa's Opal demo server
38+
opalr::opal.logout(opal_con)
3639
})
3740

3841
test_that("list method works with specific project", {
@@ -48,6 +51,9 @@ test_that("list method works with specific project", {
4851
)
4952

5053
expect_equal(attr(crate, "project"), attr(opal_con, "PROJECT"))
54+
55+
# close connection to OBiBa's Opal demo server
56+
opalr::opal.logout(opal_con)
5157
})
5258

5359
test_that("list method errors for unknown project", {
@@ -59,6 +65,9 @@ test_that("list method errors for unknown project", {
5965
"No data details were found",
6066
fixed = TRUE
6167
)
68+
69+
# close connection to OBiBa's Opal demo server
70+
opalr::opal.logout(opal_con)
6271
})
6372

6473
test_that("path argument is stored as attribute", {
@@ -74,4 +83,7 @@ test_that("path argument is stored as attribute", {
7483
)
7584

7685
expect_equal(attr(crate, "path"), tempdir())
86+
87+
# close connection to OBiBa's Opal demo server
88+
opalr::opal.logout(opal_con)
7789
})

tests/testthat/test-dsROCrate.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ test_that("init() dispatches to init.opal() with real Opal connection", {
1313

1414
expect_s3_class(res, "rocrate")
1515
expect_identical(attr(res, "connection"), opal_con)
16+
17+
# close connection to OBiBa's Opal demo server
18+
opalr::opal.logout(opal_con)
1619
})
1720

1821
test_that("init.opal() attaches metadata using demo Opal server", {
@@ -34,6 +37,9 @@ test_that("init.opal() attaches metadata using demo Opal server", {
3437
expect_identical(attr(res, "tables"), attr(opal_con, "TABLES"))
3538
expect_identical(attr(res, "user"), attr(opal_con, "PEOPLE"))
3639
expect_true(dir.exists(attr(res, "path")))
40+
41+
# close connection to OBiBa's Opal demo server
42+
opalr::opal.logout(opal_con)
3743
})
3844

3945
test_that("init.rocrate() reuses stored attributes with demo Opal server", {
@@ -54,6 +60,9 @@ test_that("init.rocrate() reuses stored attributes with demo Opal server", {
5460
expect_identical(attr(res, "tables"), attr(opal_con, "TABLES"))
5561
expect_identical(attr(res, "user"), attr(opal_con, "PEOPLE"))
5662
expect_identical(attr(res, "path"), attr(crate, "path"))
63+
64+
# close connection to OBiBa's Opal demo server
65+
opalr::opal.logout(opal_con)
5766
})
5867

5968
test_that("init.opal() errors on invalid connection object", {

tests/testthat/test-rocrate_report.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,9 @@ test_that("rocrate_report works end-to-end with real dsROCrate audit outputs", {
295295
expect_true("safe_people" %in% names(result))
296296
expect_true("safe_project" %in% names(result))
297297
expect_true("safe_data" %in% names(result))
298+
299+
# close connection to OBiBa's Opal demo server
300+
opalr::opal.logout(opal_con)
298301
})
299302

300303
test_that("rocrate_report.character loads crate from disk", {
@@ -331,6 +334,9 @@ test_that("rocrate_report.character loads crate from disk", {
331334
# ---- assertions ----
332335
expect_true(file.exists(out_file))
333336
expect_type(result, "list")
337+
338+
# close connection to OBiBa's Opal demo server
339+
opalr::opal.logout(opal_con)
334340
})
335341

336342
test_that("rocrate_report.list aggregates outputs from a study audit", {
@@ -365,6 +371,9 @@ test_that("rocrate_report.list aggregates outputs from a study audit", {
365371
# ---- assertions ----
366372
expect_true(file.exists(out_file))
367373
expect_type(result, "list")
374+
375+
# close connection to OBiBa's Opal demo server
376+
opalr::opal.logout(opal_con)
368377
})
369378

370379
test_that("rocrate_report.list handles missing outputs from a study audit", {

tests/testthat/test-safe-data.R

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,96 @@
1-
test_that("safe_data works", {
2-
# open connection to OBiBa's Opal demo server
3-
opal_con <- opal_demo_con()
4-
5-
basic_rocrate <- rocrateR::rocrate_5s()
6-
7-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
8-
# - - - - - - - - - - - - - - - - - ERRORS - - - - - - - - - - - - - - - - - #
9-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
10-
# attempt calling function with invalid class
1+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
2+
# - - - - - - - - - - - - - - - - - ERRORS - - - - - - - - - - - - - - - - - #
3+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
4+
test_that("safe_data fails when attempt calling function with invalid class", {
115
expect_error(
126
dsROCrate::safe_data(structure(list(), class = "InvalidClass"))
137
)
8+
})
9+
10+
test_that("safe_data fails when attempt calling with invalid connection", {
11+
# setup
12+
## create basic RO-Crate
13+
basic_rocrate <- rocrateR::rocrate_5s()
1414

15-
# attempt calling with invalid connection
1615
expect_error(
1716
basic_rocrate |>
1817
dsROCrate::safe_data(connection = NULL)
1918
)
19+
})
20+
21+
test_that("safe_data fails when attempt adding invalid project", {
22+
# setup
23+
## open connection to OBiBa's Opal demo server
24+
opal_con <- opal_demo_con()
25+
## create basic RO-Crate
26+
basic_rocrate <- rocrateR::rocrate_5s()
2027

21-
# attempt adding invalid project
2228
expect_error(
2329
basic_rocrate |>
2430
dsROCrate::safe_data(project = "Invalid Project", connection = opal_con)
2531
)
2632

27-
# attempt calling without a project
33+
# close connection to OBiBa's Opal demo server
34+
opalr::opal.logout(opal_con)
35+
})
36+
37+
test_that("safe_data fails when attempt calling without a project", {
38+
# setup
39+
## open connection to OBiBa's Opal demo server
40+
opal_con <- opal_demo_con()
41+
## create basic RO-Crate
42+
basic_rocrate <- rocrateR::rocrate_5s()
43+
2844
expect_error(
2945
basic_rocrate |>
3046
dsROCrate::safe_data(connection = opal_con)
3147
)
3248

33-
# attempt calling with project = NULL
49+
# close connection to OBiBa's Opal demo server
50+
opalr::opal.logout(opal_con)
51+
})
52+
53+
test_that("safe_data fails when attempt calling with project = NULL", {
54+
# setup
55+
## open connection to OBiBa's Opal demo server
56+
opal_con <- opal_demo_con()
57+
## create basic RO-Crate
58+
basic_rocrate <- rocrateR::rocrate_5s()
59+
3460
expect_error(
3561
basic_rocrate |>
3662
dsROCrate::safe_data(connection = opal_con, project = NULL)
3763
)
3864

39-
# attempt calling with multiple projects
65+
# close connection to OBiBa's Opal demo server
66+
opalr::opal.logout(opal_con)
67+
})
68+
69+
test_that("safe_data fails when attempt calling with multiple projects", {
70+
# setup
71+
## open connection to OBiBa's Opal demo server
72+
opal_con <- opal_demo_con()
73+
## create basic RO-Crate
74+
basic_rocrate <- rocrateR::rocrate_5s()
75+
4076
expect_error(
4177
basic_rocrate |>
4278
dsROCrate::safe_data(connection = opal_con, project = c("A", "B"))
4379
)
4480

45-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
46-
# - - - - - - - - - - - - - - - - - VALID - - - - - - - - - - - - - - - - - #
47-
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
81+
# close connection to OBiBa's Opal demo server
82+
opalr::opal.logout(opal_con)
83+
})
84+
85+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
86+
# - - - - - - - - - - - - - - - - - VALID - - - - - - - - - - - - - - - - - #
87+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
88+
test_that("safe_data works", {
89+
# open connection to OBiBa's Opal demo server
90+
opal_con <- opal_demo_con()
91+
92+
basic_rocrate <- rocrateR::rocrate_5s()
93+
4894
# add all datasets for a valid project
4995
basic_rocrate_2 <- basic_rocrate |>
5096
dsROCrate::safe_data(

tests/testthat/test-safe-people.R

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
test_that("safe_people works", {
2-
# open connection to OBiBa's Opal demo server
3-
opal_con <- opal_demo_con()
4-
5-
basic_rocrate <- rocrateR::rocrate_5s()
6-
7-
# attempt calling function with invalid class
1+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
2+
# - - - - - - - - - - - - - - - - - ERRORS - - - - - - - - - - - - - - - - - #
3+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
4+
test_that("safe_people fails when attempt calling function with invalid class", {
85
expect_error(
96
dsROCrate::safe_people(structure(list(), class = "InvalidClass"))
107
)
8+
})
9+
10+
test_that("safe_people fails when attempt adding user to RO-Crate without project entity, `@type = 'Project`", {
11+
# setup
12+
## open connection to OBiBa's Opal demo server
13+
opal_con <- opal_demo_con()
14+
## create basic RO-Crate
15+
basic_rocrate <- rocrateR::rocrate_5s()
1116

12-
# attempt adding user to RO-Crate without project entity, `@type = 'Project`
1317
expect_warning(
1418
basic_rocrate_1 <- opal_con |>
1519
dsROCrate::safe_people(
@@ -18,12 +22,36 @@ test_that("safe_people works", {
1822
)
1923
)
2024

21-
# attempt calling with invalid connection
25+
# close connection to OBiBa's Opal demo server
26+
opalr::opal.logout(opal_con)
27+
})
28+
29+
test_that("safe_people fails when attempt calling with invalid connection", {
30+
# setup
31+
## open connection to OBiBa's Opal demo server
32+
opal_con <- opal_demo_con()
33+
## create basic RO-Crate
34+
basic_rocrate <- rocrateR::rocrate_5s()
35+
2236
expect_error(
2337
basic_rocrate |>
2438
dsROCrate::safe_people(user = attr(opal_con, "PEOPLE"), connection = NULL)
2539
)
2640

41+
# close connection to OBiBa's Opal demo server
42+
opalr::opal.logout(opal_con)
43+
})
44+
45+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
46+
# - - - - - - - - - - - - - - - - - VALID - - - - - - - - - - - - - - - - - #
47+
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -#
48+
test_that("safe_people works", {
49+
# setup
50+
## open connection to OBiBa's Opal demo server
51+
opal_con <- opal_demo_con()
52+
## create basic RO-Crate
53+
basic_rocrate <- rocrateR::rocrate_5s()
54+
2755
# add project entity to the RO-Crate
2856
basic_rocrate_2 <- basic_rocrate |>
2957
rocrateR::add_entity(rocrateR::entity("Fake Project", type = "Project"))

0 commit comments

Comments
 (0)