tests/testthat/test_micro_yield.R

test_that("basic yield reading - long .dat.gz rect matches chunked", {
  cps_yield_source <- read_ipums_micro_yield(
    ipums_example("cps_00157.xml"),
    data_file = ipums_example("cps_00157.dat.gz"),
    verbose = FALSE
  )

  cps_yield <- list()
  while (!cps_yield_source$is_done()) {
    cps_yield[[length(cps_yield) + 1]] <- cps_yield_source$yield(1000)
  }

  cps_chunked <- read_ipums_micro_chunked(
    ipums_example("cps_00157.xml"),
    IpumsListCallback$new(function(x, ...) x),
    1000,
    data_file = ipums_example("cps_00157.dat.gz"),
    verbose = FALSE
  )

  expect_equal(cps_yield, cps_chunked)
})

test_that("basic yield reading - long .dat.gz hier matches chunked", {
  cps_yield_source <- read_ipums_micro_yield(
    ipums_example("cps_00159.xml"),
    data_file = ipums_example("cps_00159.dat.gz"),
    verbose = FALSE
  )

  cps_yield <- list()
  while (!cps_yield_source$is_done()) {
    cps_yield[[length(cps_yield) + 1]] <- cps_yield_source$yield(1000)
  }

  cps_chunked <- read_ipums_micro_chunked(
    ipums_example("cps_00159.xml"),
    IpumsListCallback$new(function(x, ...) x),
    1000,
    data_file = ipums_example("cps_00159.dat.gz"),
    verbose = FALSE
  )

  expect_equal(cps_yield, cps_chunked)
})

test_that("basic yield reading - list .dat.gz hier matches chunked", {
  cps_yield_source <- read_ipums_micro_list_yield(
    ipums_example("cps_00159.xml"),
    data_file = ipums_example("cps_00159.dat.gz"),
    verbose = FALSE
  )

  cps_yield <- list()
  while (!cps_yield_source$is_done()) {
    cps_yield[[length(cps_yield) + 1]] <- cps_yield_source$yield(1000)
  }

  cps_chunked <- read_ipums_micro_list_chunked(
    ipums_example("cps_00159.xml"),
    IpumsListCallback$new(function(x, ...) x),
    1000,
    data_file = ipums_example("cps_00159.dat.gz"),
    verbose = FALSE
  )

  expect_equal(cps_yield, cps_chunked)
})

test_that("basic yield reading - list .dat.gz rect matches chunked", {
  cps_yield_source <- read_ipums_micro_list_yield(
    ipums_example("cps_00157.xml"),
    data_file = ipums_example("cps_00157.dat.gz"),
    verbose = FALSE
  )

  cps_yield <- list()
  while (!cps_yield_source$is_done()) {
    cps_yield[[length(cps_yield) + 1]] <- cps_yield_source$yield(1000)
  }

  cps_chunked <- read_ipums_micro_list_chunked(
    ipums_example("cps_00157.xml"),
    IpumsListCallback$new(function(x, ...) x),
    1000,
    data_file = ipums_example("cps_00157.dat.gz"),
    verbose = FALSE
  )

  expect_equal(cps_yield, cps_chunked)
})

test_that("read_ipums_micro_yield can't read from .csv file", {
  expect_error(
    cps_yield_source <- read_ipums_micro_yield(
      ddi = ipums_example("cps_00158.xml"),
      data_file = ipums_example("cps_00158.csv.gz"),
      verbose = FALSE
    ),
    regexp = "does not support"
  )
})

Try the ipumsr package in your browser

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

ipumsr documentation built on Sept. 12, 2024, 7:38 a.m.