diff --git a/test/Makefile.am b/test/Makefile.am index 0d1613f0..4992e87e 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -10,11 +10,12 @@ EXTRA_DIST = \ test_python.sh test_arithmetic.py \ test_colour.py \ + test_conversion.py \ + test_convolution.py \ test_create.py \ test_draw.py \ - test_cum.py \ - test_convolution.py \ - test_conversion.py + test_histogram.py \ + test_morphology.py # don't run test_thumbnail.sh by default, it takes ages diff --git a/test/test_morphology.py b/test/test_morphology.py new file mode 100755 index 00000000..2a2a9c40 --- /dev/null +++ b/test/test_morphology.py @@ -0,0 +1,51 @@ +#!/usr/bin/python + +import unittest +import math + +#import logging +#logging.basicConfig(level = logging.DEBUG) + +from gi.repository import Vips + +# an expanding zip ... if either of the args is a scalar or a one-element list, +# duplicate it down the other side +def zip_expand(x, y): + # handle singleton list case + if isinstance(x, list) and len(x) == 1: + x = x[0] + if isinstance(y, list) and len(y) == 1: + y = y[0] + + if isinstance(x, list) and isinstance(y, list): + return list(zip(x, y)) + elif isinstance(x, list): + return [[i, y] for i in x] + elif isinstance(y, list): + return [[x, j] for j in y] + else: + return [[x, y]] + +class TestMorphology(unittest.TestCase): + # test a pair of things which can be lists for approx. equality + def assertAlmostEqualObjects(self, a, b, places = 4, msg = ''): + # print 'assertAlmostEqualObjects %s = %s' % (a, b) + for x, y in zip_expand(a, b): + self.assertAlmostEqual(x, y, places = places, msg = msg) + + def test_countlines(self): + im = Vips.Image.black(100, 100) + im = im.draw_line(255, 0, 50, 100, 50) + n_lines = im.countlines(Vips.Direction.HORIZONTAL) + self.assertEqual(n_lines, 1) + + def test_labelregions(self): + im = Vips.Image.black(100, 100) + im = im.draw_circle(255, 50, 50, 25, fill = True) + mask, opts = im.labelregions(segments = True) + + self.assertEqual(opts['segments'], 3) + self.assertEqual(mask.max(), 2) + +if __name__ == '__main__': + unittest.main() diff --git a/test/test_python.sh b/test/test_python.sh index 699c3db7..7d45aa66 100755 --- a/test/test_python.sh +++ b/test/test_python.sh @@ -17,6 +17,7 @@ python2 test_convolution.py python2 test_create.py python2 test_draw.py python2 test_histogram.py +python2 test_morphology.py echo "testing with python3 ..." @@ -27,3 +28,4 @@ python3 test_convolution.py python3 test_create.py python3 test_draw.py python3 test_histogram.py +python3 test_morphology.py