File: test-python-raw.R

package info (click to toggle)
r-cran-reticulate 1.41.0.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,088 kB
  • sloc: cpp: 5,154; python: 620; sh: 13; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
context("raw")

raw <- as.raw(c(48:57, 0, 48:57))

test_that("Raw vectors are converted to bytearraw", {
  skip_if_no_python()
  expect_s3_class(r_to_py(raw), "python.builtin.bytearray")
})

test_that("Raw vectors with null bytes roundtrip correctly", {
  skip_if_no_python()
  ba <- r_to_py(raw)
  builtins <- import_builtins()
  expect_equal(builtins$len(ba), 21)
  expect_equal(py_to_r(ba), raw)
})

test_that("Raw vector of length zero creates length zero bytearray", {
  skip_if_no_python()
  builtins <- import_builtins()
  ba <- r_to_py(as.raw(c()))
  expect_equal(builtins$len(ba), 0)
})

test_that("bytearray of length zero creates length zero Raw", {
  skip_if_no_python()
  builtins <- import_builtins()
  expect_equal(builtins$bytearray(), raw())
})