|
3 | 3 | """Tests for notebook cell parsing.""" |
4 | 4 |
|
5 | 5 | import unittest |
6 | | -import sys |
7 | 6 | from kernel_gateway.notebook_http.swagger.parser import SwaggerCellParser |
8 | 7 |
|
9 | 8 |
|
@@ -142,51 +141,48 @@ def test_endpoint_response_concatenation(self): |
142 | 141 | self.assertEqual(endpoints['/foo/:bar']['get'], '# ResponseInfo operationId: get\n') |
143 | 142 |
|
144 | 143 | def test_undeclared_operations(self): |
145 | | - if sys.version_info[:2] >= (3,4): |
146 | | - """Parser should warn about operations that aren't documented in the |
147 | | - swagger cell |
148 | | - """ |
149 | | - source_cells = [ |
150 | | - {"source":'```\n{"swagger":"2.0", "paths": {"/foo": {"put": {"operationId":"putbar","parameters": [{"name": "bar"}]},"post":{"operationId":"postbar"},"get": {"operationId":"get","parameters": [{"name": "bar"}]}}}}\n```\n'}, |
151 | | - {"source":'# operationId: get'}, |
152 | | - {"source":'# operationId: postbar '}, |
153 | | - {"source":'# operationId: putbar'}, |
154 | | - {"source":'# operationId: extraOperation'}, |
155 | | - ] |
156 | | - with self.assertLogs(level='WARNING') as warnings: |
157 | | - SwaggerCellParser(comment_prefix='#', notebook_cells=source_cells) |
158 | | - for output in warnings.output: |
159 | | - self.assertRegex(output, 'extraOperation') |
| 144 | + """Parser should warn about operations that aren't documented in the |
| 145 | + swagger cell |
| 146 | + """ |
| 147 | + source_cells = [ |
| 148 | + {"source":'```\n{"swagger":"2.0", "paths": {"/foo": {"put": {"operationId":"putbar","parameters": [{"name": "bar"}]},"post":{"operationId":"postbar"},"get": {"operationId":"get","parameters": [{"name": "bar"}]}}}}\n```\n'}, |
| 149 | + {"source":'# operationId: get'}, |
| 150 | + {"source":'# operationId: postbar '}, |
| 151 | + {"source":'# operationId: putbar'}, |
| 152 | + {"source":'# operationId: extraOperation'}, |
| 153 | + ] |
| 154 | + with self.assertLogs(level='WARNING') as warnings: |
| 155 | + SwaggerCellParser(comment_prefix='#', notebook_cells=source_cells) |
| 156 | + for output in warnings.output: |
| 157 | + self.assertRegex(output, 'extraOperation') |
160 | 158 |
|
161 | 159 | def test_undeclared_operations_reversed(self): |
162 | | - if sys.version_info[:2] >= (3,4): |
163 | | - """Parser should warn about operations that aren't documented in the |
164 | | - swagger cell |
165 | | - """ |
166 | | - source_cells = [ |
167 | | - {"source":'# operationId: get'}, |
168 | | - {"source":'# operationId: postbar '}, |
169 | | - {"source":'# operationId: putbar'}, |
170 | | - {"source":'# operationId: extraOperation'}, |
171 | | - {"source":'```\n{"swagger":"2.0", "paths": {"/foo": {"put": {"operationId":"putbar","parameters": [{"name": "bar"}]},"post":{"operationId":"postbar"},"get": {"operationId":"get","parameters": [{"name": "bar"}]}}}}\n```\n'}, |
172 | | - ] |
173 | | - with self.assertLogs(level='WARNING') as warnings: |
174 | | - SwaggerCellParser(comment_prefix='#', notebook_cells=source_cells) |
175 | | - for output in warnings.output: |
176 | | - self.assertRegex(output, 'extraOperation') |
| 160 | + """Parser should warn about operations that aren't documented in the |
| 161 | + swagger cell |
| 162 | + """ |
| 163 | + source_cells = [ |
| 164 | + {"source":'# operationId: get'}, |
| 165 | + {"source":'# operationId: postbar '}, |
| 166 | + {"source":'# operationId: putbar'}, |
| 167 | + {"source":'# operationId: extraOperation'}, |
| 168 | + {"source":'```\n{"swagger":"2.0", "paths": {"/foo": {"put": {"operationId":"putbar","parameters": [{"name": "bar"}]},"post":{"operationId":"postbar"},"get": {"operationId":"get","parameters": [{"name": "bar"}]}}}}\n```\n'}, |
| 169 | + ] |
| 170 | + with self.assertLogs(level='WARNING') as warnings: |
| 171 | + SwaggerCellParser(comment_prefix='#', notebook_cells=source_cells) |
| 172 | + for output in warnings.output: |
| 173 | + self.assertRegex(output, 'extraOperation') |
177 | 174 |
|
178 | 175 | def test_unreferenced_operations(self): |
179 | | - if sys.version_info[:2] >= (3,4): |
180 | | - """Parser should warn about documented operations that aren't referenced |
181 | | - in a cell |
182 | | - """ |
183 | | - source_cells = [ |
184 | | - {"source": '```\n{"swagger":"2.0", "paths": {"/foo": {"put": {"operationId":"putbar","parameters": [{"name": "bar"}]},"post":{"operationId":"postbar"},"get": {"operationId":"get","parameters": [{"name": "bar"}]}}}}\n```\n'}, |
185 | | - {"source": '# operationId: get'}, |
186 | | - {"source": '# operationId: putbar'}, |
187 | | - {"source": '# operationId: putbar '} |
188 | | - ] |
189 | | - with self.assertLogs(level='WARNING') as warnings: |
190 | | - SwaggerCellParser(comment_prefix='#', notebook_cells=source_cells) |
191 | | - for output in warnings.output: |
192 | | - self.assertRegex(output, 'postbar') |
| 176 | + """Parser should warn about documented operations that aren't referenced |
| 177 | + in a cell |
| 178 | + """ |
| 179 | + source_cells = [ |
| 180 | + {"source": '```\n{"swagger":"2.0", "paths": {"/foo": {"put": {"operationId":"putbar","parameters": [{"name": "bar"}]},"post":{"operationId":"postbar"},"get": {"operationId":"get","parameters": [{"name": "bar"}]}}}}\n```\n'}, |
| 181 | + {"source": '# operationId: get'}, |
| 182 | + {"source": '# operationId: putbar'}, |
| 183 | + {"source": '# operationId: putbar '} |
| 184 | + ] |
| 185 | + with self.assertLogs(level='WARNING') as warnings: |
| 186 | + SwaggerCellParser(comment_prefix='#', notebook_cells=source_cells) |
| 187 | + for output in warnings.output: |
| 188 | + self.assertRegex(output, 'postbar') |
0 commit comments