psychopy 2024.1.2__py3-none-any.whl → 2024.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of psychopy might be problematic. Click here for more details.
- psychopy/__init__.py +2 -2
- psychopy/app/builder/localizedStrings.py +11 -9
- psychopy/app/locale/ja_JP/LC_MESSAGE/messages.mo +0 -0
- psychopy/app/locale/ja_JP/LC_MESSAGE/messages.po +359 -346
- psychopy/app/plugin_manager/plugins.py +7 -0
- psychopy/demos/builder/Feature Demos/progress/progressBar.psyexp +4 -4
- psychopy/experiment/components/buttonBox/__init__.py +21 -12
- psychopy/experiment/components/mouse/__init__.py +12 -0
- psychopy/experiment/components/progress/__init__.py +1 -1
- psychopy/experiment/routines/counterbalance/__init__.py +1 -1
- psychopy/experiment/routines/photodiodeValidator/__init__.py +1 -1
- psychopy/hardware/keyboard.py +1 -2
- psychopy/tests/test_experiment/test_components/__init__.py +1 -1
- psychopy/tests/test_experiment/test_components/{test_ButtonBox.py → test_ButtonBoxComponent.py} +9 -27
- psychopy/tests/test_experiment/test_components/{test_Code.py → test_CodeComponent.py} +8 -20
- psychopy/tests/test_experiment/test_components/test_GratingComponent.py +7 -0
- psychopy/tests/test_experiment/test_components/test_ImageComponent.py +8 -0
- psychopy/tests/test_experiment/test_components/{test_Mouse.py → test_MouseComponent.py} +44 -57
- psychopy/tests/test_experiment/test_components/{test_Polygon.py → test_PolygonComponent.py} +9 -25
- psychopy/tests/test_experiment/test_components/{test_ResourceManager.py → test_ResourceManagerComponent.py} +3 -13
- psychopy/tests/test_experiment/test_components/{test_Settings.py → test_SettingsComponent.py} +1 -3
- psychopy/tests/test_experiment/test_components/{test_Static.py → test_StaticComponent.py} +3 -12
- psychopy/tests/test_experiment/test_components/test_all_components.py +8 -66
- psychopy/tests/test_experiment/test_components/test_base_components.py +212 -125
- psychopy/tests/test_hardware/test_keyboard.py +153 -16
- psychopy/visual/progress.py +1 -1
- psychopy/web.py +5 -2
- {psychopy-2024.1.2.dist-info → psychopy-2024.1.4.dist-info}/METADATA +2 -2
- {psychopy-2024.1.2.dist-info → psychopy-2024.1.4.dist-info}/RECORD +33 -32
- {psychopy-2024.1.2.dist-info → psychopy-2024.1.4.dist-info}/WHEEL +1 -1
- psychopy/tests/test_experiment/test_components/test_Image.py +0 -24
- {psychopy-2024.1.2.dist-info → psychopy-2024.1.4.dist-info}/entry_points.txt +0 -0
- {psychopy-2024.1.2.dist-info → psychopy-2024.1.4.dist-info}/licenses/AUTHORS.md +0 -0
- {psychopy-2024.1.2.dist-info → psychopy-2024.1.4.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,23 +1,14 @@
|
|
|
1
1
|
from pathlib import Path
|
|
2
2
|
|
|
3
|
-
from . import
|
|
3
|
+
from . import BaseComponentTests
|
|
4
4
|
from .test_base_components import _find_global_resource_in_js_experiment
|
|
5
5
|
from psychopy.experiment.components.static import StaticComponent
|
|
6
6
|
from psychopy import experiment, data
|
|
7
7
|
from ...utils import TESTS_DATA_PATH
|
|
8
8
|
|
|
9
9
|
|
|
10
|
-
class TestStaticComponent(
|
|
11
|
-
|
|
12
|
-
# Make blank experiment
|
|
13
|
-
self.exp = experiment.Experiment()
|
|
14
|
-
# Make blank routine
|
|
15
|
-
self.routine = experiment.routines.Routine(name="testRoutine", exp=self.exp)
|
|
16
|
-
self.exp.addRoutine("testRoutine", self.routine)
|
|
17
|
-
self.exp.flow.addRoutine(self.routine, 0)
|
|
18
|
-
# Make Static component
|
|
19
|
-
self.comp = StaticComponent(exp=self.exp, parentName="testRoutine", name="testStatic")
|
|
20
|
-
self.routine.addComponent(self.comp)
|
|
10
|
+
class TestStaticComponent(BaseComponentTests):
|
|
11
|
+
comp = StaticComponent
|
|
21
12
|
|
|
22
13
|
def test_handled_resources_removed(self):
|
|
23
14
|
"""
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from psychopy.experiment.exports import IndentingBuffer
|
|
2
|
-
from . import
|
|
2
|
+
from . import BaseComponentTests
|
|
3
3
|
from psychopy import experiment
|
|
4
4
|
import inspect
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
class _Generic(
|
|
7
|
+
class _Generic(BaseComponentTests):
|
|
8
8
|
def __init__(self, compClass):
|
|
9
9
|
self.exp = experiment.Experiment()
|
|
10
10
|
self.rt = experiment.routines.Routine(exp=self.exp, name="testRoutine")
|
|
@@ -18,14 +18,12 @@ def test_all_components():
|
|
|
18
18
|
for compName, compClass in experiment.getAllComponents().items():
|
|
19
19
|
if compName == "SettingsComponent":
|
|
20
20
|
continue
|
|
21
|
-
#
|
|
22
|
-
tester =
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
# Run each method from _TestBaseComponentsMixin on tester
|
|
28
|
-
for attr, meth in _TestDisabledMixin.__dict__.items():
|
|
21
|
+
# make a generic testing object for this component
|
|
22
|
+
tester = BaseComponentTests()
|
|
23
|
+
# make sure it has a comp class assigned
|
|
24
|
+
tester.comp = compClass
|
|
25
|
+
# Run each method from BaseComponentTests on tester
|
|
26
|
+
for attr, meth in BaseComponentTests.__dict__.items():
|
|
29
27
|
if inspect.ismethod(meth):
|
|
30
28
|
meth(tester)
|
|
31
29
|
|
|
@@ -104,59 +102,3 @@ def test_visual_set_autodraw():
|
|
|
104
102
|
f"{compName} does not set autoDraw in its Each Frame code. If this is acceptable, add the component name "
|
|
105
103
|
f"to `skipComponents`."
|
|
106
104
|
)
|
|
107
|
-
|
|
108
|
-
def test_indentation_consistency():
|
|
109
|
-
"""
|
|
110
|
-
No component should exit any of its write methods at a different indent level as it entered, as this would break
|
|
111
|
-
subsequent components / routines.
|
|
112
|
-
"""
|
|
113
|
-
for compName, compClass in experiment.getAllComponents().items():
|
|
114
|
-
if compName == "SettingsComponent":
|
|
115
|
-
continue
|
|
116
|
-
# Make a generic testing object for this component
|
|
117
|
-
tester = _Generic(compClass)
|
|
118
|
-
# Skip if component doesn't have a start/stop time
|
|
119
|
-
if "startVal" not in tester.comp.params or "stopVal" not in tester.comp.params:
|
|
120
|
-
continue
|
|
121
|
-
# Check that each write method exits at the same indent level as it entered
|
|
122
|
-
buff = IndentingBuffer(target="PsychoPy")
|
|
123
|
-
msg = "Writing {} code for {} changes indent level by {} when start is `{}` and stop is `{}`."
|
|
124
|
-
# Setup flow for writing
|
|
125
|
-
tester.exp.flow.writeStartCode(buff)
|
|
126
|
-
# Try combinations of start/stop being set/unset
|
|
127
|
-
cases = [
|
|
128
|
-
{"startVal": "0", "stopVal": "1"},
|
|
129
|
-
{"startVal": "", "stopVal": "1"},
|
|
130
|
-
{"startVal": "0", "stopVal": ""},
|
|
131
|
-
{"startVal": "", "stopVal": ""},
|
|
132
|
-
]
|
|
133
|
-
for case in cases:
|
|
134
|
-
tester.comp.params["startType"].val = "time (s)"
|
|
135
|
-
tester.comp.params["stopType"].val = "time (s)"
|
|
136
|
-
for param, val in case.items():
|
|
137
|
-
tester.comp.params[param].val = val
|
|
138
|
-
# Init
|
|
139
|
-
tester.comp.writeInitCode(buff)
|
|
140
|
-
assert buff.indentLevel == 0, msg.format(
|
|
141
|
-
"init", type(tester.comp).__name__, buff.indentLevel, case['startVal'], case['stopVal']
|
|
142
|
-
)
|
|
143
|
-
# Start routine
|
|
144
|
-
tester.comp.writeRoutineStartCode(buff)
|
|
145
|
-
assert buff.indentLevel == 0, msg.format(
|
|
146
|
-
"routine start", type(tester.comp).__name__, buff.indentLevel, case['startVal'], case['stopVal']
|
|
147
|
-
)
|
|
148
|
-
# Each frame
|
|
149
|
-
tester.comp.writeFrameCode(buff)
|
|
150
|
-
assert buff.indentLevel == 0, msg.format(
|
|
151
|
-
"each frame", type(tester.comp).__name__, buff.indentLevel, case['startVal'], case['stopVal']
|
|
152
|
-
)
|
|
153
|
-
# End routine
|
|
154
|
-
tester.comp.writeRoutineEndCode(buff)
|
|
155
|
-
assert buff.indentLevel == 0, msg.format(
|
|
156
|
-
"routine end", type(tester.comp).__name__, buff.indentLevel, case['startVal'], case['stopVal']
|
|
157
|
-
)
|
|
158
|
-
# End experiment
|
|
159
|
-
tester.comp.writeExperimentEndCode(buff)
|
|
160
|
-
assert buff.indentLevel == 0, msg.format(
|
|
161
|
-
"experiment end", type(tester.comp).__name__, buff.indentLevel, case['startVal'], case['stopVal']
|
|
162
|
-
)
|
|
@@ -6,27 +6,9 @@ from pathlib import Path
|
|
|
6
6
|
import pytest
|
|
7
7
|
|
|
8
8
|
from psychopy import experiment
|
|
9
|
+
from psychopy.experiment.loops import TrialHandler
|
|
9
10
|
from psychopy.experiment.components import BaseComponent
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def _make_minimal_experiment(obj):
|
|
13
|
-
"""
|
|
14
|
-
Make a minimal experiment with just one routine containing just one component, of the same class as the current
|
|
15
|
-
component but with all default params.
|
|
16
|
-
"""
|
|
17
|
-
# Skip whole test if required attributes aren't present
|
|
18
|
-
if not hasattr(obj, "comp"):
|
|
19
|
-
pytest.skip()
|
|
20
|
-
# Make blank experiment
|
|
21
|
-
exp = experiment.Experiment()
|
|
22
|
-
rt = exp.addRoutine(routineName='TestRoutine')
|
|
23
|
-
exp.flow.addRoutine(rt, 0)
|
|
24
|
-
# Create instance of this component with all default params
|
|
25
|
-
compClass = type(obj.comp)
|
|
26
|
-
comp = compClass(exp=exp, parentName='TestRoutine', name=f"test{compClass.__name__}")
|
|
27
|
-
rt.append(comp)
|
|
28
|
-
# Return experiment, routine and component
|
|
29
|
-
return comp, rt, exp
|
|
11
|
+
from psychopy.experiment.exports import IndentingBuffer
|
|
30
12
|
|
|
31
13
|
|
|
32
14
|
def _find_global_resource_in_js_experiment(script, resource):
|
|
@@ -48,34 +30,228 @@ def _find_global_resource_in_js_experiment(script, resource):
|
|
|
48
30
|
return resource in resourcesStr
|
|
49
31
|
|
|
50
32
|
|
|
51
|
-
class
|
|
52
|
-
#
|
|
53
|
-
|
|
33
|
+
class BaseComponentTests:
|
|
34
|
+
# component class to test
|
|
35
|
+
comp = None
|
|
54
36
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
37
|
+
# --- Utility methods ---
|
|
38
|
+
def make_minimal_experiment(self):
|
|
39
|
+
"""
|
|
40
|
+
Make a minimal experiment with just one routine containing just one component, of the same class as the current component but with all default params.
|
|
41
|
+
"""
|
|
42
|
+
# make blank experiment
|
|
43
|
+
exp = experiment.Experiment()
|
|
44
|
+
# add a Routine
|
|
45
|
+
rt = exp.addRoutine(routineName='TestRoutine')
|
|
46
|
+
exp.flow.addRoutine(rt, 0)
|
|
47
|
+
# add a loop around the Routine
|
|
48
|
+
loop = TrialHandler(exp=exp, name="testLoop")
|
|
49
|
+
exp.flow.addLoop(loop, 0, -1)
|
|
50
|
+
# create instance of this test's Component with all default params
|
|
51
|
+
comp = self.comp(exp=exp, parentName='TestRoutine', name=f"test{self.comp.__name__}")
|
|
52
|
+
rt.append(comp)
|
|
53
|
+
# return experiment, Routine and Component
|
|
54
|
+
return comp, rt, exp
|
|
55
|
+
|
|
56
|
+
@pytest.fixture(autouse=True)
|
|
57
|
+
def assert_comp_class(self):
|
|
58
|
+
"""
|
|
59
|
+
Make sure this test object has an associated Component class - and skip the test if not. This is run before each test by default.
|
|
60
|
+
"""
|
|
61
|
+
# skip whole test if there is no Component connected to test class
|
|
62
|
+
if self.comp is None:
|
|
59
63
|
pytest.skip()
|
|
60
|
-
#
|
|
64
|
+
# continue with the test as normal
|
|
65
|
+
yield
|
|
66
|
+
|
|
67
|
+
# --- Heritable tests ---
|
|
68
|
+
|
|
69
|
+
def test_icons(self):
|
|
70
|
+
"""
|
|
71
|
+
Check that Component has icons for each app theme and that these point to real files
|
|
72
|
+
"""
|
|
73
|
+
# pathify icon file path
|
|
61
74
|
icon = Path(self.comp.iconFile)
|
|
62
|
-
#
|
|
75
|
+
# get paths for each theme
|
|
63
76
|
files = [
|
|
64
77
|
icon.parent / "light" / icon.name,
|
|
65
78
|
icon.parent / "dark" / icon.name,
|
|
66
79
|
icon.parent / "classic" / icon.name,
|
|
67
80
|
]
|
|
68
|
-
#
|
|
81
|
+
# check that each path is a file
|
|
69
82
|
for file in files:
|
|
70
|
-
assert file.is_file()
|
|
83
|
+
assert file.is_file(), (
|
|
84
|
+
f"Could not find file: {file}"
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
def test_indentation_consistency(self):
|
|
88
|
+
"""
|
|
89
|
+
No component should exit any of its write methods at a different indent level as it entered, as this would break subsequent components / routines.
|
|
90
|
+
"""
|
|
91
|
+
# make minimal experiment just for this test
|
|
92
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
93
|
+
# skip if component doesn't have a start/stop time
|
|
94
|
+
if "startVal" not in comp.params or "stopVal" not in comp.params:
|
|
95
|
+
pytest.skip()
|
|
96
|
+
# create a text buffer to write to
|
|
97
|
+
buff = IndentingBuffer(target="PsychoPy")
|
|
98
|
+
# template message for if test fails
|
|
99
|
+
errMsgTemplate = "Writing {} code for {} changes indent level by {} when start is `{}` and stop is `{}`."
|
|
100
|
+
# setup flow for writing
|
|
101
|
+
exp.flow.writeStartCode(buff)
|
|
102
|
+
# combinations of start/stop being set/unset to try
|
|
103
|
+
cases = [
|
|
104
|
+
{"startVal": "0", "stopVal": "1"},
|
|
105
|
+
{"startVal": "", "stopVal": "1"},
|
|
106
|
+
{"startVal": "0", "stopVal": ""},
|
|
107
|
+
{"startVal": "", "stopVal": ""},
|
|
108
|
+
]
|
|
109
|
+
for case in cases:
|
|
110
|
+
# update error message for this case
|
|
111
|
+
errMsg = errMsgTemplate.format(
|
|
112
|
+
"{}", type(comp).__name__, "{}", case['startVal'], case['stopVal']
|
|
113
|
+
)
|
|
114
|
+
# set start/stop types
|
|
115
|
+
comp.params["startType"].val = "time (s)"
|
|
116
|
+
comp.params["stopType"].val = "time (s)"
|
|
117
|
+
# set start/stop values
|
|
118
|
+
for param, val in case.items():
|
|
119
|
+
comp.params[param].val = val
|
|
120
|
+
# write init code
|
|
121
|
+
comp.writeInitCode(buff)
|
|
122
|
+
# check indent
|
|
123
|
+
assert buff.indentLevel == 0, errMsg.format(
|
|
124
|
+
"init", buff.indentLevel
|
|
125
|
+
)
|
|
126
|
+
# write routine start code
|
|
127
|
+
comp.writeRoutineStartCode(buff)
|
|
128
|
+
# check indent
|
|
129
|
+
assert buff.indentLevel == 0, errMsg.format(
|
|
130
|
+
"routine start", buff.indentLevel
|
|
131
|
+
)
|
|
132
|
+
# write each frame code
|
|
133
|
+
comp.writeFrameCode(buff)
|
|
134
|
+
# check indent
|
|
135
|
+
assert buff.indentLevel == 0, errMsg.format(
|
|
136
|
+
"each frame", buff.indentLevel
|
|
137
|
+
)
|
|
138
|
+
# write end routine code
|
|
139
|
+
comp.writeRoutineEndCode(buff)
|
|
140
|
+
# check indent
|
|
141
|
+
assert buff.indentLevel == 0, errMsg.format(
|
|
142
|
+
"routine end", buff.indentLevel
|
|
143
|
+
)
|
|
144
|
+
# write end experiment code
|
|
145
|
+
comp.writeExperimentEndCode(buff)
|
|
146
|
+
# check indent
|
|
147
|
+
assert buff.indentLevel == 0, errMsg.format(
|
|
148
|
+
"experiment end", buff.indentLevel
|
|
149
|
+
)
|
|
150
|
+
|
|
151
|
+
def test_disabled_default_val(self):
|
|
152
|
+
"""
|
|
153
|
+
Test that components created with default params are not disabled
|
|
154
|
+
"""
|
|
155
|
+
# make minimal experiment just for this test
|
|
156
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
157
|
+
# check whether it can be disabled
|
|
158
|
+
assert 'disabled' in comp.params, (
|
|
159
|
+
f"{type(comp).__name__} does not have a 'disabled' attribute."
|
|
160
|
+
)
|
|
161
|
+
# check that disabled defaults to False
|
|
162
|
+
assert comp.params['disabled'].val is False, f"{type(comp).__name__} is defaulting to disabled."
|
|
163
|
+
|
|
164
|
+
def test_disabled_code_muting(self):
|
|
165
|
+
"""
|
|
166
|
+
Test that components are only written when enabled and targets match.
|
|
167
|
+
"""
|
|
168
|
+
# Code Component is never referenced by name, so skip it for this test
|
|
169
|
+
if self.comp.__name__ == "CodeComponent":
|
|
170
|
+
pytest.skip()
|
|
171
|
+
# Make minimal experiment just for this test
|
|
172
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
173
|
+
# Write experiment and check that component is written
|
|
174
|
+
pyScript = exp.writeScript(target="PsychoPy")
|
|
175
|
+
if "PsychoPy" in type(comp).targets:
|
|
176
|
+
assert comp.name in pyScript, (
|
|
177
|
+
f"{type(comp).__name__} not found in compiled Python script when enabled and PsychoPy in targets."
|
|
178
|
+
)
|
|
179
|
+
else:
|
|
180
|
+
assert comp.name not in pyScript, (
|
|
181
|
+
f"{type(comp).__name__} found in compiled Python script when enabled but PsychoPy not in targets."
|
|
182
|
+
)
|
|
183
|
+
# ## disabled until js can compile without saving
|
|
184
|
+
# jsScript = exp.writeScript(target="PsychoJS")
|
|
185
|
+
# if "PsychoJS" in type(comp).targets:
|
|
186
|
+
# assert comp.name in jsScript, (
|
|
187
|
+
# f"{type(comp).__name__} not found in compiled Python script when enabled and PsychoJS in targets."
|
|
188
|
+
# )
|
|
189
|
+
# else:
|
|
190
|
+
# assert comp.name not in jsScript, (
|
|
191
|
+
# f"{type(comp).__name__} found in compiled Python script when enabled but PsychoJS not in targets."
|
|
192
|
+
# )
|
|
193
|
+
|
|
194
|
+
# disable component then do same tests but assert not present
|
|
195
|
+
comp.params['disabled'].val = True
|
|
196
|
+
|
|
197
|
+
pyScript = exp.writeScript(target="PsychoPy")
|
|
198
|
+
if "PsychoPy" in type(comp).targets:
|
|
199
|
+
assert comp.name not in pyScript, (
|
|
200
|
+
f"{type(comp).__name__} found in compiled Python script when disabled but PsychoPy in targets."
|
|
201
|
+
)
|
|
202
|
+
else:
|
|
203
|
+
assert comp.name not in pyScript, (
|
|
204
|
+
f"{type(comp).__name__} found in compiled Python script when disabled and PsychoPy not in targets."
|
|
205
|
+
)
|
|
206
|
+
# ## disabled until js can compile without saving
|
|
207
|
+
# jsScript = exp.writeScript(target="PsychoJS")
|
|
208
|
+
# if "PsychoJS" in type(comp).targets:
|
|
209
|
+
# assert comp.name not in jsScript, (
|
|
210
|
+
# f"{type(comp).__name__} found in compiled Python script when disabled but PsychoJS in targets."
|
|
211
|
+
# )
|
|
212
|
+
# else:
|
|
213
|
+
# assert comp.name not in jsScript, (
|
|
214
|
+
# f"{type(comp).__name__} found in compiled Python script when disabled and PsychoJS not in targets."
|
|
215
|
+
# )
|
|
71
216
|
|
|
72
|
-
def
|
|
217
|
+
def test_disabled_components_stay_in_routine(self):
|
|
218
|
+
"""
|
|
219
|
+
Test that disabled components aren't removed from their routine when experiment is written.
|
|
220
|
+
"""
|
|
221
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
222
|
+
# Disable component
|
|
223
|
+
comp.params['disabled'].val = True
|
|
224
|
+
# Writing the script drops the component but, if working properly, only from a copy of the routine, not the
|
|
225
|
+
# original!
|
|
226
|
+
exp.writeScript()
|
|
227
|
+
|
|
228
|
+
assert comp in rt, f"Disabling {type(comp).name} appears to remove it from its routine on compile."
|
|
229
|
+
class _TestLibraryClassMixin:
|
|
230
|
+
# class in the PsychoPy libraries (visual, sound, hardware, etc.) corresponding to this component
|
|
231
|
+
libraryClass = None
|
|
232
|
+
|
|
233
|
+
# --- Utility methods ---
|
|
234
|
+
|
|
235
|
+
@pytest.fixture(autouse=True)
|
|
236
|
+
def assert_lib_class(self):
|
|
237
|
+
"""
|
|
238
|
+
Make sure this test object has an associated library class - and skip the test if not. This is run before each test by default.
|
|
239
|
+
"""
|
|
240
|
+
# skip whole test if there is no Component connected to test class
|
|
241
|
+
if self.libraryClass is None:
|
|
242
|
+
pytest.skip()
|
|
243
|
+
# continue with the test as normal
|
|
244
|
+
yield
|
|
245
|
+
|
|
246
|
+
# --- Heritable tests ---
|
|
247
|
+
|
|
248
|
+
def test_device_class_refs(self):
|
|
73
249
|
"""
|
|
74
250
|
Check that any references to device classes in this Routine object point to classes which
|
|
75
251
|
exist.
|
|
76
252
|
"""
|
|
77
253
|
# make minimal experiment just for this test
|
|
78
|
-
comp, rt, exp =
|
|
254
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
79
255
|
# skip test if this element doesn't point to any hardware class
|
|
80
256
|
if not hasattr(comp, "deviceClasses"):
|
|
81
257
|
pytest.skip()
|
|
@@ -91,13 +267,7 @@ class _TestBaseComponentsMixin:
|
|
|
91
267
|
|
|
92
268
|
def test_params_used(self):
|
|
93
269
|
# Make minimal experiment just for this test
|
|
94
|
-
comp, rt, exp =
|
|
95
|
-
# Skip if component shouldn't use all of its params
|
|
96
|
-
if type(comp).__name__ in ["SettingsComponent", "CodeComponent"]:
|
|
97
|
-
pytest.skip()
|
|
98
|
-
# Skip if component is deprecated
|
|
99
|
-
if type(comp).__name__ in ['RatingScaleComponent', 'PatchComponent']:
|
|
100
|
-
pytest.skip()
|
|
270
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
101
271
|
# Try with PsychoPy and PsychoJS
|
|
102
272
|
for target in ("PsychoPy", "PsychoJS"):
|
|
103
273
|
## Skip PsychoJS until can write script without saving
|
|
@@ -134,11 +304,8 @@ class _TestBaseComponentsMixin:
|
|
|
134
304
|
"""
|
|
135
305
|
Check that all params which are settable each frame/repeat have a set method in the corresponding class.
|
|
136
306
|
"""
|
|
137
|
-
# Skip if there's no corresponding library class
|
|
138
|
-
if self.libraryClass is None:
|
|
139
|
-
return
|
|
140
307
|
# Make minimal experiment just for this test
|
|
141
|
-
comp, rt, exp =
|
|
308
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
142
309
|
# Check each param
|
|
143
310
|
for paramName, param in comp.params.items():
|
|
144
311
|
if not param.direct:
|
|
@@ -167,91 +334,11 @@ class _TestBaseComponentsMixin:
|
|
|
167
334
|
)
|
|
168
335
|
|
|
169
336
|
|
|
170
|
-
class _TestDisabledMixin:
|
|
171
|
-
def test_disabled_default_val(self):
|
|
172
|
-
"""
|
|
173
|
-
Test that components created with default params are not disabled
|
|
174
|
-
"""
|
|
175
|
-
# Make minimal experiment just for this test
|
|
176
|
-
comp, rt, exp = _make_minimal_experiment(self)
|
|
177
|
-
# Check whether it can be disabled
|
|
178
|
-
assert 'disabled' in comp.params, (
|
|
179
|
-
f"{type(comp).__name__} does not have a 'disabled' attribute."
|
|
180
|
-
)
|
|
181
|
-
# Check that disabled defaults to False
|
|
182
|
-
assert comp.params['disabled'].val is False, f"{type(comp).__name__} is defaulting to disabled."
|
|
183
|
-
|
|
184
|
-
def test_code_muting(self):
|
|
185
|
-
"""
|
|
186
|
-
Test that components are only written when enabled and targets match.
|
|
187
|
-
"""
|
|
188
|
-
# Make minimal experiment just for this test
|
|
189
|
-
comp, rt, exp = _make_minimal_experiment(self)
|
|
190
|
-
# Skip for Code components as these purely inject code, name isn't used
|
|
191
|
-
if type(comp).__name__ in ("CodeComponent"):
|
|
192
|
-
pytest.skip()
|
|
193
|
-
# Write experiment and check that component is written
|
|
194
|
-
pyScript = exp.writeScript(target="PsychoPy")
|
|
195
|
-
if "PsychoPy" in type(comp).targets:
|
|
196
|
-
assert comp.name in pyScript, (
|
|
197
|
-
f"{type(comp).__name__} not found in compiled Python script when enabled and PsychoPy in targets."
|
|
198
|
-
)
|
|
199
|
-
else:
|
|
200
|
-
assert comp.name not in pyScript, (
|
|
201
|
-
f"{type(comp).__name__} found in compiled Python script when enabled but PsychoPy not in targets."
|
|
202
|
-
)
|
|
203
|
-
# ## disabled until js can compile without saving
|
|
204
|
-
# jsScript = exp.writeScript(target="PsychoJS")
|
|
205
|
-
# if "PsychoJS" in type(comp).targets:
|
|
206
|
-
# assert comp.name in jsScript, (
|
|
207
|
-
# f"{type(comp).__name__} not found in compiled Python script when enabled and PsychoJS in targets."
|
|
208
|
-
# )
|
|
209
|
-
# else:
|
|
210
|
-
# assert comp.name not in jsScript, (
|
|
211
|
-
# f"{type(comp).__name__} found in compiled Python script when enabled but PsychoJS not in targets."
|
|
212
|
-
# )
|
|
213
|
-
|
|
214
|
-
# Disable component then do same tests but assert not present
|
|
215
|
-
comp.params['disabled'].val = True
|
|
216
|
-
|
|
217
|
-
pyScript = exp.writeScript(target="PsychoPy")
|
|
218
|
-
if "PsychoPy" in type(comp).targets:
|
|
219
|
-
assert comp.name not in pyScript, (
|
|
220
|
-
f"{type(comp).__name__} found in compiled Python script when disabled but PsychoPy in targets."
|
|
221
|
-
)
|
|
222
|
-
else:
|
|
223
|
-
assert comp.name not in pyScript, (
|
|
224
|
-
f"{type(comp).__name__} found in compiled Python script when disabled and PsychoPy not in targets."
|
|
225
|
-
)
|
|
226
|
-
# ## disabled until js can compile without saving
|
|
227
|
-
# jsScript = exp.writeScript(target="PsychoJS")
|
|
228
|
-
# if "PsychoJS" in type(comp).targets:
|
|
229
|
-
# assert comp.name not in jsScript, (
|
|
230
|
-
# f"{type(comp).__name__} found in compiled Python script when disabled but PsychoJS in targets."
|
|
231
|
-
# )
|
|
232
|
-
# else:
|
|
233
|
-
# assert comp.name not in jsScript, (
|
|
234
|
-
# f"{type(comp).__name__} found in compiled Python script when disabled and PsychoJS not in targets."
|
|
235
|
-
# )
|
|
236
|
-
|
|
237
|
-
def test_disabled_components_stay_in_routine(self):
|
|
238
|
-
"""
|
|
239
|
-
Test that disabled components aren't removed from their routine when experiment is written.
|
|
240
|
-
"""
|
|
241
|
-
comp, rt, exp = _make_minimal_experiment(self)
|
|
242
|
-
# Disable component
|
|
243
|
-
comp.params['disabled'].val = True
|
|
244
|
-
# Writing the script drops the component but, if working properly, only from a copy of the routine, not the
|
|
245
|
-
# original!
|
|
246
|
-
exp.writeScript()
|
|
247
|
-
|
|
248
|
-
assert comp in rt, f"Disabling {type(comp).name} appears to remove it from its routine on compile."
|
|
249
|
-
|
|
250
337
|
|
|
251
338
|
class _TestDepthMixin:
|
|
252
339
|
def test_depth(self):
|
|
253
340
|
# Make minimal experiment
|
|
254
|
-
comp, rt, exp =
|
|
341
|
+
comp, rt, exp = self.make_minimal_experiment()
|
|
255
342
|
# Get class we're currently working with
|
|
256
343
|
compClass = type(comp)
|
|
257
344
|
# Add index to component name
|