Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions trace/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import os
from os import getenv
from pathlib import Path
from unittest import mock

import numpy as np
import pytest
from qtpy.QtWidgets import QMenu

Expand All @@ -10,6 +12,34 @@
from main import TraceDisplay
from config import logger

os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")


@pytest.fixture
def make_curve():
"""Fixture providing a factory for curve mocks that behave like TimePlotCurveItem.

Returns
-------
A function make_curve(timestamps, values, min_x=None, max_x=None) that returns
a MagicMock with data_buffer, points_accumulated, min_x, max_x, address, and units
set from the given arguments.
"""

def _make_curve(timestamps, values, min_x=None, max_x=None):
ts = np.array(timestamps, dtype=float)
vals = np.array(values, dtype=float)
curve = mock.MagicMock()
curve.data_buffer = np.vstack([ts, vals])
curve.points_accumulated = len(ts)
curve.min_x.return_value = min_x if min_x is not None else (ts[0] if len(ts) else 0.0)
curve.max_x.return_value = max_x if max_x is not None else (ts[-1] if len(ts) else 0.0)
curve.address = "FAKE:PV"
curve.units = "eV"
return curve

return _make_curve


@pytest.fixture
def get_test_file():
Expand Down
Loading
Loading