-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathtest_argsdocs.py
executable file
·122 lines (84 loc) · 3.65 KB
/
test_argsdocs.py
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"""Module doc - used in tests"""
import datetime
import decimal
import unittest
from robotremoteserver import RemoteLibraryFactory
class NonMarshallable:
def __repr__(self):
return f'{self.__class__.__name__}()'
class LibraryWithArgsAndDocs:
"""Intro doc"""
def __init__(self, i1, i2=1, *i3):
"""Init doc"""
def keyword(self, k1, k2=2, *k3):
"""Keyword doc"""
def no_doc_or_args(self):
pass
def marshallable_defaults(self, k1=True, k2=0, k3=0.0, k4='', k5=[], k6={}, k7=datetime.datetime.min, k8=b''):
pass
def non_marshallable_defaults(self, k1=NonMarshallable(), k2=2147483648, k3=decimal.Decimal(0), k4=None, k5=[None]):
pass
def nested_marshallable_defaults(self, k1={'one': [1], 'two': False}):
pass
def mixed_defaults(self, k1=True, k2=None):
pass
def keyword_in_module(m1, m2=3, *m3):
"""Module keyword doc"""
class TestDocs(unittest.TestCase):
def test_keyword_doc(self):
self._test_doc('keyword', 'Keyword doc')
def test_keyword_doc_when_no_doc(self):
self._test_doc('no_doc_or_args', '')
def test_intro_doc(self):
self._test_doc('__intro__', 'Intro doc')
def test_init_doc(self):
self._test_doc('__init__', 'Init doc')
def test_init_doc_when_old_style_lib_has_no_init(self):
class OldStyleLibraryWithoutInit:
pass
self._test_doc('__init__', '', OldStyleLibraryWithoutInit())
def test_init_doc_when_new_style_lib_has_no_init(self):
class NewStyleLibraryWithoutInit(object):
pass
self._test_doc('__init__', '', NewStyleLibraryWithoutInit())
def test_keyword_doc_from_module_keyword(self):
import test_argsdocs
self._test_doc('keyword_in_module', 'Module keyword doc', test_argsdocs)
def test_init_doc_from_module(self):
import test_argsdocs
self._test_doc('__init__', '', test_argsdocs)
def test_intro_doc_from_module(self):
import test_argsdocs
self._test_doc('__intro__', 'Module doc - used in tests', test_argsdocs)
def _test_doc(self, name, expected, library=LibraryWithArgsAndDocs(None)):
library = RemoteLibraryFactory(library)
self.assertEquals(library.get_keyword_documentation(name), expected)
class TestArgs(unittest.TestCase):
def test_keyword_args(self):
self._test_args('keyword', ['k1', ('k2', 2), '*k3'])
def test_keyword_args_when_no_args(self):
self._test_args('no_doc_or_args', [])
def test_keyword_args_from_module_keyword(self):
import test_argsdocs
self._test_args('keyword_in_module', ['m1', ('m2', 3), '*m3'],
test_argsdocs)
def test_marshallable_defaults(self):
self._test_args(
'marshallable_defaults',
[
('k1', True), ('k2', 0), ('k3', 0.0), ('k4', ''), ('k5', []), ('k6', {}),
('k7', datetime.datetime.min), ('k8', b'')
]
)
def test_non_marshallable_defaults(self):
self._test_args('non_marshallable_defaults',
['k1=NonMarshallable()', 'k2=2147483648', 'k3=0', 'k4=None', 'k5=[None]'])
def test_nested_marshallable_defaults(self):
self._test_args('nested_marshallable_defaults', [('k1', {'one': [1], 'two': False})])
def test_mixed_defaults(self):
self._test_args('mixed_defaults', [('k1', True), 'k2=None'])
def _test_args(self, name, expected, library=LibraryWithArgsAndDocs(None)):
library = RemoteLibraryFactory(library)
self.assertEquals(library.get_keyword_arguments(name), expected)
if __name__ == '__main__':
unittest.main()