|
196 | 196 | { |
197 | 197 | "cell_type": "code", |
198 | 198 | "execution_count": 1, |
199 | | - "metadata": {}, |
200 | | - "outputs": [ |
201 | | - { |
202 | | - "data": { |
203 | | - "application/javascript": [ |
204 | | - "IPython.notebook.save_checkpoint();\n", |
205 | | - "IPython.notebook.kernel.execute('nb_name = \"' + IPython.notebook.notebook_name + '\"')\n" |
206 | | - ], |
207 | | - "text/plain": [ |
208 | | - "<IPython.core.display.Javascript object>" |
209 | | - ] |
210 | | - }, |
211 | | - "metadata": {}, |
212 | | - "output_type": "display_data" |
213 | | - } |
214 | | - ], |
215 | | - "source": [ |
216 | | - "%%javascript\n", |
217 | | - "IPython.notebook.save_checkpoint();\n", |
218 | | - "IPython.notebook.kernel.execute('nb_name = \"' + IPython.notebook.notebook_name + '\"')" |
219 | | - ] |
220 | | - }, |
221 | | - { |
222 | | - "cell_type": "code", |
223 | | - "execution_count": 2, |
224 | 199 | "metadata": { |
225 | 200 | "scrolled": true |
226 | 201 | }, |
227 | 202 | "outputs": [], |
228 | 203 | "source": [ |
229 | | - "import ast\n", |
230 | 204 | "import ipytest\n", |
231 | | - "import nbconvert\n", |
232 | | - "import nbformat\n", |
233 | | - "import os\n", |
234 | | - "\n", |
235 | | - "\n", |
236 | | - "ipytest.autoconfig()\n", |
237 | | - "\n", |
238 | | - "\n", |
239 | | - "class InputChecker(ast.NodeVisitor):\n", |
240 | | - " def __init__(self):\n", |
241 | | - " self.num_inputs = 0\n", |
242 | | - "\n", |
243 | | - " def visit_Call(self, node):\n", |
244 | | - " if isinstance(node.func, ast.Name) and node.func.id == \"input\":\n", |
245 | | - " self.num_inputs += 1" |
| 205 | + "ipytest.autoconfig()" |
246 | 206 | ] |
247 | 207 | }, |
248 | 208 | { |
249 | 209 | "cell_type": "code", |
250 | | - "execution_count": 11, |
| 210 | + "execution_count": 3, |
251 | 211 | "metadata": {}, |
252 | 212 | "outputs": [ |
253 | 213 | { |
|
258 | 218 | "============================================= FAILURES =============================================\n", |
259 | 219 | "\u001b[31m\u001b[1m_________________________________________ test_num_inputs __________________________________________\u001b[0m\n", |
260 | 220 | "\n", |
261 | | - "tree = <ast.Module object at 0x10d086dd0>\n", |
| 221 | + "tree = <ast.Module object at 0x109a5a860>\n", |
262 | 222 | "\n", |
263 | 223 | " \u001b[94mdef\u001b[39;49;00m \u001b[92mtest_num_inputs\u001b[39;49;00m(tree):\n", |
264 | 224 | " checker = InputChecker()\n", |
|
267 | 227 | "> \u001b[94massert\u001b[39;49;00m checker.num_inputs >= \u001b[94m8\u001b[39;49;00m, \u001b[33m\"\u001b[39;49;00m\u001b[33myou don\u001b[39;49;00m\u001b[33m'\u001b[39;49;00m\u001b[33mt have enough calls to input()\u001b[39;49;00m\u001b[33m\"\u001b[39;49;00m\n", |
268 | 228 | "\u001b[1m\u001b[31mE AssertionError: you don't have enough calls to input()\u001b[0m\n", |
269 | 229 | "\u001b[1m\u001b[31mE assert 2 >= 8\u001b[0m\n", |
270 | | - "\u001b[1m\u001b[31mE + where 2 = <__main__.InputChecker object at 0x10d084fa0>.num_inputs\u001b[0m\n", |
| 230 | + "\u001b[1m\u001b[31mE + where 2 = <extras.scripts.hw_0_helper.InputChecker object at 0x10acc9ba0>.num_inputs\u001b[0m\n", |
271 | 231 | "\n", |
272 | | - "\u001b[1m\u001b[31m/var/folders/kg/1ys0dccx4237f5wsd_w10dt80000gn/T/ipykernel_65587/682324548.py\u001b[0m:27: AssertionError\n", |
| 232 | + "\u001b[1m\u001b[31m/var/folders/kg/1ys0dccx4237f5wsd_w10dt80000gn/T/ipykernel_67029/2901258849.py\u001b[0m:8: AssertionError\n", |
273 | 233 | "===================================== short test summary info ======================================\n", |
274 | | - "FAILED tmpciht1t3f.py::test_num_inputs - AssertionError: you don't have enough calls to input()\n" |
| 234 | + "FAILED tmpyoyk9z3m.py::test_num_inputs - AssertionError: you don't have enough calls to input()\n" |
275 | 235 | ] |
276 | 236 | } |
277 | 237 | ], |
278 | 238 | "source": [ |
279 | 239 | "%%ipytest -qq\n", |
280 | 240 | "\n", |
281 | | - "import pytest\n", |
282 | | - "\n", |
283 | | - "\n", |
284 | | - "\n", |
285 | | - "@pytest.fixture()\n", |
286 | | - "def notebook():\n", |
287 | | - " nb_full_path = os.path.join(os.getcwd(), nb_name)\n", |
288 | | - " return nbformat.read(nb_full_path, as_version=4)\n", |
289 | | - "\n", |
290 | | - "\n", |
291 | | - "@pytest.fixture()\n", |
292 | | - "def script(notebook):\n", |
293 | | - " exporter = nbconvert.exporters.PythonExporter\n", |
294 | | - " script, _ = nbconvert.exporters.export(exporter, notebook)\n", |
295 | | - " return script\n", |
296 | | - "\n", |
297 | | - "\n", |
298 | | - "@pytest.fixture()\n", |
299 | | - "def tree(script):\n", |
300 | | - " return ast.parse(script)\n", |
| 241 | + "from extras.scripts.hw_0_helper import *\n", |
301 | 242 | "\n", |
302 | 243 | "\n", |
303 | 244 | "def test_num_inputs(tree):\n", |
304 | 245 | " checker = InputChecker()\n", |
305 | 246 | " checker.visit(tree)\n", |
306 | | - " \n", |
| 247 | + "\n", |
307 | 248 | " assert checker.num_inputs >= 8, \"you don't have enough calls to input()\"" |
308 | 249 | ] |
309 | 250 | }, |
|
0 commit comments