File: test_docstring.py

package info (click to toggle)
python-botocore 1.37.9%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 121,768 kB
  • sloc: python: 73,696; xml: 14,880; javascript: 181; makefile: 155
file content (102 lines) | stat: -rw-r--r-- 3,593 bytes parent folder | download | duplicates (2)
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
# 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
#
# http://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.
from botocore.docs.docstring import (
    ClientMethodDocstring,
    LazyLoadedDocstring,
    PaginatorDocstring,
    WaiterDocstring,
)
from tests import mock, unittest


class MockedLazyLoadedDocstring(LazyLoadedDocstring):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.mocked_writer_method = mock.Mock()

    def _write_docstring(self, *args, **kwargs):
        self.mocked_writer_method(*args, **kwargs)


class TestLazyLoadedDocstring(unittest.TestCase):
    def test_raises_not_implemented(self):
        with self.assertRaises(NotImplementedError):
            str(LazyLoadedDocstring())

    def test_expandtabs(self):
        docstring = MockedLazyLoadedDocstring()
        docstring.mocked_writer_method.side_effect = (
            lambda section: section.write('foo\t')
        )
        self.assertEqual('foo ', docstring.expandtabs(1))

    def test_str(self):
        docstring = MockedLazyLoadedDocstring()
        docstring.mocked_writer_method.side_effect = (
            lambda section: section.write('foo')
        )
        self.assertEqual('foo', str(docstring))

    def test_repr(self):
        docstring = MockedLazyLoadedDocstring()
        docstring.mocked_writer_method.side_effect = (
            lambda section: section.write('foo')
        )
        self.assertEqual('foo', repr(docstring))

    def test_is_lazy_loaded(self):
        docstring = MockedLazyLoadedDocstring()
        str(docstring)
        str(docstring)
        # The mock.ANY represents the DocumentStructure that is filled out.
        docstring.mocked_writer_method.assert_called_once_with(mock.ANY)

    def test_args_kwargs_passed(self):
        args = ['foo', 'bar']
        kwargs = {'biz': 'baz'}
        docstring = MockedLazyLoadedDocstring(*args, **kwargs)
        str(docstring)
        # The mock.ANY represents the DocumentStructure that is filled out.
        docstring.mocked_writer_method.assert_called_with(
            mock.ANY, *args, **kwargs
        )


class TestClientMethodDocstring(unittest.TestCase):
    def test_use_correct_docstring_writer(self):
        with mock.patch(
            'botocore.docs.docstring' '.document_model_driven_method'
        ) as mock_writer:
            docstring = ClientMethodDocstring()
            str(docstring)
            self.assertTrue(mock_writer.called)


class TestWaiterDocstring(unittest.TestCase):
    def test_use_correct_docstring_writer(self):
        with mock.patch(
            'botocore.docs.docstring' '.document_wait_method'
        ) as mock_writer:
            docstring = WaiterDocstring()
            str(docstring)
            self.assertTrue(mock_writer.called)


class TestPaginatorDocstring(unittest.TestCase):
    def test_use_correct_docstring_writer(self):
        with mock.patch(
            'botocore.docs.docstring' '.document_paginate_method'
        ) as mock_writer:
            docstring = PaginatorDocstring()
            str(docstring)
            self.assertTrue(mock_writer.called)