File: test_clientwrap.py

package info (click to toggle)
python-papermill 2.6.0-3.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 2,216 kB
  • sloc: python: 4,977; makefile: 17; sh: 5
file content (39 lines) | stat: -rw-r--r-- 1,590 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
import unittest
from unittest.mock import call, patch

import nbformat

from papermill.clientwrap import PapermillNotebookClient
from papermill.engines import NotebookExecutionManager
from papermill.log import logger
from . import get_notebook_path


class TestPapermillClientWrapper(unittest.TestCase):
    def setUp(self):
        self.nb = nbformat.read(get_notebook_path('test_logging.ipynb'), as_version=4)
        self.nb_man = NotebookExecutionManager(self.nb)
        self.client = PapermillNotebookClient(self.nb_man, log=logger, log_output=True)

    def test_logging_stderr_msg(self):
        with patch.object(logger, 'warning') as warning_mock:
            for output in self.nb.cells[0].get("outputs", []):
                self.client.log_output_message(output)
            warning_mock.assert_called_once_with("INFO:test:test text\n")

    def test_logging_stdout_msg(self):
        with patch.object(logger, 'info') as info_mock:
            for output in self.nb.cells[1].get("outputs", []):
                self.client.log_output_message(output)
            info_mock.assert_called_once_with("hello world\n")

    def test_logging_data_msg(self):
        with patch.object(logger, 'info') as info_mock:
            for output in self.nb.cells[2].get("outputs", []):
                self.client.log_output_message(output)
            info_mock.assert_has_calls(
                [
                    call("<matplotlib.axes._subplots.AxesSubplot at 0x7f8391f10290>"),
                    call("<matplotlib.figure.Figure at 0x7f830af7b350>"),
                ]
            )