From 519fe286874930949fbc58ae416ac52b6db58f28 Mon Sep 17 00:00:00 2001 From: olivroy Date: Thu, 2 Jan 2025 12:57:55 -0500 Subject: [PATCH] usethis::use_testthat(3) --- DESCRIPTION | 2 +- tests/testthat.R | 9 +++++++++ tests/testthat/test-copy_labels.r | 2 -- tests/testthat/test-labelled.r | 16 ++++++++-------- tests/testthat/test-miscellanous.R | 2 -- tests/testthat/test-na_values.R | 2 -- tests/testthat/test-recode_if.r | 2 -- tests/testthat/test-tagged_na.r | 2 -- tests/testthat/test-to_labelled.r | 8 +++----- tests/testthat/test-update_with.r | 2 -- tests/testthat/test_lookfor.R | 2 -- 11 files changed, 21 insertions(+), 28 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index dd48c789..5fd8c44d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -35,7 +35,6 @@ Suggests: questionr, snakecase, utf8, - covr, spelling Enhances: memisc URL: https://larmarange.github.io/labelled/, https://github.com/larmarange/labelled @@ -45,3 +44,4 @@ LazyData: true RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) Language: en-US +Config/testthat/edition: 3 diff --git a/tests/testthat.R b/tests/testthat.R index 8f84c449..475e0d66 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,12 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(labelled) + test_check("labelled") diff --git a/tests/testthat/test-copy_labels.r b/tests/testthat/test-copy_labels.r index 906e181c..af55a78b 100644 --- a/tests/testthat/test-copy_labels.r +++ b/tests/testthat/test-copy_labels.r @@ -1,5 +1,3 @@ -context("Test copy_labels()") - test_that("copy_labels() copy variable / value labels and missing values", { x <- labelled( c(1, 1, 2), diff --git a/tests/testthat/test-labelled.r b/tests/testthat/test-labelled.r index a26d4f70..04243c8f 100644 --- a/tests/testthat/test-labelled.r +++ b/tests/testthat/test-labelled.r @@ -1,5 +1,3 @@ -context("Labelled") - # var_label -------------------------------------------------------------- test_that("var_label works properly", { @@ -484,14 +482,15 @@ test_that("sort_val_labels works properly", { x <- c(2, tagged_na("z"), 1, tagged_na("a")) val_labels(x) <- c(no = 2, refused = tagged_na("z"), yes = 1, dk = tagged_na("a")) - expect_equivalent( + expect_equal( sort_val_labels(x, according_to = "v") %>% val_labels() %>% format_tagged_na() %>% trimws(), - c("1", "2", "NA(a)", "NA(z)") + c("1", "2", "NA(a)", "NA(z)"), + ignore_attr = "names" ) - expect_equivalent( + expect_equal( sort_val_labels(x, according_to = "l") %>% val_labels() %>% names(), c("dk", "no", "refused", "yes") ) @@ -1160,12 +1159,13 @@ test_that("names_prefixed_by_values works properly", { c1 = c("[M] Male", "[F] Female"), c2 = c("[1] Yes", "[2] No") ) - expect_equivalent( + expect_equal( names_prefixed_by_values(val_labels(df)), - res_names_prefixed + res_names_prefixed, + ignore_attr = "names" ) - expect_true(is.null(names_prefixed_by_values(NULL))) + expect_null(names_prefixed_by_values(NULL)) }) test_that("null_action in var_label() works as expected", { diff --git a/tests/testthat/test-miscellanous.R b/tests/testthat/test-miscellanous.R index a93cd55b..2123f217 100644 --- a/tests/testthat/test-miscellanous.R +++ b/tests/testthat/test-miscellanous.R @@ -1,5 +1,3 @@ -context("miscellanous") - # is_prefixed ------------------------------------------------------------- test_that("error with non factor argument", { diff --git a/tests/testthat/test-na_values.R b/tests/testthat/test-na_values.R index db37e100..a6e14136 100644 --- a/tests/testthat/test-na_values.R +++ b/tests/testthat/test-na_values.R @@ -1,5 +1,3 @@ -context("na_values") - # na_values -------------------------------------------------------------------- test_that("na_values works with data.frame", { diff --git a/tests/testthat/test-recode_if.r b/tests/testthat/test-recode_if.r index 122e66ab..31f8c559 100644 --- a/tests/testthat/test-recode_if.r +++ b/tests/testthat/test-recode_if.r @@ -1,5 +1,3 @@ -context("Test recode_if()") - test_that("recode_if() works as expected", { x <- labelled(c(1, 2, 2, 9), c(yes = 1, no = 2)) y <- x %>% recode_if(x == 9, NA) diff --git a/tests/testthat/test-tagged_na.r b/tests/testthat/test-tagged_na.r index 9a5d2950..911d53d0 100644 --- a/tests/testthat/test-tagged_na.r +++ b/tests/testthat/test-tagged_na.r @@ -1,5 +1,3 @@ -context("Tests related to tagged NAs") - test_that("unique_tagged_na(), duplicated_tagged_na, order_tagged_na and sort_tagged_na work as expected", { # nolint x <- c(1, 2, tagged_na("a"), 1, tagged_na("z"), 2, tagged_na("a"), NA) diff --git a/tests/testthat/test-to_labelled.r b/tests/testthat/test-to_labelled.r index 2864b37e..80a21135 100644 --- a/tests/testthat/test-to_labelled.r +++ b/tests/testthat/test-to_labelled.r @@ -1,6 +1,3 @@ -context("Test to_labelled()") - - test_that("to_labelled.factor preserves variable label", { x <- factor(c(1, 1, 2)) var_label(x) <- "test" @@ -73,9 +70,10 @@ test_that("to_labelled.factor works with '[code] label' factors", { ) f <- to_factor(l, levels = "p") x <- f %>% to_labelled(labels = c("[1] yes" = 123, "[2] no" = 456)) - expect_equivalent( + expect_equal( unclass(x), - c(123, 123, 456, 456, NA, 456, 123, NA) + c(123, 123, 456, 456, NA, 456, 123, NA), + ignore_attr = "labels" ) # should not be applied if duplicates in code diff --git a/tests/testthat/test-update_with.r b/tests/testthat/test-update_with.r index 09bac17b..cb5bf13e 100644 --- a/tests/testthat/test-update_with.r +++ b/tests/testthat/test-update_with.r @@ -1,5 +1,3 @@ -context("Test update_*_with()") - test_that("update_variable_labels_with() works as expected", { df <- iris %>% set_variable_labels( diff --git a/tests/testthat/test_lookfor.R b/tests/testthat/test_lookfor.R index 3568111c..58052753 100644 --- a/tests/testthat/test_lookfor.R +++ b/tests/testthat/test_lookfor.R @@ -1,5 +1,3 @@ -context("Test look_for()") - test_that("look_for works correctly", { df <- data.frame( 1:3,