From df3781a13f7e30bf0829cc2942381c11ca55cd1f Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 27 Jul 2021 17:42:09 +0300 Subject: [PATCH] A rudimentary test case for qidenticon --- src/tests/test_identicon.py | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/tests/test_identicon.py diff --git a/src/tests/test_identicon.py b/src/tests/test_identicon.py new file mode 100644 index 00000000..4c6be32d --- /dev/null +++ b/src/tests/test_identicon.py @@ -0,0 +1,49 @@ +"""Tests for qidenticon""" + +import atexit +import unittest + +try: + from PyQt5 import QtGui, QtWidgets + from xvfbwrapper import Xvfb + from pybitmessage import qidenticon +except ImportError: + Xvfb = None + # raise unittest.SkipTest( + # 'Skipping graphical test, because of no PyQt or xvfbwrapper') +else: + vdisplay = Xvfb(width=1024, height=768) + vdisplay.start() + atexit.register(vdisplay.stop) + + +sample_code = 0x3fd4bf901b9d4ea1394f0fb358725b28 +sample_size = 48 + + +@unittest.skipUnless( + Xvfb, 'Skipping graphical test, because of no PyQt or xvfbwrapper') +class TestIdenticon(unittest.TestCase): + """QIdenticon implementation test case""" + + @classmethod + def setUpClass(cls): + """Instantiate QtWidgets.QApplication""" + cls.app = QtWidgets.QApplication([]) + + def test_qidenticon_samples(self): + """Generate 4 qidenticon samples and check their properties""" + icon_simple = qidenticon.render_identicon(sample_code, sample_size) + self.assertIsInstance(icon_simple, QtGui.QPixmap) + self.assertEqual(icon_simple.height(), sample_size * 3) + self.assertEqual(icon_simple.width(), sample_size * 3) + self.assertFalse(icon_simple.hasAlphaChannel()) + + # icon_sample = QtGui.QPixmap() + # icon_sample.load('../images/qidenticon.png') + # self.assertFalse( + # icon_simple.toImage(), icon_sample.toImage()) + + icon_x = qidenticon.render_identicon( + sample_code, sample_size, opacity=0) + self.assertTrue(icon_x.hasAlphaChannel())