-
Notifications
You must be signed in to change notification settings - Fork 52
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
Code quality improvements to the TangoShutter Class #847
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5601846
Update of the TangoShutter class
4eaab9d
Refactoring of the TangoShutter class
e11507b
minor change to the class instantiation
7c7d2d8
Update mxcubecore/HardwareObjects/TangoShutter.py
HilbertCorsair adeebc1
minor change : super().init() instead of AbstractShutter.init(self)
60cb43e
code formatting with black
557ff3c
no change in code: pre-commit hooks test
113b623
Revert "no change in code: pre-commit hooks test"
019f8bd
cosmetic changes after pylint analysis: rm traing spaces, rm unused i…
80eea86
formating line endings to LF to address mixed line endings issue
6434c67
new linting
2a590f0
Merge remote-tracking branch 'upstream/develop' into develop
f4c2960
Merge remote-tracking branch 'upstream/develop' into develop
5800b6d
code quality improvements in the TangoShutter class
bad989a
Update mxcubecore/HardwareObjects/TangoShutter.py
HilbertCorsair a3bcdf0
adding logging and minor chenges in the comments
7ecf1fe
Merge remote-tracking branch 'origin/develop' into develop
e4b2434
minor corections in the comments
670efc0
Dropping json for ast.literal_eval in initalize values
15a282e
Merge remote-tracking branch 'upstream/develop' into develop
f01e33c
tests on HardwareObjects.TangoShutter hardware objects
elmjag 3eb6cd7
Merge remote-tracking branch 'upstream/develop' into develop
cceeaa1
Minor refactoring of get_object_by_role() in HardwareObjectNode class
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 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
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,119 @@ | ||
from typing import Callable | ||
import pytest | ||
import gevent | ||
from gevent import Timeout | ||
from tango import DeviceProxy, DevState | ||
from tango.server import Device, command | ||
from tango.test_context import DeviceTestContext | ||
from mxcubecore.HardwareObjects import TangoShutter | ||
|
||
""" | ||
Test the HardwareObjects.TangoShutter shutter hardware object. | ||
""" | ||
|
||
|
||
VALUES_JSON = """ | ||
{"OPEN": "OPEN", "CLOSED": "CLOSE", "MOVING" : "MOVING"} | ||
""" | ||
|
||
|
||
class Shutter(Device): | ||
""" | ||
Very simple tango shutter device, that only goes between 'open' and 'close' states. | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): | ||
self._is_open = False | ||
super().__init__(*args, **kwargs) | ||
|
||
@command() | ||
def Open(self): | ||
self._is_open = True | ||
|
||
@command() | ||
def Close(self): | ||
self._is_open = False | ||
|
||
def dev_state(self): | ||
return DevState.OPEN if self._is_open else DevState.CLOSE | ||
|
||
|
||
@pytest.fixture | ||
def shutter(): | ||
tangods_test_context = DeviceTestContext(Shutter, process=True) | ||
tangods_test_context.start() | ||
|
||
# | ||
# set up the TangoShutter hardware object | ||
# | ||
hwo_shutter = TangoShutter.TangoShutter("/random_name") | ||
hwo_shutter.tangoname = tangods_test_context.get_device_access() | ||
hwo_shutter.set_property("values", VALUES_JSON) | ||
hwo_shutter.add_channel( | ||
{ | ||
"name": "State", | ||
"type": "tango", | ||
}, | ||
"State", | ||
True, | ||
) | ||
hwo_shutter.add_command( | ||
{ | ||
"name": "Open", | ||
"type": "tango", | ||
}, | ||
"Open", | ||
True, | ||
) | ||
hwo_shutter.add_command( | ||
{ | ||
"name": "Close", | ||
"type": "tango", | ||
}, | ||
"Close", | ||
True, | ||
) | ||
|
||
hwo_shutter.init() | ||
|
||
yield hwo_shutter | ||
|
||
tangods_test_context.stop() | ||
tangods_test_context.join() | ||
|
||
|
||
def _wait_until(condition: Callable, condition_desc: str): | ||
with Timeout(1.2, Exception(f"timed out while waiting for {condition_desc}")): | ||
while not condition(): | ||
gevent.sleep(0.01) | ||
|
||
|
||
def test_open(shutter): | ||
""" | ||
test opening the shutter | ||
""" | ||
dev = DeviceProxy(shutter.tangoname) | ||
|
||
assert dev.State() == DevState.CLOSE | ||
assert not shutter.is_open | ||
|
||
shutter.open() | ||
|
||
_wait_until(lambda: shutter.is_open, "shutter to open") | ||
assert dev.State() == DevState.OPEN | ||
|
||
|
||
def test_close(shutter): | ||
""" | ||
test closing the shutter | ||
""" | ||
dev = DeviceProxy(shutter.tangoname) | ||
dev.Open() | ||
|
||
assert dev.State() == DevState.OPEN | ||
assert shutter.is_open | ||
|
||
shutter.close() | ||
|
||
_wait_until(lambda: not shutter.is_open, "shutter to close") | ||
assert dev.State() == DevState.CLOSE |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this variable to for example
VALUES_LITERAL
. TheVALUES_JSON
is now confusing, as technically speaking we are not supporting JSON strings but pythong literal expressions. Event if it so happens in this case that text is identical.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @elmjag, I am a bit puzzled that we need a special test for the TangoShutter and not using the generic shutter test. Do we miss something in the generic shutter test or the ShutterMockup. If such is the case, maybe it is worth adding your work to the generic shutter test, so it would serve other shutter types, not just the Tango ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are tests to test code in TangoShutter.py. The generic shutter test code does not cover it, as it is using ShutterMockup hardware object.
More specifically these tests set-up an actual tango device and instantiate a TangoShutter hardware object that talks to that device. This way you check that opening/closing shutter work, with TangoShutter hwo, using real tango stack.
They way I read the code in
test/pytest/test_shutter.py
, it is testing the code in the abstract classes starting with AbstractShutter.The tests in
test_shutter.py
andtest_hwo_tango_shutter.py
are testing related, but separate aspects of the code base.