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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
|
# Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# https://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import io
from tests import mock
from tests.unit.docs import BaseDocsTest
class TestResourceDocstrings(BaseDocsTest):
def test_action_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.sample_operation)
action_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
' **Request Syntax**',
' ::',
' response = myservice.sample_operation(',
' Foo=\'string\',',
' Bar=\'string\'',
' )',
' :type Foo: string',
' :param Foo: Documents Foo',
' :type Bar: string',
' :param Bar: Documents Bar',
' :rtype: dict',
' :returns:',
' **Response Syntax**',
' ::',
' {',
' \'Foo\': \'string\',',
' \'Bar\': \'string\'',
' }',
' **Response Structure**',
' - *(dict) --*',
' - **Foo** *(string) --* Documents Foo',
' - **Bar** *(string) --* Documents Bar',
],
action_docstring,
)
def test_load_help(self):
sub_resource = self.resource.Sample('Id')
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(sub_resource.load)
load_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
(
' Calls :py:meth:`MyService.Client.sample_operation` to update '
'the attributes of the Sample resource'
),
' **Request Syntax** ',
' ::',
' sample.load()',
' :returns: None',
],
load_docstring,
)
def test_sub_resource_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample)
sub_resource_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
' Creates a Sample resource.::',
" sample = myservice.Sample('name')",
' :type name: string',
" :param name: The Sample's name identifier.",
' :rtype: :py:class:`MyService.Sample`',
' :returns: A Sample resource',
],
sub_resource_docstring,
)
def test_attribute_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample('id').__class__.foo)
attribute_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[' - *(string) --* Documents Foo'], attribute_docstring
)
def test_identifier_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample('id').__class__.name)
identifier_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
" *(string)* The Sample's name identifier. This "
"**must** be set."
],
identifier_docstring,
)
def test_reference_help(self):
sample_resource = self.resource.Sample('id')
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(sample_resource.__class__.related_sample)
reference_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
" (:py:class:`Sample`) The related related_sample "
"if set, otherwise ``None``."
],
reference_docstring,
)
def test_collection_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.__class__.samples)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[' A collection of Sample resources'],
collection_method_docstring,
)
def test_collection_all_method_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.all)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
(
' Creates an iterable of all Sample resources in the '
'collection.'
),
' **Request Syntax** ',
' ::',
' sample_iterator = myservice.samples.all()',
' :rtype: list(:py:class:`myservice.Sample`)',
' :returns: A list of Sample resources',
],
collection_method_docstring,
)
def test_collection_filter_method_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.filter)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
' **Request Syntax** ',
' ::',
' sample_iterator = myservice.samples.filter(',
" Foo='string',",
" Bar='string'",
' )',
' :type Foo: string',
' :param Foo: Documents Foo',
' :type Bar: string',
' :param Bar: Documents Bar',
' :rtype: list(:py:class:`myservice.Sample`)',
' :returns: A list of Sample resources',
],
collection_method_docstring,
)
def test_collection_limit_method_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.limit)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
' **Request Syntax** ',
' ::',
' sample_iterator = myservice.samples.limit(',
' count=123',
' )',
' :type count: integer',
(
' :param count: The limit to the number of resources '
'in the iterable.'
),
' :rtype: list(:py:class:`myservice.Sample`)',
' :returns: A list of Sample resources',
],
collection_method_docstring,
)
def test_collection_page_size_method_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.page_size)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
' **Request Syntax** ',
' ::',
' sample_iterator = myservice.samples.page_size(',
' count=123',
' )',
' :type count: integer',
(
' :param count: The number of items returned by '
'each service call'
),
' :rtype: list(:py:class:`myservice.Sample`)',
' :returns: A list of Sample resources',
],
collection_method_docstring,
)
def test_collection_chaining_help(self):
collection = self.resource.samples.all()
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(collection.all)
collection_method_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
(
' Creates an iterable of all Sample resources in the '
'collection.'
),
' **Request Syntax** ',
' ::',
' sample_iterator = myservice.samples.all()',
' :rtype: list(:py:class:`myservice.Sample`)',
' :returns: A list of Sample resources',
],
collection_method_docstring,
)
def test_batch_action_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.samples.operate)
batch_action_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
' **Request Syntax** ',
' ::',
' response = myservice.samples.operate(',
" Foo='string',",
" Bar='string'",
' )',
' :type Foo: string',
' :param Foo: Documents Foo',
' :type Bar: string',
' :param Bar: Documents Bar',
' :rtype: dict',
' :returns: ',
' **Response Syntax** ',
' ::',
' {',
" 'Foo': 'string',",
" 'Bar': 'string'",
' }',
' **Response Structure** ',
' - *(dict) --* ',
' - **Foo** *(string) --* Documents Foo',
' - **Bar** *(string) --* Documents Bar',
],
batch_action_docstring,
)
def test_resource_waiter_help(self):
with mock.patch('sys.stdout', io.StringIO()) as mock_stdout:
help(self.resource.Sample('id').wait_until_complete)
resource_waiter_docstring = mock_stdout.getvalue()
self.assert_contains_lines_in_order(
[
(
' Waits until this Sample is complete. This method calls '
':py:meth:`MyService.Waiter.sample_operation_complete.wait` '
'which polls. :py:meth:`MyService.Client.sample_operation` every '
'15 seconds until a successful state is reached. An error '
'is returned after 40 failed checks.'
),
' **Request Syntax** ',
' ::',
' sample.wait_until_complete(',
" Bar='string'",
' )',
' :type Bar: string',
' :param Bar: Documents Bar',
' :returns: None',
],
resource_waiter_docstring,
)
|