File: test-python-strings.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 (25 lines) | stat: -rw-r--r-- 664 bytes parent folder | download
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
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")
})