Skip to content

Commit

Permalink
trying to mock pydm stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
lisazacarias committed May 24, 2024
1 parent 5ba2397 commit cdead38
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
18 changes: 13 additions & 5 deletions tests/test_gui_machine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 13 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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:
Expand Down

0 comments on commit cdead38

Please sign in to comment.