1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
# SPDX-FileCopyrightText: All Contributors to the ITango project
# SPDX-License-Identifier: LGPL-3.0-or-later
import re
import tango
from IPython.utils.io import capture_output
def test_db_info(ipython_shell):
# db variable contains Database
with capture_output() as captured:
result = ipython_shell.run_cell("print(db.get_info())")
assert result.success
assert "Running since" in captured.stdout
assert "Devices defined =" in captured.stdout
assert "Device servers exported =" in captured.stdout
assert "Class properties defined =" in captured.stdout
def test_lsdev_magic(ipython_shell):
with capture_output() as captured:
result = ipython_shell.run_cell("lsdev")
assert result.success
assert result.result is None
assert (
re.search(r"sys/database/2\s*DataBaseds/2\s*DataBase", captured.stdout)
is not None
)
assert (
re.search(r"sys/tg_test/1\s*TangoTest/test\s*TangoTest", captured.stdout)
is not None
)
def test_lsdevclass_magic(ipython_shell):
with capture_output() as captured:
result = ipython_shell.run_cell("lsdevclass")
assert result.success
assert result.result is None
assert "sys/database/2" not in captured.stdout
assert "DataBase" in captured.stdout
assert "TangoTest" in captured.stdout
def test_lsserv_magic(ipython_shell):
with capture_output() as captured:
result = ipython_shell.run_cell("lsserv")
assert result.success
assert result.result is None
assert "sys/database/2" not in captured.stdout
assert "DataBaseds/2" in captured.stdout
assert "TangoTest/test" in captured.stdout
def test_device_proxy(ipython_shell):
# DeviceProxy imported and available
result = ipython_shell.run_cell("DeviceProxy('sys/tg_test/1').State()")
assert result.success
assert result.result == tango.DevState.RUNNING
def test_device(ipython_shell):
# Device is equivalent to DeviceProxy
result = ipython_shell.run_cell("Device('sys/tg_test/1').State()")
assert result.success
assert result.result == tango.DevState.RUNNING
def test_tango_test_class(ipython_shell):
# TangoTest can be used as DeviceProxy
result = ipython_shell.run_cell("TangoTest('sys/tg_test/1').Status()")
assert result.success
assert result.result == "The device is in RUNNING state."
def test_dev_not_found(ipython_shell):
with capture_output() as captured:
result = ipython_shell.run_cell("Device('sys/tg_test/2').state()")
assert not result.success
assert "device sys/tg_test/2 not defined in the database" in captured.stdout
def test_dev_not_exported(ipython_shell):
with capture_output() as captured:
result = ipython_shell.run_cell("Device('sys/access_control/1').state()")
assert not result.success
assert "Device sys/access_control/1 is not exported" in captured.stdout
def test_refreshdb_magic(ipython_shell):
device_name = "sys/tg_test/2"
# Add a new device to the database
db = tango.Database()
dev_info = tango.DbDevInfo()
dev_info.name = device_name
dev_info._class = "TangoTest"
dev_info.server = "TangoTest/test"
db.add_device(dev_info)
try:
# device was added after itango was loaded - it's not in cache
with capture_output() as captured:
ipython_shell.run_cell("lsdev")
assert device_name not in captured.stdout
# Run refreshdb
ipython_shell.run_cell("refreshdb")
# new device is now listed
with capture_output() as captured:
ipython_shell.run_cell("lsdev")
assert device_name in captured.stdout
finally:
# Cleaning
db.delete_device(device_name)
|