|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +"""QGIS Unit tests for QgsProcessingRecentAlgorithmLog. |
| 3 | +
|
| 4 | +.. note:: This program is free software; you can redistribute it and/or modify |
| 5 | +it under the terms of the GNU General Public License as published by |
| 6 | +the Free Software Foundation; either version 2 of the License, or |
| 7 | +(at your option) any later version. |
| 8 | +""" |
| 9 | +__author__ = 'Nyall Dawson' |
| 10 | +__date__ = '2018-07' |
| 11 | +__copyright__ = 'Copyright 2018, The QGIS Project' |
| 12 | +# This will get replaced with a git SHA1 when you do a git archive |
| 13 | +__revision__ = '$Format:%H$' |
| 14 | + |
| 15 | +from qgis.PyQt.QtCore import QCoreApplication |
| 16 | +from qgis.core import QgsSettings |
| 17 | +from qgis.gui import QgsProcessingRecentAlgorithmLog, QgsGui |
| 18 | +from qgis.testing import start_app, unittest |
| 19 | +from qgis.PyQt.QtTest import QSignalSpy |
| 20 | + |
| 21 | +start_app() |
| 22 | + |
| 23 | + |
| 24 | +class TestQgsProcessingRecentAlgorithmLog(unittest.TestCase): |
| 25 | + |
| 26 | + @classmethod |
| 27 | + def setUpClass(cls): |
| 28 | + """Run before all tests""" |
| 29 | + QCoreApplication.setOrganizationName("QGIS_Test") |
| 30 | + QCoreApplication.setOrganizationDomain("QGIS_TestPyQgsNewGeoPackageLayerDialog.com") |
| 31 | + QCoreApplication.setApplicationName("QGIS_TestPyQgsNewGeoPackageLayerDialog") |
| 32 | + QgsSettings().clear() |
| 33 | + |
| 34 | + def test_log(self): |
| 35 | + log = QgsProcessingRecentAlgorithmLog() |
| 36 | + self.assertFalse(log.recentAlgorithmIds()) |
| 37 | + spy = QSignalSpy(log.changed) |
| 38 | + |
| 39 | + log.push('test') |
| 40 | + self.assertEqual(log.recentAlgorithmIds(), ['test']) |
| 41 | + self.assertEqual(len(spy), 1) |
| 42 | + log.push('test') |
| 43 | + self.assertEqual(log.recentAlgorithmIds(), ['test']) |
| 44 | + self.assertEqual(len(spy), 1) |
| 45 | + |
| 46 | + log.push('test2') |
| 47 | + self.assertEqual(log.recentAlgorithmIds(), ['test2', 'test']) |
| 48 | + self.assertEqual(len(spy), 2) |
| 49 | + |
| 50 | + log.push('test') |
| 51 | + self.assertEqual(log.recentAlgorithmIds(), ['test', 'test2']) |
| 52 | + self.assertEqual(len(spy), 3) |
| 53 | + |
| 54 | + log.push('test3') |
| 55 | + self.assertEqual(log.recentAlgorithmIds(), ['test3', 'test', 'test2']) |
| 56 | + self.assertEqual(len(spy), 4) |
| 57 | + |
| 58 | + log.push('test4') |
| 59 | + self.assertEqual(log.recentAlgorithmIds(), ['test4', 'test3', 'test', 'test2']) |
| 60 | + self.assertEqual(len(spy), 5) |
| 61 | + |
| 62 | + log.push('test5') |
| 63 | + self.assertEqual(log.recentAlgorithmIds(), ['test5', 'test4', 'test3', 'test', 'test2']) |
| 64 | + self.assertEqual(len(spy), 6) |
| 65 | + |
| 66 | + log.push('test6') |
| 67 | + self.assertEqual(log.recentAlgorithmIds(), ['test6', 'test5', 'test4', 'test3', 'test']) |
| 68 | + self.assertEqual(len(spy), 7) |
| 69 | + |
| 70 | + log.push('test3') |
| 71 | + self.assertEqual(log.recentAlgorithmIds(), ['test3', 'test6', 'test5', 'test4', 'test']) |
| 72 | + self.assertEqual(len(spy), 8) |
| 73 | + |
| 74 | + log.push('test3') |
| 75 | + self.assertEqual(log.recentAlgorithmIds(), ['test3', 'test6', 'test5', 'test4', 'test']) |
| 76 | + self.assertEqual(len(spy), 8) |
| 77 | + |
| 78 | + # test that log has been saved to QgsSettings |
| 79 | + log2 = QgsProcessingRecentAlgorithmLog() |
| 80 | + self.assertEqual(log2.recentAlgorithmIds(), ['test3', 'test6', 'test5', 'test4', 'test']) |
| 81 | + |
| 82 | + def test_gui_instance(self): |
| 83 | + self.assertIsNotNone(QgsGui.instance().processingRecentAlgorithmLog()) |
| 84 | + |
| 85 | + |
| 86 | +if __name__ == '__main__': |
| 87 | + unittest.main() |
0 commit comments