Commit 89e298e9 authored by Samuel Jones's avatar Samuel Jones
Browse files

Improve testability and test the memory view

parent 3ba2876d
......@@ -7,8 +7,8 @@
# This file is part of the mantid workbench.
#
from qtpy.QtWidgets import QWidget, QProgressBar
from qtpy.QtCore import Qt, QMetaObject, Q_ARG
from PyQt5.QtCore import pyqtSlot
from qtpy.QtCore import Qt
from PyQt5.QtCore import pyqtSlot, pyqtSignal
NORMAL_STYLE = """
QProgressBar::chunk {
......@@ -48,15 +48,16 @@ def from_critical_to_normal(critical: int, current_value: int, new_value: int) -
class MemoryView(QWidget):
set_value = pyqtSignal(int, float, float)
"""
Initializes and updates the view of memory(progress) bar.
"""
def __init__(self, parent):
super(MemoryView, self).__init__(parent)
self.critical = CRITICAL_PERCENTAGE
self.memory_bar = QProgressBar(self)
self.memory_bar.setAlignment(Qt.AlignCenter)
self.set_value.connect(self._set_value)
def set_bar_color(self, current_value: int, new_value: int):
"""
......@@ -72,10 +73,7 @@ class MemoryView(QWidget):
pass
def invoke_set_value(self, new_value: int, mem_used: float, mem_avail: float):
new_value = Q_ARG(int, new_value)
mem_used = Q_ARG(float, mem_used)
mem_avail = Q_ARG(float, mem_avail)
QMetaObject.invokeMethod(self, "_set_value", Qt.AutoConnection, new_value, mem_used, mem_avail)
self.set_value.emit(new_value, mem_used, mem_avail)
@pyqtSlot(int, float, float)
def _set_value(self, new_value, mem_used, mem_avail):
......
......@@ -31,7 +31,7 @@ class MemoryPresenterTest(unittest.TestCase):
self.view.memory_bar = mock.Mock()
self.view.memory_bar.value.return_value = 0
self.view.set_bar_color = mock.Mock()
self.view.set_value = mock.Mock()
self.view.invoke_set_value = mock.Mock()
def test_presenter(self):
self.presenter.cancel_memory_update()
......@@ -45,7 +45,7 @@ class MemoryPresenterTest(unittest.TestCase):
def test_memory_usage_is_updated_based_on_a_constant(self):
# Sleep for just longer than the default so the test can run
time.sleep(TIME_INTERVAL_MEMORY_USAGE_UPDATE + 0.5)
self.assertGreater(self.view.set_value.call_count, 1)
self.assertGreater(self.view.invoke_set_value.call_count, 1)
if __name__ == "__main__":
......
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2021 ISIS Rutherford Appleton Laboratory UKRI,
# NScD Oak Ridge National Laboratory, European Spallation Source,
# Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
import unittest
from unittest import mock
from mantidqt.utils.qt.testing import start_qapplication
from mantidqt.utils.qt.testing.qt_assertions_helper import QtAssertionsHelper
from mantidqt.widgets.memorywidget.memoryview import MemoryView
@start_qapplication
class MemoryViewTest(unittest.TestCase, QtAssertionsHelper):
def setUp(self):
self.view = MemoryView(None)
def test_invoke_set_value_connects_slot_set_value(self):
self.assert_connected_once(self.view, self.view.set_value)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment