summaryrefslogtreecommitdiffstats
path: root/share/extensions/test
diff options
context:
space:
mode:
authorRichard White <rwhite8282@gmail.com>2016-05-19 01:17:29 +0000
committerRichard White <rwhite8282@gmail.com>2016-05-19 01:17:29 +0000
commit1fe9c2603c33fddcd9f2688b30e843f91e1a86fa (patch)
tree13289cbe033a46a40eb829437e115b5393e2ca84 /share/extensions/test
parentCorrected frame extension stroke and fill values on 64 bit machine. (diff)
parentGTK3: Another widget named. (diff)
downloadinkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.tar.gz
inkscape-1fe9c2603c33fddcd9f2688b30e843f91e1a86fa.zip
Merge from Inkscape trunk.
(bzr r14668.1.3)
Diffstat (limited to 'share/extensions/test')
-rw-r--r--share/extensions/test/Makefile.am1
-rwxr-xr-xshare/extensions/test/color_randomize.test.py123
-rwxr-xr-xshare/extensions/test/run-all-extension-tests20
3 files changed, 138 insertions, 6 deletions
diff --git a/share/extensions/test/Makefile.am b/share/extensions/test/Makefile.am
index 7ff68083d..cd1929a7f 100644
--- a/share/extensions/test/Makefile.am
+++ b/share/extensions/test/Makefile.am
@@ -6,6 +6,7 @@
EXTRA_DIST = \
addnodes.test.py \
chardataeffect.test.py \
+ color_randomize_test.py \
coloreffect.test.py \
create_test_from_template.sh \
dots.test.py \
diff --git a/share/extensions/test/color_randomize.test.py b/share/extensions/test/color_randomize.test.py
new file mode 100755
index 000000000..d8549a35a
--- /dev/null
+++ b/share/extensions/test/color_randomize.test.py
@@ -0,0 +1,123 @@
+#!/usr/bin/env python
+'''
+Unit test file for ../color_randomize.py
+--
+If you want to help, read the python unittest documentation:
+http://docs.python.org/library/unittest.html
+'''
+
+import os
+import sys
+import unittest
+
+sys.path.append('..') # this line allows to import the extension code
+from color_randomize import *
+
+def extract_hsl(e,rgb):
+ r = int(rgb[:2], 16)
+ g = int(rgb[2:4], 16)
+ b = int(rgb[4:6], 16)
+ return e.rgb_to_hsl(r/255.0, g/255.0, b/255.0)
+
+
+class ColorRandomizeBasicTest(unittest.TestCase):
+ def setUp(self):
+ self.e=C()
+
+ def test_default_values(self):
+ """ The default ranges are set to 0, and thus the color and opacity should not change. """
+ args = ['svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ col = self.e.colmod(128, 128, 255)
+ self.assertEqual("8080ff", col)
+ opac = self.e.opacmod(5)
+ self.assertEqual(5, opac)
+
+
+class ColorRandomizeColorModificationTest(unittest.TestCase):
+ def setUp(self):
+ self.e=C()
+
+ def test_no_change(self):
+ """ The user selected 0% values, and thus the color should not change. """
+ args = ['-y 0', '-t 0', '-m 0', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ col = self.e.colmod(128, 128, 255)
+ self.assertEqual("8080ff", col)
+
+ def test_random_hue(self):
+ """ Random hue only. Saturation and lightness not changed. """
+ args = ['-y 50','-t 0','-m 0','svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ hsl = extract_hsl(self.e, self.e.colmod(150, 100, 200))
+ self.assertEqual([0.47, 0.59], [round(hsl[1], 2), round(hsl[2], 2)])
+
+ @unittest.skip("Inaccurate convertion")
+ def test_random_lightness(self):
+ """ Random lightness only. Hue and saturation not changed. """
+ args = ['-y 0', '-t 0', '-m 50', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ hsl = extract_hsl(self.e, self.e.colmod(150, 100, 200))
+ # Lightness change also affects hue and saturation...
+ #self.assertEqual(0.75, round(hsl[0], 2))
+ #self.assertEqual(0.48, round(hsl[1], 2))
+
+ def test_random_saturation(self):
+ """ Random saturation only. Hue and lightness not changed. """
+ args = ['-y 0', '-t 50', '-m 0', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ hsl = extract_hsl(self.e, self.e.colmod(150, 100, 200))
+ self.assertEqual([0.75, 0.59], [round(hsl[0], 2), round(hsl[2], 2)])
+
+ def test_range_limits(self):
+ """ The maximum hsl values should be between 0 and 100% of their maximum """
+ args = ['-y 100', '-t 100', '-m 100', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ hsl = extract_hsl(self.e, self.e.colmod(156, 156, 156))
+ self.assertLessEqual([hsl[0], hsl[1], hsl[2]], [1, 1, 1])
+ self.assertGreaterEqual([hsl[0], hsl[1], hsl[2]], [0, 0, 0])
+
+
+class ColorRandomizeOpacityModificationTest(unittest.TestCase):
+ def setUp(self):
+ self.e=C()
+
+ def test_no_change(self):
+ """ The user selected 0% opacity range, and thus the opacity should not change. """
+ args = ['-o 0', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ opac = self.e.opacmod(0.15)
+ self.assertEqual(0.15, opac)
+
+ def test_range_min_limit(self):
+ """ The opacity value should be greater than 0 """
+ args = ['-o 100', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ opac = self.e.opacmod(0)
+ self.assertGreaterEqual(opac, "0")
+
+ def test_range_max_limit(self):
+ """ The opacity value should be lesser than 1 """
+ args = ['-o 100', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ opac = self.e.opacmod(1)
+ self.assertLessEqual(opac, "1")
+
+ def test_non_float_opacity(self):
+ """ Non-float opacity value not changed """
+ args = ['-o 100', 'svg/empty-SVG.svg']
+ self.e.affect(args, False)
+ opac = self.e.opacmod("toto")
+ self.assertLessEqual(opac, "toto")
+
+if __name__ == '__main__':
+ #unittest.main()
+ suite = unittest.TestLoader().loadTestsFromTestCase(ColorRandomizeBasicTest)
+ unittest.TextTestRunner(verbosity=2).run(suite)
+ suite = unittest.TestLoader().loadTestsFromTestCase(ColorRandomizeColorModificationTest)
+ unittest.TextTestRunner(verbosity=2).run(suite)
+ suite = unittest.TestLoader().loadTestsFromTestCase(ColorRandomizeOpacityModificationTest)
+ unittest.TextTestRunner(verbosity=2).run(suite)
+
+
+# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
diff --git a/share/extensions/test/run-all-extension-tests b/share/extensions/test/run-all-extension-tests
index aa20c8c7b..e7faf672a 100755
--- a/share/extensions/test/run-all-extension-tests
+++ b/share/extensions/test/run-all-extension-tests
@@ -35,24 +35,32 @@ has_py_coverage=false
py_cover_files=$( $MKTEMP )
failed_tests=$( $MKTEMP )
-if coverage.py -e >/dev/null 2>/dev/null; then
+if coverage.py erase >/dev/null 2>/dev/null; then
has_py_coverage=true
cover_py_cmd=coverage.py
else
- if coverage -e >/dev/null 2>/dev/null; then
+ if coverage erase >/dev/null 2>/dev/null; then
has_py_coverage=true
cover_py_cmd=coverage
+ else
+ if python-coverage erase >/dev/null 2>/dev/null; then
+ has_py_coverage=true
+ cover_py_cmd=python-coverage
+ fi
fi
fi
+if $has_py_coverage; then
+ echo -e "\nRunning tests with coverage"
+fi
#if $has_py_coverage; then
# $cover_py_cmd -e
#fi
function run_py_test() {
- echo -e "\n>> Testing $1"
+ echo -e "\n>>>>>> Testing $1 <<<<<<\n"
if $has_py_coverage; then
- if ! $cover_py_cmd -x "$1.test.py"; then
+ if ! $cover_py_cmd run -a "$1.test.py"; then
echo "$1" >> $failed_tests
fi
echo "../$1.py" >> $py_cover_files
@@ -77,7 +85,7 @@ else
SED_EXTENDED='sed -E' # BSD sed (e.g. on Mac OS X)
fi
-echo "sed regex command: $SED_EXTENDED"
+echo -e "sed regex command: $SED_EXTENDED\n"
# ---------------------------------------------------------------------
@@ -89,7 +97,7 @@ done
if $has_py_coverage; then
echo -e "\n>> Coverage Report:"
- cat $py_cover_files | xargs $cover_py_cmd -r
+ cat $py_cover_files | xargs $cover_py_cmd report
fi
fail=false