Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit fb76941

Browse files
authored
Merge pull request #14 from ALBA-Synchrotron/add_tests
Add motor tests using pool fixtures
2 parents c66ff14 + 6ba0040 commit fb76941

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

tests/test_motor.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
"""Requires `sys/tg_test/1` device running
2+
"""
3+
import os
4+
import inspect
5+
from numbers import Number
6+
7+
import pytest
8+
from sardana import State
9+
from sardana.pool.test.util import ActionEvent
10+
11+
# Setting pool_path won't be necessary when SEP19 gets implemented
12+
current_dir = os.path.dirname(
13+
os.path.abspath(inspect.getfile(inspect.currentframe()))
14+
)
15+
parent_dir = os.path.dirname(current_dir)
16+
pool_path = os.path.join(parent_dir, "sardana_tango/ctrl")
17+
18+
pool_mark = pytest.mark.attrs({"pool": {"pool_path": [pool_path]}})
19+
20+
ctrl_mark = pytest.mark.kwargs({
21+
"motctrl01": {
22+
"klass": "TangoAttrMotorController",
23+
"library": "TangoAttrMotorCtrl.py"
24+
}
25+
})
26+
27+
mot_mark = pytest.mark.attribute_values({
28+
"mot01": {
29+
"TangoAttribute": "sys/tg_test/1/ampli",
30+
}
31+
})
32+
33+
pytestmark = [pool_mark, ctrl_mark, mot_mark]
34+
35+
#############
36+
# Alternatively you could create your own fixtures
37+
# using the "Factory as fixture" e.g. `create_motor_ctrl`
38+
# or `create_motor`.
39+
40+
41+
# @pytest.fixture()
42+
# def pool(create_pool):
43+
# pool = create_pool()
44+
# pool.pool_path = [pool_path]
45+
# return pool
46+
47+
48+
# @pytest.fixture()
49+
# def motctrl01(create_motor_ctrl):
50+
# kwargs = {
51+
# "klass": "TangoAttrMotorController",
52+
# "library": "TangoAttrMotorCtrl.py"
53+
# }
54+
# return create_motor_ctrl(kwargs)
55+
56+
57+
# @pytest.fixture()
58+
# def mot01(motctrl01, create_motor):
59+
# axis = 1
60+
# mot = create_motor(motctrl01, axis)
61+
# mot.init_attribute_values({
62+
# "TangoAttribute": "sys/tg_test/1/ampli"
63+
# })
64+
# return mot
65+
##############
66+
67+
def test_init(motctrl01):
68+
assert motctrl01.is_online() == True
69+
70+
71+
def test_get_state(mot01):
72+
assert mot01.state == State.On
73+
74+
75+
def test_get_position(mot01):
76+
assert isinstance(mot01.position.value, Number)
77+
78+
79+
def test_set_position(mot01):
80+
mot01.position = 10
81+
motion_event = ActionEvent(mot01)
82+
motion_event.started.wait(1)
83+
motion_event.done.wait(1)
84+
assert mot01.position.value == 10
85+
86+
87+
def test_stop(mot01):
88+
mot01.position = 10
89+
motion_event = ActionEvent(mot01)
90+
motion_event.started.wait(1)
91+
mot01.stop()
92+
motion_event.done.wait(1)
93+
assert mot01.state == State.On

0 commit comments

Comments
 (0)