|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# ----------------------------------------------------------------------------- |
| 3 | +# Copyright © QtAppUtils Project Contributors |
| 4 | +# https://github.com/jnsebgosselin/qtapputils |
| 5 | +# |
| 6 | +# This file is part of QtAppUtils. |
| 7 | +# Licensed under the terms of the MIT License. |
| 8 | +# ----------------------------------------------------------------------------- |
| 9 | + |
| 10 | +""" |
| 11 | +Tests for the statusbar.py module. |
| 12 | +""" |
| 13 | + |
| 14 | +# ---- Third party imports |
| 15 | +import pytest |
| 16 | + |
| 17 | +# ---- Local imports |
| 18 | +from qtapputils.widgets.statusbar import ProcessStatusBar |
| 19 | + |
| 20 | +ACTIONS = ['Action #{}'.format(i) for i in range(3)] |
| 21 | + |
| 22 | + |
| 23 | +# ============================================================================= |
| 24 | +# ---- Fixtures |
| 25 | +# ============================================================================= |
| 26 | +@pytest.fixture |
| 27 | +def pstatusbar(qtbot): |
| 28 | + pstatusbar = ProcessStatusBar() |
| 29 | + qtbot.addWidget(pstatusbar) |
| 30 | + |
| 31 | + assert pstatusbar.status == pstatusbar.HIDDEN |
| 32 | + assert not pstatusbar._spinner._isSpinning |
| 33 | + assert not pstatusbar._spinner.isVisible() |
| 34 | + for icon in pstatusbar._icons.values(): |
| 35 | + assert not icon.isVisible() |
| 36 | + assert pstatusbar._label.text() == '' |
| 37 | + |
| 38 | + return pstatusbar |
| 39 | + |
| 40 | + |
| 41 | +# ============================================================================= |
| 42 | +# ---- Tests for the ProcessStatusBar |
| 43 | +# ============================================================================= |
| 44 | +def test_pstatusbar_showhide(pstatusbar): |
| 45 | + """Test the process status bar show/hide interface.""" |
| 46 | + |
| 47 | + # Show the progress status bar. |
| 48 | + pstatusbar.show(message='test in progess') |
| 49 | + assert pstatusbar.status == pstatusbar.IN_PROGRESS |
| 50 | + assert pstatusbar._spinner._isSpinning |
| 51 | + assert pstatusbar._spinner.isVisible() |
| 52 | + for icon in pstatusbar._icons.values(): |
| 53 | + assert not icon.isVisible() |
| 54 | + assert pstatusbar._label.text() == 'test in progess' |
| 55 | + |
| 56 | + # Hide the progress status bar. |
| 57 | + pstatusbar.hide() |
| 58 | + assert not pstatusbar._spinner._isSpinning |
| 59 | + assert not pstatusbar._spinner.isVisible() |
| 60 | + for icon in pstatusbar._icons.values(): |
| 61 | + assert not icon.isVisible() |
| 62 | + |
| 63 | + |
| 64 | +def test_pstatusbar_fail_success_update(pstatusbar): |
| 65 | + """ |
| 66 | + Test the process status bar interface to show icons is working |
| 67 | + as expected. |
| 68 | + """ |
| 69 | + # Show the progress status bar. |
| 70 | + pstatusbar.show('test is spinning') |
| 71 | + assert pstatusbar._spinner._isSpinning |
| 72 | + assert pstatusbar._spinner.isVisible() |
| 73 | + assert pstatusbar._label.text() == 'test is spinning' |
| 74 | + for icon in pstatusbar._icons.values(): |
| 75 | + assert not icon.isVisible() |
| 76 | + |
| 77 | + # Show the failed icon and message. |
| 78 | + pstatusbar.show_fail_icon('test fail icon') |
| 79 | + assert pstatusbar.status == pstatusbar.PROCESS_FAILED |
| 80 | + assert not pstatusbar._spinner._isSpinning |
| 81 | + assert not pstatusbar._spinner.isVisible() |
| 82 | + assert pstatusbar._icons['failed'].isVisible() |
| 83 | + assert not pstatusbar._icons['success'].isVisible() |
| 84 | + assert not pstatusbar._icons['update'].isVisible() |
| 85 | + assert pstatusbar._label.text() == 'test fail icon' |
| 86 | + |
| 87 | + # Show the progress status bar again. |
| 88 | + pstatusbar.show('test is spinning') |
| 89 | + assert pstatusbar._spinner._isSpinning |
| 90 | + assert pstatusbar._spinner.isVisible() |
| 91 | + assert pstatusbar._label.text() == 'test is spinning' |
| 92 | + for icon in pstatusbar._icons.values(): |
| 93 | + assert not icon.isVisible() |
| 94 | + |
| 95 | + # Show the success icon and message. |
| 96 | + pstatusbar.show_sucess_icon('test success icon') |
| 97 | + assert pstatusbar.status == pstatusbar.PROCESS_SUCCEEDED |
| 98 | + assert not pstatusbar._spinner._isSpinning |
| 99 | + assert not pstatusbar._spinner.isVisible() |
| 100 | + assert not pstatusbar._icons['failed'].isVisible() |
| 101 | + assert pstatusbar._icons['success'].isVisible() |
| 102 | + assert not pstatusbar._icons['update'].isVisible() |
| 103 | + assert pstatusbar._label.text() == 'test success icon' |
| 104 | + |
| 105 | + # Show the progress status bar again. |
| 106 | + pstatusbar.show('test is spinning') |
| 107 | + assert pstatusbar._spinner._isSpinning |
| 108 | + assert pstatusbar._spinner.isVisible() |
| 109 | + assert pstatusbar._label.text() == 'test is spinning' |
| 110 | + for icon in pstatusbar._icons.values(): |
| 111 | + assert not icon.isVisible() |
| 112 | + |
| 113 | + # Show the update icon and message. |
| 114 | + pstatusbar.show_update_icon('test update icon') |
| 115 | + assert pstatusbar.status == pstatusbar.NEED_UPDATE |
| 116 | + assert not pstatusbar._spinner._isSpinning |
| 117 | + assert not pstatusbar._spinner.isVisible() |
| 118 | + assert not pstatusbar._icons['failed'].isVisible() |
| 119 | + assert not pstatusbar._icons['success'].isVisible() |
| 120 | + assert pstatusbar._icons['update'].isVisible() |
| 121 | + assert pstatusbar._label.text() == 'test update icon' |
| 122 | + |
| 123 | + |
| 124 | +if __name__ == "__main__": |
| 125 | + pytest.main(['-x', __file__, '-v', '-rw']) |
0 commit comments