tests/testthat/test-get.R

library("testthat")
library("tidywikidatar")
test_that("check if tw_get returns tibble with four columns and meaningful number of rows", {
  testthat::skip_if_offline()

  expect_true(object = {
    item <- tw_get(
      id = c(
        "Q180099"
      ),
      id_l = tw_test_items
    )

    if (is.null(attr(item, "warning")) == FALSE) {
      message("Issues with API in testing")
      test_result <- TRUE
    } else {
      test_result <- Reduce(
        f = `|`,
        x = c(
          ncol(item) == 4,
          nrow(item) > 100
        )
      )
    }
    test_result
  })
})



test_that("check if tw_get works when more than one id as input", {
  testthat::skip_if_offline()

  expect_true(object = {
    item <- tw_get(
      id = c(
        "Q180099",
        "Q228822"
      ),
      language = "en",
      id_l = tw_test_items
    )
    if (is.null(attr(item, "warning")) == FALSE) {
      message("Issues with API in testing")
      test_result <- TRUE
    } else {
      test_result <- Reduce(
        f = `|`,
        x = c(
          ncol(item) == 3,
          nrow(item) > 200
        ),
        length(unique(item$id) == 2)
      )
    }
    test_result
  })
})

Try the tidywikidatar package in your browser

Any scripts or data that you put into this service are public.

tidywikidatar documentation built on March 31, 2023, 9:08 p.m.