-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_docassert_cpp.py
More file actions
61 lines (54 loc) · 2.54 KB
/
test_docassert_cpp.py
File metadata and controls
61 lines (54 loc) · 2.54 KB
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
import unittest
from sphinx_runpython.ext_test_case import ExtTestCase
from sphinx_runpython.import_object_helper import import_object
from sphinx_runpython.docassert.sphinx_docassert_extension import parse_signature
class TestDocAssertCpp(ExtTestCase):
def test_import_object1(self):
name = "onnx_extended.ortcy.wrap.ortinf.OrtSession"
try:
obj, new_name = import_object(name, kind="class")
except (ImportError, RuntimeError):
return
self.assertEqual(name.split(".")[-1], new_name)
self.assertEqual(obj.__text_signature__, "($self, /, *args, **kwargs)")
def test_import_object2(self):
name = "onnx_extended.validation.cpu._validation.benchmark_cache"
try:
obj, new_name = import_object(name, kind="function")
except (ImportError, RuntimeError):
return
self.assertEqual(name.split(".")[-1], new_name)
self.assertEmpty(obj.__text_signature__)
sig = parse_signature(obj.__doc__)
self.assertEqual(
repr(sig), "benchmark_cache(size: int, verbose: bool = True) -> float"
)
self.assertIn("size", sig.param_names)
def test_import_object3(self):
name = "onnx_extended.validation.cython.vector_function_cy.vector_add_c"
try:
obj, new_name = import_object(name, kind="function")
except (ImportError, RuntimeError):
return
self.assertEqual(name.split(".")[-1], new_name)
self.assertIn("vector_add_c(v1, v2)", obj.__doc__)
sig = parse_signature(obj.__doc__)
self.assertEqual(repr(sig), "vector_add_c(v1, v2)")
self.assertIn("v1", sig.param_names)
def test_extract_signature(self):
sig = (
"benchmark_cache(size: int, verbose: bool = True) -> float\n\n "
"Runs a benchmark to measure the cache performance.\nThe function "
"measures the time for N random accesses in array of size N\nand "
"returns the time divided by N.\nIt copies random elements taken "
"from the array size to random\nposition in another of the same size. "
"It does that *size* times\nand return the average time per move."
"\nSee example :ref:`l-example-bench-cpu`.\n\n"
":param size: array size\n:return: average time per move\n\n'"
)
res = parse_signature(sig)
self.assertEqual(
repr(res), "benchmark_cache(size: int, verbose: bool = True) -> float"
)
if __name__ == "__main__":
unittest.main(verbosity=2)