|
1 | 1 | import pytest |
2 | 2 | from pytest_mock import MockerFixture |
| 3 | +from tango import DevState |
3 | 4 | from tango._tango import AttrWriteType, CmdArgType |
4 | 5 |
|
| 6 | +from fastcs.attributes import AttrR |
5 | 7 | from fastcs.backends.tango.dsr import _collect_dev_attributes, _collect_dev_commands |
| 8 | +from fastcs.datatypes import Bool, Int |
6 | 9 |
|
7 | 10 |
|
8 | 11 | def test_collect_attributes(mapping): |
@@ -35,3 +38,70 @@ async def test_collect_commands(mapping, mocker: MockerFixture): |
35 | 38 | # Check that command is created and it can be called |
36 | 39 | assert list(commands.keys()) == ["Go"] |
37 | 40 | await commands["Go"](mocker.MagicMock()) |
| 41 | + |
| 42 | + |
| 43 | +class TestTangoDevice: |
| 44 | + def test_list_attributes(self, tango_context): |
| 45 | + assert list(tango_context.get_attribute_list()) == [ |
| 46 | + "BigEnum", |
| 47 | + "ReadBool", |
| 48 | + "ReadInt", |
| 49 | + "ReadWriteFloat", |
| 50 | + "ReadWriteInt", |
| 51 | + "StringEnum", |
| 52 | + "WriteBool", |
| 53 | + "State", |
| 54 | + "Status", |
| 55 | + ] |
| 56 | + |
| 57 | + def test_list_commands(self, tango_context): |
| 58 | + assert list(tango_context.get_command_list()) == [ |
| 59 | + "Go", |
| 60 | + "Init", |
| 61 | + "State", |
| 62 | + "Status", |
| 63 | + ] |
| 64 | + |
| 65 | + def test_read_int(self, tango_context): |
| 66 | + result = tango_context.read_attribute("ReadInt") |
| 67 | + assert result.value == AttrR(Int())._value |
| 68 | + |
| 69 | + def test_read_write_int(self, tango_context): |
| 70 | + expected = 42 |
| 71 | + tango_context.write_attribute("ReadWriteInt", expected) |
| 72 | + result = tango_context.read_attribute("ReadWriteInt") |
| 73 | + assert result.w_value == expected |
| 74 | + |
| 75 | + def test_read_write_float(self, tango_context): |
| 76 | + expected = 23.1 |
| 77 | + tango_context.write_attribute("ReadWriteFloat", expected) |
| 78 | + result = tango_context.read_attribute("ReadWriteFloat") |
| 79 | + assert result.w_value == expected |
| 80 | + |
| 81 | + def test_read_bool(self, tango_context): |
| 82 | + result = tango_context.read_attribute("ReadBool") |
| 83 | + assert result.value == AttrR(Bool())._value |
| 84 | + |
| 85 | + def test_write_bool(self, tango_context): |
| 86 | + tango_context.write_attribute("WriteBool", AttrR(Bool())._value) |
| 87 | + |
| 88 | + # # We need to discuss enums |
| 89 | + # def test_string_enum(self, tango_context): |
| 90 | + # expected = 1 |
| 91 | + # tango_context.write_attribute("StringEnum", "green") |
| 92 | + # result = tango_context.read_attribute("StringEnum") |
| 93 | + # assert result.w_value == expected |
| 94 | + |
| 95 | + def test_big_enum(self, tango_context): |
| 96 | + result = tango_context.read_attribute("BigEnum") |
| 97 | + assert result.value == AttrR(Int(), allowed_values=list(range(1, 18)))._value |
| 98 | + |
| 99 | + def test_go(self, tango_context): |
| 100 | + tango_context.command_inout("go") |
| 101 | + |
| 102 | + def test_state(self, tango_context): |
| 103 | + assert tango_context.command_inout("State") == DevState.ON |
| 104 | + |
| 105 | + def test_status(self, tango_context): |
| 106 | + expected = "The device is in ON state." |
| 107 | + assert tango_context.command_inout("Status") == expected |
0 commit comments