Skip to content

Commit

Permalink
convert more assert_equals() (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmeine committed Feb 20, 2022
1 parent 7c4d019 commit 4f9af2a
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 66 deletions.
42 changes: 21 additions & 21 deletions test/test_imread.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import qimage2ndarray, os, numpy

from nose.tools import assert_equal, raises
from nose.tools import raises
from nose.plugins.skip import SkipTest


Expand All @@ -22,25 +22,25 @@ def test_imread_box():

gray = qimage2ndarray.imread(filename)

assert_equal(gray.min(), 0)
assert_equal(gray.max(), 255)
assert gray.min() == 0
assert gray.max() == 255

assert_equal(numpy.ndim(gray), 2)
assert numpy.ndim(gray) == 2

assert_equal(gray.shape, (50, 111))
assert gray.shape == (50, 111)


def test_imread_rgba():
filename = _locate_test_image('test_colored_shadow.png')

rgb = qimage2ndarray.imread(filename)

assert_equal(rgb.min(), 0)
assert_equal(rgb.max(), 255)
assert rgb.min() == 0
assert rgb.max() == 255

assert_equal(numpy.ndim(rgb), 3)
assert numpy.ndim(rgb) == 3

assert_equal(rgb.shape, (50, 111, 4))
assert rgb.shape == (50, 111, 4)


def test_imread_gray():
Expand All @@ -50,9 +50,9 @@ def test_imread_gray():

assert 200 < gray.max() <= 255

assert_equal(numpy.ndim(gray), 2)
assert numpy.ndim(gray) == 2

assert_equal(gray.shape, (11, 16))
assert gray.shape == (11, 16)


def test_imread_gray_alpha():
Expand All @@ -62,9 +62,9 @@ def test_imread_gray_alpha():

assert 200 < gray.max() <= 255

assert_equal(numpy.ndim(gray), 3)
assert numpy.ndim(gray) == 3

assert_equal(gray.shape, (50, 111, 2))
assert gray.shape == (50, 111, 2)


def test_imread_masked():
Expand All @@ -74,15 +74,15 @@ def test_imread_masked():

assert 200 < gray.max() <= 255

assert_equal(numpy.ndim(gray), 2)
assert numpy.ndim(gray) == 2

assert_equal(gray.shape, (50, 111))
assert gray.shape == (50, 111)

assert numpy.ma.is_masked(gray)

masked_count = gray.mask.sum()
assert 0 < masked_count < numpy.product(gray.shape)
assert_equal(masked_count, 1464)
assert masked_count == 1464


def test_imread_masked_no_alpha():
Expand All @@ -92,9 +92,9 @@ def test_imread_masked_no_alpha():

assert 200 < gray.max() <= 255

assert_equal(numpy.ndim(gray), 2)
assert numpy.ndim(gray) == 2

assert_equal(gray.shape, (11, 16))
assert gray.shape == (11, 16)

assert not numpy.ma.is_masked(gray)

Expand All @@ -111,7 +111,7 @@ def test_imread_against_scipy_ndimage():
for filename in all_test_images:
a = scipy.ndimage.imread(filename)
b = qimage2ndarray.imread(filename)
assert_equal(a.shape, b.shape)
assert a.shape == b.shape
assert numpy.all(a == b)

def test_imread_against_scipy_misc():
Expand All @@ -123,7 +123,7 @@ def test_imread_against_scipy_misc():
for filename in all_test_images:
a = scipy.misc.imread(filename)
b = qimage2ndarray.imread(filename)
assert_equal(a.shape, b.shape)
assert a.shape == b.shape
assert numpy.all(a == b)

def test_imread_against_matplotlib():
Expand All @@ -135,7 +135,7 @@ def test_imread_against_matplotlib():
for filename in all_test_images:
a = matplotlib.pyplot.imread(filename)
b = qimage2ndarray.imread(filename)
assert_equal(a.shape, b.shape)
assert a.shape == b.shape
if a.max() == 1.0: # strange MPL API: only the PNG has 0..1.0 range
a *= 255
assert numpy.all(numpy.abs(a - b) < 1e-8)
90 changes: 45 additions & 45 deletions test/test_qimageview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
from qimage2ndarray.dynqt import qt, QtGui
import sys, numpy

from nose.tools import raises, assert_equal
from nose.tools import raises
from compat import setNumColors, numBytes


def test_viewcreation():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGB32)
v = _qimageview(qimg)
assert_equal(v.shape, (240, 320))
assert v.shape == (240, 320)
assert v.base is not None
del qimg
if hasattr(v.base, 'width'):
w, h = v.base.width(), v.base.height() # should not segfault
assert_equal((w, h), (320, 240))
assert (w, h) == (320, 240)
v[239] = numpy.arange(320) # should not segfault

@raises(TypeError)
Expand All @@ -35,19 +35,19 @@ def test_data_access():
setNumColors(qimg, 256)
qimg.fill(42)
v = _qimageview(qimg)
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 42)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 42
assert v.nbytes == numBytes(qimg)

def test_being_view():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_Indexed8)
setNumColors(qimg, 256)
qimg.fill(23)
v = _qimageview(qimg)
qimg.fill(42)
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 42)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 42
assert v.nbytes == numBytes(qimg)

