-
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 all 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,112 @@ | ||
| 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.backends.tango.backend import TangoBackend | ||
|
|
||
|
|
||
| class TestTangoDevice: | ||
| @pytest.fixture(scope="class") | ||
| def tango_context(self, assertable_controller): | ||
| # https://tango-controls.readthedocs.io/projects/pytango/en/v9.5.1/testing/test_context.html | ||
| device = TangoBackend(assertable_controller)._dsr._device | ||
| with DeviceTestContext(device) as proxy: | ||
| yield proxy | ||
|
|
||
| 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): | ||
| expect = "The device is in ON state." | ||
| assert tango_context.command_inout("Status") == expect | ||
|
|
||
| def test_read_int(self, assertable_controller, tango_context): | ||
| expect = 0 | ||
| with assertable_controller.assert_read_here(["read_int"]): | ||
| result = tango_context.read_attribute("ReadInt").value | ||
| assert result == expect | ||
|
|
||
| def test_read_write_int(self, assertable_controller, tango_context): | ||
| expect = 0 | ||
| with assertable_controller.assert_read_here(["read_write_int"]): | ||
| result = tango_context.read_attribute("ReadWriteInt").value | ||
| assert result == expect | ||
| new = 9 | ||
| with assertable_controller.assert_write_here(["read_write_int"]): | ||
| tango_context.write_attribute("ReadWriteInt", new) | ||
| assert tango_context.read_attribute("ReadWriteInt").value == new | ||
|
|
||
| def test_read_write_float(self, assertable_controller, tango_context): | ||
| expect = 0.0 | ||
| with assertable_controller.assert_read_here(["read_write_float"]): | ||
| result = tango_context.read_attribute("ReadWriteFloat").value | ||
| assert result == expect | ||
| new = 0.5 | ||
| with assertable_controller.assert_write_here(["read_write_float"]): | ||
| tango_context.write_attribute("ReadWriteFloat", new) | ||
| assert tango_context.read_attribute("ReadWriteFloat").value == new | ||
|
|
||
| def test_read_bool(self, assertable_controller, tango_context): | ||
| expect = False | ||
| with assertable_controller.assert_read_here(["read_bool"]): | ||
| result = tango_context.read_attribute("ReadBool").value | ||
| assert result == expect | ||
|
|
||
| def test_write_bool(self, assertable_controller, tango_context): | ||
| with assertable_controller.assert_write_here(["write_bool"]): | ||
| tango_context.write_attribute("WriteBool", True) | ||
|
|
||
| def test_string_enum(self, assertable_controller, tango_context): | ||
| expect = "" | ||
| with assertable_controller.assert_read_here(["string_enum"]): | ||
| result = tango_context.read_attribute("StringEnum").value | ||
| assert result == expect | ||
| new = "new" | ||
| with assertable_controller.assert_write_here(["string_enum"]): | ||
| tango_context.write_attribute("StringEnum", new) | ||
| assert tango_context.read_attribute("StringEnum").value == new | ||
|
|
||
| def test_big_enum(self, assertable_controller, tango_context): | ||
| expect = 0 | ||
| with assertable_controller.assert_read_here(["big_enum"]): | ||
| result = tango_context.read_attribute("BigEnum").value | ||
| assert result == expect | ||
|
|
||
| def test_go(self, assertable_controller, tango_context): | ||
| with assertable_controller.assert_execute_here(["go"]): | ||
| tango_context.command_inout("Go") | ||
|
|
||
| def test_read_child1(self, assertable_controller, tango_context): | ||
| expect = 0 | ||
| with assertable_controller.assert_read_here(["SubController01", "read_int"]): | ||
| result = tango_context.read_attribute("SubController01_ReadInt").value | ||
| assert result == expect | ||
|
|
||
| def test_read_child2(self, assertable_controller, tango_context): | ||
| expect = 0 | ||
| with assertable_controller.assert_read_here(["SubController02", "read_int"]): | ||
| result = tango_context.read_attribute("SubController02_ReadInt").value | ||
| assert result == expect | ||
Oops, something went wrong.
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.