-
Notifications
You must be signed in to change notification settings - Fork 6
Remove tango polling #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b4fb01
Remove tango polling
marcelldls dbe58fb
Process review comments
marcelldls 83cab26
Fix epics tests
marcelldls 46163db
Fix typo
marcelldls 5d9229d
Expose assertions in tests
marcelldls 92f5e46
Write to val before read
marcelldls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,37 +1,125 @@ | ||
| import copy | ||
| import re | ||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from pytest_mock import MockerFixture | ||
| from tango._tango import AttrWriteType, CmdArgType | ||
|
|
||
| from fastcs.backends.tango.dsr import _collect_dev_attributes, _collect_dev_commands | ||
|
|
||
|
|
||
| def test_collect_attributes(mapping): | ||
| attributes = _collect_dev_attributes(mapping) | ||
|
|
||
| # Check that attributes are created and of expected type | ||
| assert list(attributes.keys()) == [ | ||
| "BigEnum", | ||
| "ReadBool", | ||
| "ReadInt", | ||
| "ReadWriteFloat", | ||
| "ReadWriteInt", | ||
| "StringEnum", | ||
| "WriteBool", | ||
| ] | ||
| assert attributes["ReadInt"].attr_write == AttrWriteType.READ | ||
| assert attributes["ReadInt"].attr_type == CmdArgType.DevLong64 | ||
| assert attributes["StringEnum"].attr_write == AttrWriteType.READ_WRITE | ||
| assert attributes["StringEnum"].attr_type == CmdArgType.DevString | ||
| assert attributes["ReadWriteFloat"].attr_write == AttrWriteType.READ_WRITE | ||
| assert attributes["ReadWriteFloat"].attr_type == CmdArgType.DevDouble | ||
| assert attributes["WriteBool"].attr_write == AttrWriteType.WRITE | ||
| assert attributes["WriteBool"].attr_type == CmdArgType.DevBoolean | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_collect_commands(mapping, mocker: MockerFixture): | ||
| commands = _collect_dev_commands(mapping) | ||
|
|
||
| # Check that command is created and it can be called | ||
| assert list(commands.keys()) == ["Go"] | ||
| await commands["Go"](mocker.MagicMock()) | ||
| from tango import DevState | ||
| from tango.test_context import DeviceTestContext | ||
|
|
||
| from fastcs.attributes import AttrR | ||
| from fastcs.backends.tango.backend import TangoBackend | ||
| from fastcs.datatypes import Bool, Float, Int, String | ||
|
|
||
|
|
||
| def pascal_2_snake(input: list[str]) -> list[str]: | ||
| """ | ||
| Converts the last entry in a list of strings | ||
| """ | ||
| snake_list = copy.deepcopy(input) | ||
| snake_list[-1] = re.sub(r"(?<!^)(?=[A-Z])", "_", snake_list[-1]).lower() | ||
| return snake_list | ||
|
|
||
|
|
||
| class TestTangoDevice: | ||
| @pytest.fixture(scope="class", autouse=True) | ||
| def setup_class(self, assertable_controller): | ||
| self.controller = assertable_controller | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def tango_context(self): | ||
| # https://tango-controls.readthedocs.io/projects/pytango/en/v9.5.1/testing/test_context.html | ||
| device = TangoBackend(self.controller)._dsr._device | ||
| with DeviceTestContext(device) as proxy: | ||
| yield proxy | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def client_read(self, tango_context): | ||
| def _read_attribute(path: list[str], expected: Any): | ||
| attribute = "_".join(path) | ||
| with self.controller.assertPerformed(pascal_2_snake(path), "READ"): | ||
| result = tango_context.read_attribute(attribute).value | ||
| assert result == expected | ||
|
|
||
| return _read_attribute | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def client_write(self, tango_context): | ||
| def _write_attribute(path: list[str], expected: Any): | ||
| attribute = "_".join(path) | ||
| with self.controller.assertPerformed(pascal_2_snake(path), "WRITE"): | ||
| tango_context.write_attribute(attribute, expected) | ||
|
|
||
| return _write_attribute | ||
|
|
||
| @pytest.fixture(scope="class") | ||
| def client_exec(self, tango_context): | ||
| def _exec_command(path: list[str]): | ||
| command = "_".join(path) | ||
| with self.controller.assertPerformed(pascal_2_snake(path), "EXECUTE"): | ||
| tango_context.command_inout(command) | ||
|
|
||
| return _exec_command | ||
|
|
||
| def test_list_attributes(self, tango_context): | ||
| assert list(tango_context.get_attribute_list()) == [ | ||
| "BigEnum", | ||
| "ReadBool", | ||
| "ReadInt", | ||
| "ReadWriteFloat", | ||
| "ReadWriteInt", | ||
| "StringEnum", | ||
| "WriteBool", | ||
| "SubController01_ReadInt", | ||
| "SubController02_ReadInt", | ||
| "State", | ||
| "Status", | ||
| ] | ||
|
|
||
| def test_list_commands(self, tango_context): | ||
| assert list(tango_context.get_command_list()) == [ | ||
| "Go", | ||
| "Init", | ||
| "State", | ||
| "Status", | ||
| ] | ||
|
|
||
| def test_state(self, tango_context): | ||
| assert tango_context.command_inout("State") == DevState.ON | ||
|
|
||
| def test_status(self, tango_context): | ||
| expected = "The device is in ON state." | ||
| assert tango_context.command_inout("Status") == expected | ||
|
|
||
| def test_read_int(self, client_read): | ||
| client_read(["ReadInt"], AttrR(Int())._value) | ||
|
|
||
| def test_read_write_int(self, client_read, client_write): | ||
| client_read(["ReadWriteInt"], AttrR(Int())._value) | ||
| client_write(["ReadWriteInt"], AttrR(Int())._value) | ||
|
|
||
| def test_read_write_float(self, client_read, client_write): | ||
| client_read(["ReadWriteFloat"], AttrR(Float())._value) | ||
| client_write(["ReadWriteFloat"], AttrR(Float())._value) | ||
|
|
||
| def test_read_bool(self, client_read): | ||
| client_read(["ReadBool"], AttrR(Bool())._value) | ||
|
|
||
| def test_write_bool(self, client_write): | ||
| client_write(["WriteBool"], AttrR(Bool())._value) | ||
|
|
||
| def test_string_enum(self, client_read, client_write): | ||
| enum = AttrR(String(), allowed_values=["red", "green", "blue"])._value | ||
| client_read(["StringEnum"], enum) | ||
| client_write(["StringEnum"], enum) | ||
|
|
||
| def test_big_enum(self, client_read): | ||
| client_read(["BigEnum"], AttrR(Int(), allowed_values=list(range(1, 18)))._value) | ||
|
|
||
| def test_go(self, client_exec): | ||
| client_exec(["Go"]) | ||
|
|
||
| def test_read_child1(self, client_read): | ||
| client_read(["SubController01", "ReadInt"], AttrR(Int())._value) | ||
|
|
||
| def test_read_child2(self, client_read): | ||
| client_read(["SubController02", "ReadInt"], AttrR(Int())._value) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.