mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-01-16 05:56:50 +01:00
testing
This commit is contained in:
@@ -46,4 +46,7 @@ endforeach(FILE ${PYTHON_FILES})
|
||||
|
||||
configure_file( scripts/basic.py
|
||||
${CMAKE_BINARY_DIR}/basic.py
|
||||
)
|
||||
configure_file( scripts/test_virtual.py
|
||||
${CMAKE_BINARY_DIR}/test_virtual.py
|
||||
)
|
||||
33
python/scripts/test_virtual.py
Normal file
33
python/scripts/test_virtual.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import pytest
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
sys.path.append(os.path.join(os.getcwd(), 'bin'))
|
||||
from sls_detector import ExperimentalDetector
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def virtual_jf_detectors(request):
|
||||
print('Setting up virtual detectors')
|
||||
subprocess.run(["killall", "jungfrauDetectorServer_virtual"])
|
||||
virtual_jf_detectors = []
|
||||
virtual_jf_detectors.append(subprocess.Popen('bin/jungfrauDetectorServer_virtual'))
|
||||
time.sleep(5)
|
||||
def fin():
|
||||
print("Cleaning up virtual detectors")
|
||||
subprocess.run(["killall", "jungfrauDetectorServer_virtual"])
|
||||
|
||||
|
||||
|
||||
request.addfinalizer(fin)
|
||||
return virtual_jf_detectors # provide the fixture value
|
||||
|
||||
|
||||
def test_hostname(virtual_jf_detectors):
|
||||
d = ExperimentalDetector()
|
||||
d.hostname = 'localhost'
|
||||
assert d.hostname == 'localhost'
|
||||
|
||||
def test_fwversion(virtual_jf_detectors):
|
||||
d = ExperimentalDetector()
|
||||
assert d.detectorversion == 0 #Firmware of virtual detector
|
||||
@@ -1,4 +1,4 @@
|
||||
from _sls_detector import multiDetectorApi
|
||||
from _sls_detector import CppDetectorApi
|
||||
from _sls_detector import slsDetectorDefs
|
||||
|
||||
runStatus = slsDetectorDefs.runStatus
|
||||
@@ -35,20 +35,40 @@ def freeze(cls):
|
||||
|
||||
|
||||
@freeze
|
||||
class ExperimentalDetector(multiDetectorApi):
|
||||
class ExperimentalDetector(CppDetectorApi):
|
||||
"""
|
||||
This class is the base for detector specific
|
||||
interfaces. Most functions exists in two versions
|
||||
like the getExptime() function that uses the
|
||||
C++ API directly and the simplified exptime property.
|
||||
"""
|
||||
def __init__(self, multi_id = 0):
|
||||
|
||||
def __init__(self, multi_id=0):
|
||||
"""
|
||||
multi_id refers to the shared memory id of the
|
||||
slsDetectorPackage. Default value is 0.
|
||||
"""
|
||||
super().__init__(multi_id)
|
||||
|
||||
# CONFIGURATION
|
||||
|
||||
@property
|
||||
def hostname(self):
|
||||
return element_if_equal(self.getHostname())
|
||||
|
||||
@hostname.setter
|
||||
def hostname(self, hostnames):
|
||||
if isinstance(hostnames, str):
|
||||
hostnames = [hostnames]
|
||||
if isinstance(hostnames, list):
|
||||
self.setHostname(hostnames)
|
||||
else:
|
||||
raise ValueError("hostname needs to be string or list of strings")
|
||||
|
||||
@property
|
||||
def detectorversion(self):
|
||||
return element_if_equal(self.getFirmwareVersion())
|
||||
|
||||
# Acq
|
||||
@property
|
||||
def rx_status(self):
|
||||
@@ -95,7 +115,7 @@ class ExperimentalDetector(multiDetectorApi):
|
||||
|
||||
"""
|
||||
return self.getAcquiringFlag()
|
||||
|
||||
|
||||
@busy.setter
|
||||
def busy(self, value):
|
||||
self.setAcquiringFlag(value)
|
||||
@@ -129,7 +149,7 @@ class ExperimentalDetector(multiDetectorApi):
|
||||
@property
|
||||
def fpath(self):
|
||||
return element_if_equal(self.getFilePath())
|
||||
|
||||
|
||||
@fpath.setter
|
||||
def fpath(self, path):
|
||||
self.setFilePath(path)
|
||||
|
||||
@@ -8,25 +8,40 @@
|
||||
#include "typecaster.h"
|
||||
namespace py = pybind11;
|
||||
void init_experimental(py::module &m) {
|
||||
// Experimental API to use the multi directly and inherit from to reduce
|
||||
// code duplication need to investigate how to handle documentation
|
||||
using sls::Detector;
|
||||
using sls::Positions;
|
||||
py::class_<Detector> multiDetectorApi(m, "multiDetectorApi");
|
||||
multiDetectorApi
|
||||
py::class_<Detector> CppDetectorApi(m, "CppDetectorApi");
|
||||
CppDetectorApi
|
||||
.def(py::init<int>())
|
||||
|
||||
// Configuration
|
||||
.def("free", &Detector::freeSharedMemory)
|
||||
.def("freeSharedMemory", &Detector::freeSharedMemory)
|
||||
.def("loadConfig", &Detector::loadConfig)
|
||||
.def("loadParameters", &Detector::loadParameters)
|
||||
.def("getHostname", &Detector::getHostname, py::arg() = Positions{})
|
||||
.def("setHostname", &Detector::setHostname)
|
||||
.def("getShmId", &Detector::getShmId)
|
||||
.def("getFirmwareVersion", &Detector::getFirmwareVersion,
|
||||
py::arg() = Positions{})
|
||||
.def("getDetectorServerVersion", &Detector::getDetectorServerVersion,
|
||||
py::arg() = Positions{})
|
||||
.def("getSerialNumber", &Detector::getSerialNumber,
|
||||
py::arg() = Positions{})
|
||||
.def("getClientVersion", &Detector::getClientVersion)
|
||||
.def("getReceiverVersion", &Detector::getReceiverVersion,
|
||||
py::arg() = Positions{})
|
||||
.def("getDetectorType", &Detector::getDetectorType,
|
||||
py::arg() = Positions{})
|
||||
.def("size", &Detector::size)
|
||||
|
||||
|
||||
// Acq related
|
||||
.def("acquire", &Detector::acquire)
|
||||
.def("clearAcquiringFlag", &Detector::clearAcquiringFlag)
|
||||
.def("getReceiverStatus", &Detector::getReceiverStatus,
|
||||
py::arg() = Positions{})
|
||||
|
||||
// Configuration
|
||||
.def("free", &Detector::freeSharedMemory)
|
||||
.def("loadConfig", &Detector::loadConfig)
|
||||
.def("getHostname", &Detector::getHostname, py::arg() = Positions{})
|
||||
|
||||
// Bits and registers
|
||||
.def("setBit", &Detector::setBit, py::arg(), py::arg(),
|
||||
py::arg() = Positions{})
|
||||
@@ -42,9 +57,11 @@ void init_experimental(py::module &m) {
|
||||
|
||||
// File
|
||||
.def("getFileNamePrefix", &Detector::getFileNamePrefix)
|
||||
.def("setFileNamePrefix", &Detector::setFileNamePrefix, py::arg(),py::arg() = Positions{})
|
||||
.def("setFileNamePrefix", &Detector::setFileNamePrefix, py::arg(),
|
||||
py::arg() = Positions{})
|
||||
.def("getFilePath", &Detector::getFilePath)
|
||||
.def("setFilePath", &Detector::setFilePath, py::arg(),py::arg() = Positions{})
|
||||
.def("setFilePath", &Detector::setFilePath, py::arg(),
|
||||
py::arg() = Positions{})
|
||||
.def("setFileWrite", &Detector::setFileWrite, py::arg(),
|
||||
py::arg() = Positions{})
|
||||
.def("getFileWrite", &Detector::getFileWrite, py::arg() = Positions{})
|
||||
|
||||
Reference in New Issue
Block a user