Skip to content

Commit

Permalink
usethis::use_testthat(3)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivroy committed Jan 2, 2025
1 parent 874c3ab commit 519fe28
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 28 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Suggests:
questionr,
snakecase,
utf8,
covr,
spelling
Enhances: memisc
URL: https://larmarange.github.io/labelled/, https://github.com/larmarange/labelled
Expand All @@ -45,3 +44,4 @@ LazyData: true
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Language: en-US
Config/testthat/edition: 3
9 changes: 9 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -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")
2 changes: 0 additions & 2 deletions tests/testthat/test-copy_labels.r
Original file line number Diff line number Diff line change
@@ -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),
Expand Down
16 changes: 8 additions & 8 deletions tests/testthat/test-labelled.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Labelled")

# var_label --------------------------------------------------------------

test_that("var_label works properly", {
Expand Down Expand Up @@ -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")
)
Expand Down Expand Up @@ -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", {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-miscellanous.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("miscellanous")

# is_prefixed -------------------------------------------------------------

test_that("error with non factor argument", {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-na_values.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("na_values")

# na_values --------------------------------------------------------------------

test_that("na_values works with data.frame", {
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-recode_if.r
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-tagged_na.r
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-to_labelled.r
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-update_with.r
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Test update_*_with()")

test_that("update_variable_labels_with() works as expected", {
df <- iris %>%
set_variable_labels(
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test_lookfor.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
context("Test look_for()")

test_that("look_for works correctly", {
df <- data.frame(
1:3,
Expand Down

0 comments on commit 519fe28

Please sign in to comment.