File: test-help-handlers.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 (72 lines) | stat: -rw-r--r-- 1,875 bytes parent folder | download | duplicates (3)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
context("helper handlers")

test_that("Documentations in Sphinx style can be extracted correctly for help handlers", {
  skip_if_no_docutils()

  docs <- "
Initialize the model.

Parameters
----------
a : int, optional
  Description for a.
  Defaults to 3.
type : str, optional
  Type of algorithm (default: 'linear')
    'linear'        - linear model
    'nonlinear'     - nonlinear model

Returns
-------
values : array-like

Section1
-----------
Just a placeholder here.
"

  doctree <- sphinx_doctree_from_doc(docs)
  expect_setequal(names(doctree$ids), c("parameters", "returns", "section1"))

  arg_descriptions <- arg_descriptions_from_doc_sphinx(docs)
  expect_setequal(names(arg_descriptions), c("a", "type"))
  expect_match(arg_descriptions[["a"]], "Description for a")
  expect_match(arg_descriptions[["type"]], "Type of algorithm")

  result <- help_completion_handler_sphinx(docs)
  expect_match(result$description, "Initialize the model")
  expect_match(result$returns, "values: array-like")
})

test_that("Documentations in Google style can be extracted correctly for help handlers", {
  skip_if_no_docutils()

  docs <- "
Initialize the model.

Args:
  a: Description for a.
    Defaults to 3.
  type: Type of algorithm (default: 'linear')
    'linear'        - linear model
    'nonlinear'     - nonlinear model

Returns:
  array-like values

Section1:
  Just a placeholder here.
"

  sections <- sections_from_doc(docs)
  expect_equal(names(sections), c("Args", "Returns", "Section1"))

  arg_descriptions <- arg_descriptions_from_doc_default(c("a", "type"), docs)
  expect_match(arg_descriptions[["a"]], "Description for a")
  expect_match(arg_descriptions[["type"]], "Type of algorithm")

  result <- help_completion_handler_default(docs)
  expect_match(result$description, "Initialize the model")
  expect_match(result$returns, "array-like values")
})