-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from BNL-ATF/fix-timeout-processing-with-tests
Fix timeout processing + tests
- Loading branch information
Showing
4 changed files
with
68 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from ._version import get_versions | ||
from .utils import configure_logger, logger # noqa F401 | ||
|
||
__version__ = get_versions()["version"] | ||
del get_versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
from atfdb.ophyd import ATFSignalNoConn | ||
import pytest | ||
|
||
from atfdb.ophyd import ATFSignalNoConn, TimeoutException | ||
from atfdb.utils import configure_logger, logger | ||
|
||
|
||
def test_ophyd_atfsignal_never_sets(socket_server): | ||
test1 = ATFSignalNoConn(psname="test1", db="test", name="test1", tol=0.0, timeout=2.0) | ||
print(f"{test1.get() = }") | ||
print(f"{test1.read() = }") | ||
|
||
configure_logger(logger=logger) | ||
with pytest.raises(TimeoutException) as excinfo: | ||
test1.put(1) | ||
|
||
excinfo_value = excinfo.exconly() | ||
assert "ophyd object has not reached the setpoint" in excinfo_value, excinfo_value | ||
print(excinfo_value) | ||
|
||
print(f"{test1.get() = }") | ||
|
||
|
||
def test_ophyd_atfsignal(socket_server): | ||
test = ATFSignalNoConn(psname="test", db="test", name="test") | ||
print(test.get()) | ||
print(test.read()) | ||
test.put(1) | ||
print(test.get()) | ||
test2 = ATFSignalNoConn(psname="test2", db="test2", name="test2", tol=0.25, timeout=2.0) | ||
print(f"{test2.get() = }") | ||
print(f"{test2.read() = }") | ||
test2.put(1) | ||
print(f"{test2.get() = }") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import logging | ||
from logging import StreamHandler | ||
|
||
logger = logging.getLogger("atfdb") | ||
|
||
|
||
def configure_logger(logger, log_level=logging.DEBUG, handlers=[StreamHandler]): | ||
log_file_format = "[%(levelname)1.1s %(asctime)s %(name)s %(module)s:%(lineno)d] %(message)s" | ||
logger.setLevel(log_level) | ||
|
||
if logger.hasHandlers(): | ||
logger.handlers.clear() | ||
|
||
for handler_class in handlers: | ||
handler = handler_class() | ||
handler.setFormatter(logging.Formatter(fmt=log_file_format)) | ||
logger.addHandler(handler) | ||
handler.setLevel(log_level) |