diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 4a82bf6..a1ba63c 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -18,22 +18,22 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.10 - uses: actions/setup-python@v3 - with: - python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics - # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics - - name: Test with pytest - run: | - python -m unittest discover . + - uses: actions/checkout@v3 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + QT_QPA_PLATFORM=offscreen python -m unittest discover . diff --git a/tests/test_gui_machine.py b/tests/test_gui_machine.py index 17b72f0..7b7f55b 100644 --- a/tests/test_gui_machine.py +++ b/tests/test_gui_machine.py @@ -4,20 +4,28 @@ from PyQt5.QtWidgets import QApplication -from tests.utils import mock_func, make_mock_pv, test_setup +from tests.utils import mock_func, make_mock_pv, test_setup, MockPyDMWidget +# TODO figure out a cleaner way to do this with mock.patch("epics.camonitor", mock_func): - with mock.patch("pydm.PyDMChannel", mock.MagicMock()): - from frontend.gui_machine import GUIMachine + with mock.patch("pydm.widgets.PyDMLabel", MockPyDMWidget): + with mock.patch( + "pydm.widgets.analog_indicator.PyDMAnalogIndicator", MockPyDMWidget + ): + with mock.patch("pydm.widgets.base.widget_destroyed", mock_func): + from frontend.gui_machine import GUIMachine + + +app = QApplication(sys.argv) class TestGUI(TestCase): + def setUp(self) -> None: - self.app = QApplication(sys.argv) self.gui_machine = GUIMachine() def tearDown(self) -> None: - self.app.closeAllWindows() + app.closeAllWindows() class TestGUIMachine(TestGUI): diff --git a/tests/utils.py b/tests/utils.py index c52cd98..55bf93f 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,5 +1,7 @@ from unittest.mock import MagicMock +from PyQt5.QtWidgets import QWidget + from lcls_tools.common.controls.pyepics.utils import EPICS_NO_ALARM_VAL @@ -9,6 +11,17 @@ def mock_func(*args, **kwargs): print(f"mocking with {','.join([args_str, kwargs_str])}") +class MockPyDMWidget(QWidget): + def __init__(self, **kwargs): + super().__init__(parent=None) + + def setAlignment(self, *args): + pass + + def setWordWrap(self, *args): + pass + + def make_mock_pv( pv_name: str = None, get_val=None, severity=EPICS_NO_ALARM_VAL ) -> MagicMock: