コード例 #1
0
    def test_rendering_one_row_adjusts_the_top_height(self, monkeypatch,
                                                      fake_image,
                                                      simulator_fig):
        self.subplot_forward_simulator_axes(monkeypatch, [AxesDouble()])

        found_adjust_top = None

        def mock_subplots_adjust(left=None,
                                 bottom=None,
                                 right=None,
                                 top=None,
                                 wspace=None,
                                 hspace=None):
            # Note that "nonlocal" is required here but not in the "simulator_fig"
            # variable above since found_adjust_top is assigned. The behavior of
            # assignment is more restrictive/safe.
            nonlocal found_adjust_top
            found_adjust_top = top

        monkeypatch.setattr(plt, "subplots_adjust", mock_subplots_adjust)

        subject = PlotGallery(title='One Row', columns=1)
        subject.add_exhibit(Exhibit(fake_image, 'does not matter'))
        subject.open()

        assert found_adjust_top == 1.3
コード例 #2
0
    def test_exhibits_can_opt_into_displaying_axes(self, fake_image,
                                                   monkeypatch,
                                                   subplot_adjust_noop):
        simulator_axes = [AxesDouble(), AxesDouble()]
        self.subplot_forward_simulator_axes(monkeypatch, simulator_axes)

        axis_on_exhibit = Exhibit(fake_image, title='axis on', axis='on')
        default_axis_exhibit = Exhibit(fake_image, title='default axis')

        subject = PlotGallery(title='test')
        subject.add_exhibit(axis_on_exhibit)
        subject.add_exhibit(default_axis_exhibit)
        subject.open()

        assert simulator_axes[0].axis_setting == 'on'
        assert simulator_axes[1].axis_setting == 'off'
コード例 #3
0
    def test_exhibit_attributes_are_passed_into_matplotlib_axes(
            self, monkeypatch, fake_image, simulator_fig, subplot_adjust_noop):
        gallery_title = 'test gallery'
        expected_fig = FigureDouble()
        expected_fig.suptitle(gallery_title)

        my_exhibit = Exhibit(fake_image, title='exhibit 1')
        subject = PlotGallery(gallery_title)
        subject.add_exhibit(my_exhibit)

        simulator_axes = []
        found_nrows = None
        found_ncols = None

        def mock_subplot(nrows, ncols, figsize=None):
            nonlocal found_nrows
            nonlocal found_ncols
            found_nrows = nrows
            found_ncols = ncols

            for i in range(0, nrows * ncols):
                simulator_axes.append(AxesDouble())

            return simulator_fig, simulator_axes

        monkeypatch.setattr(plt, "subplots", mock_subplot)

        subject.open()

        assert simulator_fig.title == expected_fig.title

        assert found_nrows == 1
        assert found_ncols == 1

        assert len(simulator_axes) == 1

        found_axis = simulator_axes[0]
        expected_axis_state = {
            'axis_setting': 'off',
            'fontsize': 8,
            'image': my_exhibit.image,
            'shown': True,
            'title': my_exhibit.title,
        }

        assert found_axis.title == my_exhibit.title
        assert found_axis.__dict__ == expected_axis_state
コード例 #4
0
    def test_rendering_multiple_rows(self, monkeypatch, fake_image,
                                     simulator_fig, subplot_adjust_noop):
        simulator_axes = [
            [AxesDouble(), AxesDouble()],
            [AxesDouble(), AxesDouble()],
        ]
        self.subplot_forward_simulator_axes(monkeypatch, simulator_axes)

        subject = PlotGallery(title='two rows', columns=2)
        subject.add_exhibit(Exhibit(fake_image, '1'))
        subject.add_exhibit(Exhibit(fake_image, '2'))
        subject.add_exhibit(Exhibit(fake_image, '3, on a second row'))
        subject.open()

        assert simulator_axes[0][0].title == '1'
        assert simulator_axes[0][1].title == '2'
        assert simulator_axes[1][0].title == '3, on a second row'
コード例 #5
0
    def test_rendering_multiple_rows_uses_no_top_height(
            self, monkeypatch, fake_image, simulator_fig, subplot_adjust_noop):
        self.subplot_forward_simulator_axes(
            monkeypatch, [AxesDouble(), AxesDouble()])

        found_adjust_top = None

        def mock_subplots_adjust(left=None,
                                 bottom=None,
                                 right=None,
                                 top=None,
                                 wspace=None,
                                 hspace=None):
            nonlocal found_adjust_top
            found_adjust_top = top

        monkeypatch.setattr(plt, "subplots_adjust", mock_subplots_adjust)

        subject = PlotGallery(title='Two Rows', columns=1)
        subject.add_exhibit(Exhibit(fake_image, 'on first row'))
        subject.add_exhibit(Exhibit(fake_image, 'on second row'))
        subject.open()

        assert found_adjust_top == None