Tests: make sure accessToken is NULL
Change-Id: I9cc4407cdeaf0a10e2b209f7604943f3a4a38bde
diff --git a/tests/testthat/test-corpusQuery.R b/tests/testthat/test-corpusQuery.R
index afd2c97..b5b73ee 100644
--- a/tests/testthat/test-corpusQuery.R
+++ b/tests/testthat/test-corpusQuery.R
@@ -263,7 +263,7 @@
# Test 10: Check that relative frequencies are between 0 and 1
expect_true(all(df1$f >= 0 & df1$f <= 1), info = "Relative frequencies should be between 0 and 1")
-
+
# Test with multiple VCs (this would fail before the ungroup() fix)
# This test ensures all rows get valid results, not just the first two
multiple_years <- c(1999, 2000, 2001, 2002)
@@ -271,10 +271,10 @@
query = c("macht", "ergibt", "ist", "wird"),
vc = paste("textType = /Zeit.*/ & pubDate in", multiple_years),
as.alternatives = TRUE)
-
+
# Test 11: All rows should have valid f values (this failed before the fix)
expect_true(all(!is.na(df3$f)), info = "All rows should have valid f values (not just first two)")
-
+
# Test 12: Each VC should have f=1.0 (since each query is in its own VC)
expect_true(all(abs(df3$f - 1.0) < 1e-10), info = "Each single query in its own VC should have f=1.0")
})
diff --git a/tests/testthat/test-corpusquery-eta.R b/tests/testthat/test-corpusquery-eta.R
index be73b1d..16352d8 100644
--- a/tests/testthat/test-corpusquery-eta.R
+++ b/tests/testthat/test-corpusquery-eta.R
@@ -1,6 +1,6 @@
test_that("corpusQuery displays ETA with multiple queries", {
- skip_if_offline() # Commented out for testing
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ skip_if_offline() # Commented out for testing
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
# Use simple queries to ensure they complete quickly
query <- c("Test", "der")
@@ -53,16 +53,17 @@
# Test 4: Check that we get results for all query combinations
# Note: with expand=TRUE (default), we should get length(query) * length(vc) results
expect_equal(nrow(result), length(query) * length(vc),
- info = paste("Should get results for all query/vc combinations. Got:", nrow(result), "Expected:", length(query) * length(vc)))
+ info = paste("Should get results for all query/vc combinations. Got:", nrow(result), "Expected:", length(query) * length(vc))
+ )
})
test_that("corpusQuery ETA works with frequencyQuery", {
- skip_if_offline() # Commented out for testing
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ skip_if_offline() # Commented out for testing
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
# Test the exact pattern from the user's example (but smaller)
query <- c("macht []{0,3} Sinn", "ergibt []{0,3} Sinn")
- years <- c(2020:2021) # Just 2 years for testing
+ years <- c(2020:2021) # Just 2 years for testing
as.alternatives <- TRUE
vc <- "textType = /Zeit.*/ & pubDate in"
@@ -105,18 +106,20 @@
# Test 3: Check that we get results
expect_true(nrow(result) > 0,
- info = "Should get frequency query results")
+ info = "Should get frequency query results"
+ )
# Test 4: Check that result has expected columns
expect_true(all(c("query", "vc", "totalResults") %in% names(result)),
- info = "Result should contain expected columns")
+ info = "Result should contain expected columns"
+ )
})
test_that("corpusQuery ETA only displays with verbose=TRUE and multiple queries", {
- skip_if_offline() # Commented out for testing
+ skip_if_offline() # Commented out for testing
# Test with verbose=FALSE - should not show ETA
- kco_quiet <- KorAPConnection(verbose = FALSE, cache = FALSE)
+ kco_quiet <- KorAPConnection(verbose = FALSE, cache = FALSE, accessToken = NULL)
query <- c("Test", "der")
vc <- c("pubDate in 2020", "pubDate in 2021")
@@ -135,14 +138,17 @@
# Should not contain ETA information when verbose=FALSE
expect_false(grepl("ETA:", output_str),
- info = "ETA should not be displayed when verbose=FALSE")
+ info = "ETA should not be displayed when verbose=FALSE"
+ )
# Test with single query - should not show ETA even with verbose=TRUE
- kco_verbose <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ kco_verbose <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
temp_file2 <- tempfile()
sink(temp_file2)
- result2 <- corpusQuery(kco_verbose, query = "Test", vc = "pubDate in 2020",
- metadataOnly = TRUE, as.df = TRUE)
+ result2 <- corpusQuery(kco_verbose,
+ query = "Test", vc = "pubDate in 2020",
+ metadataOnly = TRUE, as.df = TRUE
+ )
cat("\n")
sink()
@@ -154,14 +160,15 @@
# Should not contain ETA for single query
expect_false(grepl("ETA:", output_str2),
- info = "ETA should not be displayed for single queries")
+ info = "ETA should not be displayed for single queries"
+ )
})
test_that("corpusQuery ETA format_duration function works correctly", {
# This tests the internal format_duration function indirectly
# by checking that ETA displays reasonable time formats
- skip_if_offline() # Commented out for testing
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ skip_if_offline() # Commented out for testing
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
# Use multiple queries to trigger ETA display
query <- c("Test", "der", "und")
diff --git a/tests/testthat/test-fetch.R b/tests/testthat/test-fetch.R
index 33d18f9..f374f46 100644
--- a/tests/testthat/test-fetch.R
+++ b/tests/testthat/test-fetch.R
@@ -1,6 +1,6 @@
test_that("fetchNext works with maxFetch", {
skip_if_offline()
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
q <- kco %>% corpusQuery("Test", "pubDate since 2014", fields = c("sigle"))
q <- fetchNext(q, maxFetch = 75)
expect_equal(nrow(q@collectedMatches), 75)
@@ -11,7 +11,7 @@
test_that("fetchNext works with randomizePageOrder", {
skip_if_offline()
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
q <- kco %>% corpusQuery("Test", "pubDate since 2014", fields = c("sigle"))
q <- fetchNext(q, maxFetch = 175, randomizePageOrder = T)
expect_equal(nrow(q@collectedMatches), 175)
@@ -19,4 +19,3 @@
q <- fetchNext(q, maxFetch = 50, randomizePageOrder = T)
expect_equal(nrow(q@collectedMatches), 225)
})
-
diff --git a/tests/testthat/test-page-numbering.R b/tests/testthat/test-page-numbering.R
index 9e2b8ec..a75dba4 100644
--- a/tests/testthat/test-page-numbering.R
+++ b/tests/testthat/test-page-numbering.R
@@ -2,7 +2,7 @@
test_that("page numbering is displayed correctly in sequential mode", {
skip_if_offline()
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
q <- kco %>% corpusQuery("Test", "pubDate since 2014", fields = c("sigle"))
# Capture output - we need to use sink to capture the actual console output
@@ -47,7 +47,7 @@
test_that("page numbering and ETA are displayed correctly in randomized mode", {
skip_if_offline()
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
q <- kco %>% corpusQuery("Test", "pubDate since 2014", fields = c("sigle"))
# Set a fixed seed for reproducible tests
@@ -95,7 +95,7 @@
test_that("page numbering and ETA are displayed correctly in subsequent calls with randomized mode", {
skip_if_offline()
- kco <- KorAPConnection(verbose = TRUE, cache = FALSE)
+ kco <- KorAPConnection(verbose = TRUE, cache = FALSE, accessToken = NULL)
q <- kco %>% corpusQuery("Test", "pubDate since 2014", fields = c("sigle"))
# Set a fixed seed for reproducible tests