From 74f65cd086fde456308fc365dcaf04f188dae57c Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Fri, 10 Jan 2025 18:01:08 -0800 Subject: [PATCH 1/7] 2579 Add test #11 test-derive_vars_query.R Calls assert_db_requirements() with no argumetns and expects error. --- tests/testthat/test-derive_vars_query.R | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/testthat/test-derive_vars_query.R b/tests/testthat/test-derive_vars_query.R index 5529d398bf..61d85d6dd4 100644 --- a/tests/testthat/test-derive_vars_query.R +++ b/tests/testthat/test-derive_vars_query.R @@ -347,4 +347,15 @@ test_that("assert_valid_queries Test 10: assert_valid_queries checks", { ), error = TRUE ) +} +) + +# assert_db_requirements ---- +## Test 11: assert_db_requirements_ +test_that("assert_db_requirements 11: assert_db_requirements checks", { + expect_error( + assert_db_requirements() + ) }) + + From 996b93135185fa07b4c8452dc8ee63cf4b789e0e Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Fri, 10 Jan 2025 18:07:13 -0800 Subject: [PATCH 2/7] fix styler --- tests/testthat/test-derive_vars_query.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/testthat/test-derive_vars_query.R b/tests/testthat/test-derive_vars_query.R index 61d85d6dd4..89c8291904 100644 --- a/tests/testthat/test-derive_vars_query.R +++ b/tests/testthat/test-derive_vars_query.R @@ -347,8 +347,7 @@ test_that("assert_valid_queries Test 10: assert_valid_queries checks", { ), error = TRUE ) -} -) +}) # assert_db_requirements ---- ## Test 11: assert_db_requirements_ @@ -357,5 +356,3 @@ test_that("assert_db_requirements 11: assert_db_requirements checks", { assert_db_requirements() ) }) - - From bbea72d26b118e24174bf26b1eca3bea26d6b694 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Sat, 11 Jan 2025 12:35:28 -0800 Subject: [PATCH 3/7] # 2579 Improve description for Test #11 assert_db_requirements --- tests/testthat/test-derive_vars_query.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_vars_query.R b/tests/testthat/test-derive_vars_query.R index 89c8291904..ee44afab7c 100644 --- a/tests/testthat/test-derive_vars_query.R +++ b/tests/testthat/test-derive_vars_query.R @@ -351,7 +351,7 @@ test_that("assert_valid_queries Test 10: assert_valid_queries checks", { # assert_db_requirements ---- ## Test 11: assert_db_requirements_ -test_that("assert_db_requirements 11: assert_db_requirements checks", { +test_that("assert_db_requirements 11: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided", { expect_error( assert_db_requirements() ) From c1938bfb383511bbd69a2fa43abeadaf96a478a7 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Sat, 11 Jan 2025 12:43:27 -0800 Subject: [PATCH 4/7] # 2579 Run lintr --- tests/testthat/test-derive_vars_query.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/testthat/test-derive_vars_query.R b/tests/testthat/test-derive_vars_query.R index ee44afab7c..e76de68675 100644 --- a/tests/testthat/test-derive_vars_query.R +++ b/tests/testthat/test-derive_vars_query.R @@ -351,7 +351,8 @@ test_that("assert_valid_queries Test 10: assert_valid_queries checks", { # assert_db_requirements ---- ## Test 11: assert_db_requirements_ -test_that("assert_db_requirements 11: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided", { +test_that("assert_db_requirements 11: assert_db_requirements() throws error and + increases code coverage when called with no `fun` arugment provided", { expect_error( assert_db_requirements() ) From 005df042b13d0ed6a08865ed96d0e872bc909916 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Sat, 11 Jan 2025 13:28:02 -0800 Subject: [PATCH 5/7] # 2579 Correction: When tests throw errors, capture the error with `expect_snapshot`, not `expect_error` --- tests/testthat/_snaps/derive_vars_query.md | 8 ++++++++ tests/testthat/test-derive_vars_query.R | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/testthat/_snaps/derive_vars_query.md b/tests/testthat/_snaps/derive_vars_query.md index 90cfb7f7f6..18996c3288 100644 --- a/tests/testthat/_snaps/derive_vars_query.md +++ b/tests/testthat/_snaps/derive_vars_query.md @@ -100,3 +100,11 @@ ! Queries dataset (`test`) contains duplicate records with respect to `PREFIX`, `GRPNAME`, `SRCVAR`, `TERMCHAR`, `GRPID`, and `TERMNUM` i Run `admiral::get_duplicates_dataset()` to access the duplicate records +# assert_db_requirements 11: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided + + Code + assert_db_requirements() + Condition + Error in `assert_db_requirements()`: + ! argument "fun" is missing, with no default + diff --git a/tests/testthat/test-derive_vars_query.R b/tests/testthat/test-derive_vars_query.R index e76de68675..5fce2778d2 100644 --- a/tests/testthat/test-derive_vars_query.R +++ b/tests/testthat/test-derive_vars_query.R @@ -353,7 +353,8 @@ test_that("assert_valid_queries Test 10: assert_valid_queries checks", { ## Test 11: assert_db_requirements_ test_that("assert_db_requirements 11: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided", { - expect_error( - assert_db_requirements() - ) + expect_snapshot( + assert_db_requirements(), + error = TRUE + ) }) From b11abf37c93105e0c3341bdd951675dd409ce0cb Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Sat, 11 Jan 2025 14:11:03 -0800 Subject: [PATCH 6/7] # 2579 add 2nd test for asset_db_requirements() to increase code coverage. --- tests/testthat/_snaps/create_query_data.md | 16 ++++++++++++++++ tests/testthat/_snaps/derive_vars_query.md | 8 -------- tests/testthat/test-create_query_data.R | 18 ++++++++++++++++++ tests/testthat/test-derive_vars_query.R | 10 ---------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/tests/testthat/_snaps/create_query_data.md b/tests/testthat/_snaps/create_query_data.md index 81ab3248c3..42168d0433 100644 --- a/tests/testthat/_snaps/create_query_data.md +++ b/tests/testthat/_snaps/create_query_data.md @@ -146,3 +146,19 @@ Error in `basket_select()`: ! argument "type" is missing, with no default +# assert_db_requirements 24: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided + + Code + assert_db_requirements(fun = NULL) + Condition + Error in `assert_db_requirements()`: + ! argument "queries" is missing, with no default + +# assert_db_requirements 25: assert_db_requirements() throws error and increases code coverage when called with no `queries` arugment provided + + Code + assert_db_requirements(fun = print, version = NULL) + Condition + Error in `assert_db_requirements()`: + ! argument "queries" is missing, with no default + diff --git a/tests/testthat/_snaps/derive_vars_query.md b/tests/testthat/_snaps/derive_vars_query.md index 18996c3288..90cfb7f7f6 100644 --- a/tests/testthat/_snaps/derive_vars_query.md +++ b/tests/testthat/_snaps/derive_vars_query.md @@ -100,11 +100,3 @@ ! Queries dataset (`test`) contains duplicate records with respect to `PREFIX`, `GRPNAME`, `SRCVAR`, `TERMCHAR`, `GRPID`, and `TERMNUM` i Run `admiral::get_duplicates_dataset()` to access the duplicate records -# assert_db_requirements 11: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided - - Code - assert_db_requirements() - Condition - Error in `assert_db_requirements()`: - ! argument "fun" is missing, with no default - diff --git a/tests/testthat/test-create_query_data.R b/tests/testthat/test-create_query_data.R index 5f9b5ec971..fc15ac6196 100644 --- a/tests/testthat/test-create_query_data.R +++ b/tests/testthat/test-create_query_data.R @@ -578,3 +578,21 @@ test_that("format.basket_select Test 23: formatting is correct (name specified)" "basket_select(name = \"My SDG\", id = NULL, scope = \"NA\", type = \"sdg\")" ) }) + +# assert_db_requirements ---- +## Test 24: assert_db_requirements_ +test_that("assert_db_requirements 24: assert_db_requirements() throws error and + increases code coverage when called with no `fun` arugment provided", { + expect_snapshot( + assert_db_requirements(fun = NULL), + error = TRUE + ) +}) +## Test 25: assert_db_requirements_ +test_that("assert_db_requirements 25: assert_db_requirements() throws error and + increases code coverage when called with no `queries` arugment provided", { + expect_snapshot( + assert_db_requirements(fun = print, version = NULL), + error = TRUE + ) +}) diff --git a/tests/testthat/test-derive_vars_query.R b/tests/testthat/test-derive_vars_query.R index 5fce2778d2..5529d398bf 100644 --- a/tests/testthat/test-derive_vars_query.R +++ b/tests/testthat/test-derive_vars_query.R @@ -348,13 +348,3 @@ test_that("assert_valid_queries Test 10: assert_valid_queries checks", { error = TRUE ) }) - -# assert_db_requirements ---- -## Test 11: assert_db_requirements_ -test_that("assert_db_requirements 11: assert_db_requirements() throws error and - increases code coverage when called with no `fun` arugment provided", { - expect_snapshot( - assert_db_requirements(), - error = TRUE - ) -}) From 60330dccd49c816fd3822364533a40d00180af30 Mon Sep 17 00:00:00 2001 From: jimrothstein Date: Sat, 11 Jan 2025 14:18:11 -0800 Subject: [PATCH 7/7] # 2579 run styler --- tests/testthat/test-create_query_data.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/testthat/test-create_query_data.R b/tests/testthat/test-create_query_data.R index fc15ac6196..0b47652250 100644 --- a/tests/testthat/test-create_query_data.R +++ b/tests/testthat/test-create_query_data.R @@ -583,16 +583,16 @@ test_that("format.basket_select Test 23: formatting is correct (name specified)" ## Test 24: assert_db_requirements_ test_that("assert_db_requirements 24: assert_db_requirements() throws error and increases code coverage when called with no `fun` arugment provided", { - expect_snapshot( - assert_db_requirements(fun = NULL), + expect_snapshot( + assert_db_requirements(fun = NULL), error = TRUE - ) + ) }) ## Test 25: assert_db_requirements_ test_that("assert_db_requirements 25: assert_db_requirements() throws error and increases code coverage when called with no `queries` arugment provided", { - expect_snapshot( - assert_db_requirements(fun = print, version = NULL), + expect_snapshot( + assert_db_requirements(fun = print, version = NULL), error = TRUE - ) + ) })