3 Commits

Author SHA1 Message Date
stalbe_j
ca2caad46c new tests from before 2023-04-13 14:49:04 +02:00
stalbe_j
b13b91e55b Merge branch 'tests' of gitlab.psi.ch:augustin_s/grum into tests 2023-03-14 14:53:45 +01:00
stalbe_j
7780281e0c Merge branch 'master' of gitlab.psi.ch:augustin_s/grum into tests 2023-02-06 13:34:23 +01:00
10 changed files with 68 additions and 105 deletions

View File

@@ -1,62 +1,29 @@
stages:
- Tests
- OptionalTests
.install-grum-test: &install-grum-test
- pip install pytest pytest-random-order pytest-cov
- pip install -e ./
- apt-get update
- apt-get install -y ffmpeg libnss3 libxcomposite1 libxtst6
- Test
tests:
stage: Tests
image: python:3.8
stage: Test
variables:
QT_QPA_PLATFORM: "offscreen"
XDG_RUNTIME_DIR: "/tmp/runtime-root"
PYTHONFAULTHANDLER: 1
script:
- *install-grum-test
- coverage run --source=./grum -m pytest ./tests --junitxml=report-junit.xml
- pip install pytest pytest-random-order pytest-cov
- pip install -e ./
- pip install PyQtWebEngine
- apt-get update
- apt-get install -y ffmpeg libnss3 libxcomposite1 libxtst6
# - python -m unittest discover -f ./tests
# - coverage run --source=./grum -m unittest discover -f ./tests
- coverage run --source=./grum -m pytest ./tests
- coverage report
- coverage xml
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
reports:
cobertura: coverage.xml
junit: report-junit.xml
tests-3.6:
stage: OptionalTests
image: python:3.6
needs: ["tests"]
allow_failure: true
variables:
QT_QPA_PLATFORM: "offscreen"
XDG_RUNTIME_DIR: "/tmp/runtime-root"
PYTHONFAULTHANDLER: 1
script:
- *install-grum-test
- pytest ./tests
tests-3.7:
extends: "tests-3.6"
image: python:3.7
#tests-3.8:
# extends: "tests-3.6"
# image: python:3.8
tests-3.9:
extends: "tests-3.6"
image: python:3.9
tests-3.10:
extends: "tests-3.6"
image: python:3.10
tests-3.11:
extends: "tests-3.6"
image: python:3.11

View File

@@ -86,8 +86,6 @@ class MainWindow(QMainWindow):
rst.start()
rst.server.register_function(self.new_plot)
rst.server.register_function(self.append_data)
rst.server.register_function(self.extend_data)
rst.server.register_function(self.set_data)
self.sig_make_new_plot.connect(self.on_make_new_plot)
@@ -118,27 +116,14 @@ class MainWindow(QMainWindow):
item = self.lst.get(name)
desc = item.value
desc.append(point)
self.sync_item_and_plots(item)
def extend_data(self, name, data):
"""
Extend the current data of the (existing) plot <name>.by <data>
The data is forwarded to the extend method of PlotDescription.
"""
item = self.lst.get(name)
desc = item.value
desc.extend(data)
self.sync_item_and_plots(item)
def set_data(self, name, data):
"""
Set <data> as the data of the (existing) plot <name>.
The data is assigned to the data attribute of PlotDescription.
"""
item = self.lst.get(name)
desc = item.value
desc.data = data
self.sync_item_and_plots(item)
alarm = True
for sub in self.mdi.subWindowList():
if name in sub.plots:
plot = sub.plots[name]
plot.setData(*desc.data)
alarm = False
item.timestamps.modification.update()
item.set_alarm(alarm)
# Signal callbacks
@@ -211,17 +196,6 @@ class MainWindow(QMainWindow):
self.lst.set(name, desc)
return desc
def sync_item_and_plots(self, item):
name, desc = item.key, item.value
alarm = True
for sub in self.mdi.subWindowList():
if name in sub.plots:
plot = sub.plots[name]
plot.setData(*desc.data)
alarm = False
item.timestamps.modification.update()
item.set_alarm(alarm)
def plot_single_item(self, item):
item.timestamps.access.update()
item.set_alarm(False)

View File

