Beispiel #1
0
 def test_file_as_memory_output(self):
     img = array([[0, 1], [1, 0], [.5, .3]])
     mem = BytesIO()
     img2output(img, cmap="gray", output=mem)
     mem.seek(0)
     png_data = imread(mem)
     for row_png, row_img in zip(png_data, img):
         for pixel_png, pixel_img in zip(row_png, row_img):
             assert almost_equal_diff(pixel_png[-1], 1.)
             for pixel in pixel_png[:-1]:
                 assert almost_equal_diff(pixel, pixel_img)
Beispiel #2
0
 def test_file_as_memory_output(self):
   img = array([[0, 1], [1, 0], [.5, .3]])
   mem = BytesIO()
   img2output(img, cmap="gray", output=mem)
   mem.seek(0)
   png_data = imread(mem)
   for row_png, row_img in zip(png_data, img):
     for pixel_png, pixel_img in zip(row_png, row_img):
       assert almost_equal_diff(pixel_png[-1], 1.)
       for pixel in pixel_png[:-1]:
         assert almost_equal_diff(pixel, pixel_img)
Beispiel #3
0
    def test_show_and_output(self, monkeypatch):
        def imsave(output, img, cmap):  # Should be called first
            assert not imsave.called
            assert not imshow.called
            assert cmap == "something"
            assert img.shape == (2, 4)
            imsave.called = True
            output.write(b"Data!")

        def imshow(img, cmap):
            assert imsave.called
            assert not imshow.called
            assert cmap == "something"
            assert img.shape == (2, 4)
            imshow.called = True

        def show():
            assert imsave.called
            assert imshow.called

        monkeypatch.setattr(pylab, "imsave", imsave)
        monkeypatch.setattr(pylab, "imshow", imshow)
        monkeypatch.setattr(pylab, "show", show)

        img = array([[5, -1, 4, .0003], [.1, 0., 47.8, -8]])
        imshow.called = False
        imsave.called = False
        mem = BytesIO()
        assert img2output(img, cmap="something", output=mem, show=True) is None
        mem.seek(0)
        assert mem.read() == b"Data!"
Beispiel #4
0
  def test_show_and_output(self, monkeypatch):
    def imsave(output, img, cmap): # Should be called first
      assert not imsave.called
      assert not imshow.called
      assert cmap == "something"
      assert img.shape == (2, 4)
      imsave.called = True
      output.write(b"Data!")
    def imshow(img, cmap):
      assert imsave.called
      assert not imshow.called
      assert cmap == "something"
      assert img.shape == (2, 4)
      imshow.called = True
    def show():
      assert imsave.called
      assert imshow.called
    monkeypatch.setattr(pylab, "imsave", imsave)
    monkeypatch.setattr(pylab, "imshow", imshow)
    monkeypatch.setattr(pylab, "show", show)

    img = array([[5, -1, 4, .0003], [.1, 0., 47.8, -8]])
    imshow.called = False
    imsave.called = False
    mem = BytesIO()
    assert img2output(img, cmap="something", output=mem, show=True) is None
    mem.seek(0)
    assert mem.read() == b"Data!"
Beispiel #5
0
  def test_show(self, monkeypatch):
    def imshow(img, cmap):
      assert not imshow.called
      assert cmap == "gray"
      assert img.shape == (3, 2)
      imshow.called = True
    def show():
      assert imshow.called
    monkeypatch.setattr(pylab, "imshow", imshow)
    monkeypatch.setattr(pylab, "show", show)

    img = array([[0, 1], [1, 0], [.5, .3]])
    imshow.called = False
    assert img2output(img, cmap="gray", show=True) is None
Beispiel #6
0
    def test_show(self, monkeypatch):
        def imshow(img, cmap):
            assert not imshow.called
            assert cmap == "gray"
            assert img.shape == (3, 2)
            imshow.called = True

        def show():
            assert imshow.called

        monkeypatch.setattr(pylab, "imshow", imshow)
        monkeypatch.setattr(pylab, "show", show)

        img = array([[0, 1], [1, 0], [.5, .3]])
        imshow.called = False
        assert img2output(img, cmap="gray", show=True) is None