def test_coordinate_access():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_Indexed8)
Expand All @@ -56,99 +56,99 @@ def test_coordinate_access():
v = _qimageview(qimg)
qimg.fill(23)
qimg.setPixel(12, 10, 42)
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 23)
assert_equal(v[10,12], 42)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 23
assert v[10,12] == 42
assert v.nbytes == numBytes(qimg)

def test_RGB32():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGB32)
qimg.fill(0)
v = _qimageview(qimg)
qimg.fill(23)
qimg.setPixel(12, 10, QtGui.qRgb(0x12,0x34,0x56))
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 23 | 0xff000000)
assert_equal(v[10,12], 0xff123456 if sys.byteorder == 'little' else 0x563412ff)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 23 | 0xff000000
assert v[10,12] == 0xff123456 if sys.byteorder == 'little' else 0x563412ff
assert v.nbytes == numBytes(qimg)

def test_ARGB32():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_ARGB32)
qimg.fill(0)
v = _qimageview(qimg)
qimg.setPixel(12, 10, QtGui.qRgb(0x12,0x34,0x56))
assert_equal(v.shape, (240, 320))
assert_equal(v[10,12], 0xff123456 if sys.byteorder == 'little' else 0x563412ff)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,12] == 0xff123456 if sys.byteorder == 'little' else 0x563412ff
assert v.nbytes == numBytes(qimg)

def test_RGBX8888():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGBX8888)
qimg.fill(0)
v = _qimageview(qimg)
qimg.fill(23)
qimg.setPixel(12, 10, QtGui.qRgb(0x12,0x34,0x56))
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 23 | 0xff000000)
assert_equal(v[10,12], 0x123456ff if sys.byteorder == 'big' else 0xff563412)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 23 | 0xff000000
assert v[10,12] == 0x123456ff if sys.byteorder == 'big' else 0xff563412
assert v.nbytes == numBytes(qimg)

def test_RGBA8888():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGBA8888)
qimg.fill(0)
v = _qimageview(qimg)
qimg.setPixel(12, 10, QtGui.qRgb(0x12,0x34,0x56))
assert_equal(v.shape, (240, 320))
assert_equal(v[10,12], 0x123456ff if sys.byteorder == 'big' else 0xff563412)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,12] == 0x123456ff if sys.byteorder == 'big' else 0xff563412
assert v.nbytes == numBytes(qimg)

def test_RGBX64():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGBX64)
qimg.fill(QtGui.qRgb(0, 0, 0))
v = _qimageview(qimg)
qimg.setPixel(12, 10, QtGui.qRgb(0x12,0x34,0x56))
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 0xffff000000000000 if sys.byteorder == 'little' else 0xffff)
assert_equal(v[10,12], 0xffff565634341212 if sys.byteorder == 'little' else 0x121234345656ffff)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 0xffff000000000000 if sys.byteorder == 'little' else 0xffff
assert v[10,12] == 0xffff565634341212 if sys.byteorder == 'little' else 0x121234345656ffff
assert v.nbytes == numBytes(qimg)

def test_RGBA64():
qimg = QtGui.QImage(320, 240, QtGui.QImage.Format_RGBX64)
qimg.fill(0)
v = _qimageview(qimg)
qimg.setPixel(12, 10, QtGui.qRgb(0x12,0x34,0x56))
assert_equal(v.shape, (240, 320))
assert_equal(v[10,10], 0)
assert_equal(v[10,12], 0xffff565634341212 if sys.byteorder == 'little' else 0x121234345656ffff)
assert_equal(v.nbytes, numBytes(qimg))
assert v.shape == (240, 320)
assert v[10,10] == 0
assert v[10,12] == 0xffff565634341212 if sys.byteorder == 'little' else 0x121234345656ffff
assert v.nbytes == numBytes(qimg)

def test_odd_size_8bit():
qimg = QtGui.QImage(321, 240, QtGui.QImage.Format_Indexed8)
setNumColors(qimg, 256)
qimg.fill(0)
v = _qimageview(qimg)
qimg.setPixel(12, 10, 42)
assert_equal(v.shape, (240, 321))
assert_equal(v[10,12], 42)
assert_equal(v.strides[0], qimg.bytesPerLine())
assert v.shape == (240, 321)
assert v[10,12] == 42
assert v.strides[0] == qimg.bytesPerLine()

def test_odd_size_32bit():
qimg = QtGui.QImage(321, 240, QtGui.QImage.Format_ARGB32)
qimg.fill(0)
v = _qimageview(qimg)
qimg.setPixel(12, 10, 42)
assert_equal(v.shape, (240, 321))
assert_equal(v[10,12], 42)
assert_equal(v.strides[0], qimg.bytesPerLine())
assert v.shape == (240, 321)
assert v[10,12] == 42
assert v.strides[0] == qimg.bytesPerLine()

def test_odd_size_32bit_rgb():
qimg = QtGui.QImage(321, 240, QtGui.QImage.Format_RGB32)
qimg.fill(0)
v = _qimageview(qimg)
qimg.setPixel(12, 10, 42)
assert_equal(v.shape, (240, 321))
assert_equal(v[10,12], 42 | 0xff000000)
assert_equal(v.strides[0], qimg.bytesPerLine())
assert_equal(v.strides[1], 4)
assert v.shape == (240, 321)
assert v[10,12] == 42 | 0xff000000
assert v.strides[0] == qimg.bytesPerLine()
assert v.strides[1] == 4

@raises(ValueError)
def test_mono():
Expand Down

0 comments on commit 4f9af2a

Please sign in to comment.