@@ -14,21 +14,12 @@ class PlotDescription:
def data(self):
return (self.xs, self.ys)
@data.setter
def data(self, value):
self.xs, self.ys = value
def append(self, xy):
x, y = xy
self.xs.append(x)
self.ys.append(y)
def extend(self, data):
xs, ys = data
self.xs.extend(xs)
self.ys.extend(ys)
def make_plot(self, plotwidget, style):
res = plotwidget.plot(self.xs, self.ys, name=self.name, **style)

View File

@@ -16,10 +16,4 @@ class RPCClient(xrc.ServerProxy):
return head + help
def __dir__(self):
d1 = super().__dir__()
d2 = self.utils.info().keys()
return [*d1, *d2]

View File

@@ -6,7 +6,7 @@ long_description = file: README.md
long_description_content_type = text/markdown
url = https://gitlab.psi.ch/augustin_s/grum
project_urls =
Bug Tracker = https://gitlab.psi.ch/augustin_s/grum/issues
Bug Tracker = https://gitlab.psi.ch/augustin_s/grum/issues
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
@@ -16,7 +16,7 @@ classifiers =
package_dir =
= .
packages = find:
python_requires = >=3.6
python_requires = >=3.8
[options.packages.find]
where = .

View File

@@ -2,7 +2,7 @@ from setuptools import setup
if __name__ == "__main__":
setup(
install_requires=["pyqt5", "pyqtgraph", "h5py", "PyQtWebEngine"],
install_requires=["pyqt5", "pyqtgraph", "h5py"],
entry_points={"console_scripts": ["grum=grum:main"]},
)

View File

@@ -0,0 +1,27 @@
from grum.dictlist.dictlistwidget import DictListWidget
from grum.menus.rclickmenu import RClickMenu
class DictListWidgetMock(DictListWidget):
def __init__(self) -> None:
self.items = {}
self.nkeep = None
def get_DictListWidgetMock():
return DictListWidgetMock()
# def test_defaults():
# dlw = get_DictListWidgetMock()
# assert dlw.items == {}
# assert dlw.nkeep == None
# def test_add_menu():
# dlw = get_DictListWidgetMock()
# dlw._add_menu()
# assert dlw.menu == RClickMenu(dlw)

View File

@@ -21,7 +21,6 @@ from grum.rpc import RPCServerThread
class TestMainWin:
def setup_method(self):
print("setup")
self.app = QApplication(sys.argv)
theme.apply(self.app)
# ctrl_c.setup(self.app)
@@ -30,10 +29,8 @@ class TestMainWin:
def teardown_method(self):
print("teardown")
self.mw.rst.wait_for_stop()
self.app.quit()
print("app quit called")
del self.mw
del self.app
@@ -167,6 +164,19 @@ class TestMainWin:
mw.on_plot_selected()
mw.plot_multiple_items.assert_called_once_with([sine_item, cosine_item])
def test_on_sort_by_name(self):
mw = self.mw
mw.lst = DictList()
mw.new_plot("bb", {})
mw.new_plot("dd", {})
mw.new_plot("aa", {})
mw.new_plot("cc", {})
assert mw.lst.lst.items == 111
assert [key for key in mw.lst.lst.items.keys()] == ['bb', 'dd', 'aa', 'cc']
mw.on_sort_by_name()
assert mw.lst.lst.items == 111
def test_plot_single_item(self):
mw = self.mw

View File

@@ -15,13 +15,13 @@ class TestMDIArea:
def setup_method(self):
print("setup")
self.app = QApplication(sys.argv)
self.mw = MainWindow(add_examples=True, offline=True)
self.mw = MainWindow(add_examples=True)
self.mw.show()
def teardown_method(self):
print("teardown")
# self.mw.rst.wait_for_stop()
self.mw.rst.wait_for_stop()
self.app.quit()
print("app quit called")
del self.mw

View File

@@ -53,7 +53,7 @@ def test_make_plot():
)
app = QApplication(sys.argv)
theme.apply(app)
mw = MainWindow(add_examples=True, offline=True)
mw = MainWindow(add_examples=True)
mdi_sub = MDISubPlot("mdi", pd)
pw = pg.PlotWidget()