From a3ceb7ae9995817ddbf38a847b0d4b3307af9b34 Mon Sep 17 00:00:00 2001 From: aleksanderbl29 <73799306+aleksanderbl29@users.noreply.github.com> Date: Thu, 28 Nov 2024 12:07:40 +0100 Subject: [PATCH] Upgrade tests to 3 edition --- DESCRIPTION | 2 ++ tests/testthat/test-dst_date_parse.R | 26 ++++++++++++-------------- tests/testthat/test-dst_get_data.R | 19 ++++++++----------- tests/testthat/test-dst_get_tables.R | 9 +++------ tests/testthat/test-dst_query_match.R | 8 ++------ tests/testthat/test-dst_value_limit.R | 5 ----- 6 files changed, 27 insertions(+), 42 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ac86d4b..ff610f2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -25,6 +25,8 @@ Suggests: testthat Encoding: UTF-8 Roxygen: list(markdown = TRUE) +Config/testthat/edition: 3 +Config/testthat/parallel: true RoxygenNote: 7.3.2 X-schema.org-isPartOf: http://ropengov.org/ X-schema.org-keywords: ropengov diff --git a/tests/testthat/test-dst_date_parse.R b/tests/testthat/test-dst_date_parse.R index ad8ab61..3fc007c 100644 --- a/tests/testthat/test-dst_date_parse.R +++ b/tests/testthat/test-dst_date_parse.R @@ -1,51 +1,49 @@ -context("dst_date_parse") - test_that("dst_date_parse gives the correct class.", { - + exp_dates <- c("POSIXct", "POSIXt") - + # Daily expect_equal(class(dst_date_parse(dst_date = "2000M01D01")), exp_dates) expect_equal(class(dst_date_parse(dst_date = c("2000M01D20", "2000M02D21", "2000M03D23", "2000M04D24"))), exp_dates) - + # Monthly expect_equal(class(dst_date_parse(dst_date = "2000M01")), exp_dates) expect_equal(class(dst_date_parse(dst_date = c("2000M01", "2000M02", "2000M03", "2000M04", "2000M10", "2000M11"))), exp_dates) - + # Quarterly expect_equal(class(dst_date_parse(dst_date = "2000Q1")), exp_dates) expect_equal(class(dst_date_parse(dst_date = "2000Q2")), exp_dates) expect_equal(class(dst_date_parse(dst_date = "2000Q3")), exp_dates) expect_equal(class(dst_date_parse(dst_date = "2000Q4")), exp_dates) expect_equal(class(dst_date_parse(dst_date = c("2000Q1", "2000Q2", "2000Q3", "2000Q4"))), exp_dates) - + # Yearly expect_equal(class(dst_date_parse(dst_date = "2000")), exp_dates) expect_equal(class(dst_date_parse(dst_date = c("2000", "2000", "2000", "2000"))), exp_dates) - + expect_equal(class(dst_date_parse(dst_date = c("2015H1", "2015H2"))), exp_dates) expect_equal(as.character(dst_date_parse(dst_date = c("2015H1", "2015H2"))), c("2015-01-01", "2015-07-01")) - + }) test_that("Test that dst_date_parse stops when the input is bad.", { - + # Daily expect_error(dst_date_parse(dst_date = "2000M01D35")) expect_error(dst_date_parse(dst_date = "2000M10D40")) - + # Monthly expect_error(dst_date_parse(dst_date = "20000M01")) expect_error(dst_date_parse(dst_date = "2000M101")) expect_error(dst_date_parse(dst_date = "2000M13")) - + # Quarterly expect_error(dst_date_parse(dst_date = "2000Q0")) expect_error(dst_date_parse(dst_date = "2000Q5")) - + # Yearly expect_error(dst_date_parse(dst_date = "20000")) expect_error(dst_date_parse(dst_date = "200")) - + }) diff --git a/tests/testthat/test-dst_get_data.R b/tests/testthat/test-dst_get_data.R index 57eea63..01e62d0 100644 --- a/tests/testthat/test-dst_get_data.R +++ b/tests/testthat/test-dst_get_data.R @@ -1,28 +1,25 @@ - -context("dst_get_data") - test_that("dst_get_data returns an error when the limit is reached.", { - + expect_error(dst_get_data(table = "folk1", - query = list(CIVILSTAND = "*", - STATSB = "*", + query = list(CIVILSTAND = "*", + STATSB = "*", HERKOMST = c("Personer med dansk oprindelse", "Efterkommere"), TID = "*", ALDER = "*"), lang = "da")) - + }) test_that("dst_get_data is parsing the data correctly when 'en' and 'da' are selected as language. The API returns decimal numbers with both , and .", { - + expect_equal(class(dst_get_data("AUP01", ALDER = "*", TID = "*", lang = "da", format = "CSV")$value), "numeric") - + }) test_that("dst_get_data fails with the BULK format when not all parameters have values.", { - + expect_error(dst_get_data("AUP01", ALDER = "*", TID = "*", lang = "da", format = "BULK")) - + }) diff --git a/tests/testthat/test-dst_get_tables.R b/tests/testthat/test-dst_get_tables.R index 0802a67..1d4eca6 100644 --- a/tests/testthat/test-dst_get_tables.R +++ b/tests/testthat/test-dst_get_tables.R @@ -1,15 +1,12 @@ - -context("dst_get_tables") - test_that("dst_get_tables return a data.frame",{ - + expect_equal(class(dst_get_tables(lang = "da")), "data.frame") expect_equal(class(dst_get_tables(lang = "en")), "data.frame") - + }) test_that("dst_get_tables failes with wrong language input",{ - + expect_error(dst_get_tables(lang = "uk")) expect_error(dst_get_tables(lang = "no")) }) diff --git a/tests/testthat/test-dst_query_match.R b/tests/testthat/test-dst_query_match.R index 9d9d931..4a98011 100644 --- a/tests/testthat/test-dst_query_match.R +++ b/tests/testthat/test-dst_query_match.R @@ -1,8 +1,4 @@ - - -context("dst_query_match") - test_that("The function fails when mandatory values are not supplied.",{ - + expect_error(dst_query_match(table = "NRHP", meta_data = NULL, lang = "en", query = list(TRANSAKT = "P.1 Output", Tid = "1993"))) -}) \ No newline at end of file +}) diff --git a/tests/testthat/test-dst_value_limit.R b/tests/testthat/test-dst_value_limit.R index ea5f9f5..d34e9e7 100644 --- a/tests/testthat/test-dst_value_limit.R +++ b/tests/testthat/test-dst_value_limit.R @@ -1,8 +1,3 @@ - - - -context("dst_value_limit") - test_that("dst_value_limit returns the correct value.", { expect_equal(dst_value_limit(query = list(CIVILSTAND = "*",