Skip to content

Commit fd47272

Browse files
committed
Replace XML profile (and loading) with direct profile creation/modification during test
1 parent 5e5ccf4 commit fd47272

3 files changed

Lines changed: 68 additions & 124 deletions

File tree

test/integration/action_plugins/conftest.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,22 @@
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

1818
from collections.abc import Iterator
19-
import pathlib
2019

2120
import pytest
2221

23-
from gremlin import profile
2422
from gremlin.ui import backend
2523

2624

27-
@pytest.fixture(scope="module")
28-
def edited_profile_path(profile_path: pathlib.Path) -> Iterator[str]:
29-
"""For action plugins tests we don't need to edit the profile."""
30-
yield str(profile_path)
31-
32-
33-
@pytest.fixture(scope="module")
34-
def loaded_profile() -> profile.Profile:
35-
return backend.Backend().profile
25+
# Do not use directly, see app_tester fixture instead.
26+
@pytest.fixture(scope="module", autouse=True)
27+
def _activate_gremlin(profile_setup: None) -> Iterator[None]:
28+
"""Activates Gremlin using the profile created by profile_setup.
29+
30+
profile_setup is a fixture that should be created by individual tests, creating
31+
the necessary IntermediateOutput objects, actions, and InputItemBindings.
32+
"""
33+
backend_ = backend.Backend()
34+
backend_.activate_gremlin(True)
35+
backend_.minimize()
36+
yield
37+
backend_.activate_gremlin(False)

test/integration/action_plugins/test_response_curve.py

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,76 @@
2222

2323
import pytest
2424

25+
from action_plugins import response_curve
26+
from action_plugins import root
2527
from action_plugins import map_to_io
2628
import dill
29+
from gremlin.ui import backend
2730
from gremlin import event_handler
31+
from gremlin import intermediate_output
32+
from gremlin import plugin_manager
2833
from gremlin import profile
34+
from gremlin import shared_state
2935
from gremlin import types
3036
from gremlin import mode_manager
3137
from test.integration import app_tester
3238

39+
_INPUT_IO_AXIS_LABEL = "InputAxis1"
40+
_OUTPUT_IO_AXIS_LABEL = "OutputAxis1"
3341

34-
@pytest.fixture(scope="module", autouse=True)
35-
def profile_name() -> str:
36-
return "action_response_curve.xml"
42+
43+
@pytest.fixture(scope="module")
44+
def profile_setup() -> None:
45+
# This is important for locally-run tests where the last used profile could
46+
# get loaded, if present in configuration.
47+
backend.Backend().profile = pr = profile.Profile()
48+
shared_state.current_profile = pr
49+
50+
# Create intermediate output axis for both input and output.
51+
io = intermediate_output.IntermediateOutput()
52+
io.reset()
53+
io.create(types.InputType.JoystickAxis, label=_INPUT_IO_AXIS_LABEL)
54+
io.create(types.InputType.JoystickAxis, label=_OUTPUT_IO_AXIS_LABEL)
55+
56+
p_manager = plugin_manager.PluginManager()
57+
# Create response curve action.
58+
response_curve_action = p_manager.create_instance(
59+
response_curve.ResponseCurveData.name,
60+
types.InputType.JoystickAxis
61+
)
62+
63+
# Create intermediate output mapping action.
64+
map_to_io_action = p_manager.create_instance(
65+
map_to_io.MapToIOData.name,
66+
types.InputType.JoystickAxis
67+
)
68+
map_to_io_action.io_input_guid = io[_OUTPUT_IO_AXIS_LABEL].guid
69+
70+
# Add actions to profile.
71+
root_action = p_manager.create_instance(root.RootData.name, types.InputType.JoystickAxis)
72+
root_action.insert_action(response_curve_action, "children")
73+
root_action.insert_action(map_to_io_action, "children")
74+
# Add input item and its binding.
75+
input_item = profile.InputItem(pr.library)
76+
input_item.device_id = dill.UUID_IntermediateOutput
77+
input_item.input_id = io[_INPUT_IO_AXIS_LABEL].guid
78+
input_item.input_type = types.InputType.JoystickAxis
79+
input_item.mode = mode_manager.ModeManager().current.name
80+
input_item_binding = profile.InputItemBinding(input_item)
81+
input_item_binding.root_action = root_action
82+
input_item_binding.behavior = types.InputType.JoystickAxis
83+
input_item.action_sequences.append(input_item_binding)
84+
pr.inputs.setdefault(dill.UUID_IntermediateOutput, []).append(input_item)
3785

3886

3987
@pytest.fixture
40-
def input_axis_uuid(loaded_profile: profile.Profile) -> uuid.UUID:
41-
return loaded_profile.inputs[dill.UUID_IntermediateOutput][0].input_id
88+
def input_axis_uuid() -> uuid.UUID:
89+
return intermediate_output.IntermediateOutput()[_INPUT_IO_AXIS_LABEL].guid
4290

4391

4492
@pytest.fixture
45-
def output_axis_uuid(loaded_profile: profile.Profile) -> uuid.UUID:
46-
return loaded_profile.library.actions_by_type(map_to_io.MapToIOData)[
47-
0
48-
].io_input_guid
93+
def output_axis_uuid() -> uuid.UUID:
94+
return intermediate_output.IntermediateOutput()[_OUTPUT_IO_AXIS_LABEL].guid
4995

5096

5197
class TestResponseCurve:

test/integration/xml/action_response_curve.xml

Lines changed: 0 additions & 104 deletions
This file was deleted.

0 commit comments

Comments
 (0)