<commit_before>context('adapter reference class')

test_that('it can initialize an adapter correctly', {
  a <- adapter(identity, identity)
})

test_that('it can read using a simple example adapter correctly', {
  tmp <- new.env()
  read_function <- function(opts) tmp$x <- opts$resource
  a <- adapter(read_function, identity)
  expect_identical(a$read("test"), "test")
  expect_identical(tmp$x, "test")
})

test_that('it can write using a simple example adapter correctly', {
  tmp <- new.env()
  read_function <- function(opts) tmp[[opts$resource]]
  write_function <- function(val, opts) { force(opts); tmp$x <- val }
  a <- adapter(read_function, write_function)
  a$write("test")
  expect_identical(tmp$x, "test")
  expect_identical(a$read('x'), "test")
})

describe("RDS2 functionality", {
  library(RDS2)

  test_that("it can read an RDS2 object correctly", {
    file_adapter <- construct_file_adapter()
    rds2_object <- structure("foo", RDS2.serialize = list(
      read  = function(obj) paste0(obj, "bar"),
      write = identity
    ))
    file <- tempfile(fileext = ".rds")
    RDS2::saveRDS(rds2_object, file)
    with_mock(has_RDS2 = function() TRUE, {
      object <- file_adapter$read(file)
      expect_false("RDS2.serialize" %in% names(attributes(object)))
    })
    with_mock(has_RDS2 = function() FALSE, {
      object <- file_adapter$read(file)
      expect_true("RDS2.serialize" %in% names(attributes(object)))
    })
  })
})<commit_msg>Explicit mock.<commit_after>context('adapter reference class')

test_that('it can initialize an adapter correctly', {
  a <- adapter(identity, identity)
})

test_that('it can read using a simple example adapter correctly', {
  tmp <- new.env()
  read_function <- function(opts) tmp$x <- opts$resource
  a <- adapter(read_function, identity)
  expect_identical(a$read("test"), "test")
  expect_identical(tmp$x, "test")
})

test_that('it can write using a simple example adapter correctly', {
  tmp <- new.env()
  read_function <- function(opts) tmp[[opts$resource]]
  write_function <- function(val, opts) { force(opts); tmp$x <- val }
  a <- adapter(read_function, write_function)
  a$write("test")
  expect_identical(tmp$x, "test")
  expect_identical(a$read('x'), "test")
})

describe("RDS2 functionality", {
  library(RDS2)

  test_that("it can read an RDS2 object correctly", {
    file_adapter <- construct_file_adapter()
    rds2_object <- structure("foo", RDS2.serialize = list(
      read  = function(obj) paste0(obj, "bar"),
      write = identity
    ))
    file <- tempfile(fileext = ".rds")
    RDS2::saveRDS(rds2_object, file)
    with_mock(`syberiaStages:::has_RDS2` = function() TRUE, {
      object <- file_adapter$read(file)
      expect_false("RDS2.serialize" %in% names(attributes(object)))
    })
    with_mock(`syberiaStages:::has_RDS2` = function() FALSE, {
      object <- file_adapter$read(file)
      expect_true("RDS2.serialize" %in% names(attributes(object)))
    })
  })
})
{'fraction_non_alphanumeric': 0.15356058049274385, 'fraction_numerical': 0.00809989875126561, 'mean_word_length': 4.398907103825136, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3711281', 'n_tokens_mistral': 1011, 'n_tokens_neox': 976, 'n_words': 211}