tests/testthat/test-python-strings.R

context("strings")

test_that("Unicode strings are handled by py_str", {
  skip_if_no_python()
  skip_on_cran()
  skip_on_os("windows")
  main <- py_run_string("x = u'\\xfc'", convert = FALSE)
  expect_equal(py_str(main$x), "ΓΌ")
})



test_that("subclassed strings convert", {
  skip_if_no_python()
  skip_on_cran()

  # https://github.com/rstudio/reticulate/issues/1348
  # https://github.com/fastai/fastcore/blob/master/fastcore/basics.py#L1015
  PrettyString <- py_run_string(
  'class PrettyString(str):
    def __repr__(self): return self', convert = FALSE)$PrettyString
  expect_identical(py_repr(PrettyString("abc_xyz")),
                   "abc_xyz")
})

Try the reticulate package in your browser

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

reticulate documentation built on Sept. 11, 2024, 8:31 p.m.