Skip to content

Commit 42c5390

Browse files
authored
Merge branch 'dev' into mpepBindServerTest
2 parents 0801252 + d96cbbb commit 42c5390

File tree

8 files changed

+181
-39
lines changed

8 files changed

+181
-39
lines changed

+srv/StimulusControl.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ function delete(obj)
178178
end
179179
end
180180

181-
methods %(Access = protected) %TODO Check everything works as protected
181+
methods (Access = protected)
182182
function b = connected(obj)
183183
b = ~isempty(obj.Socket) && obj.Socket.isOpen();
184184
end
@@ -288,7 +288,7 @@ function send(obj, id, data)
288288
methods (Static)
289289
function errorOnFail(r)
290290
if iscell(r) && strcmp(r{1}, 'fail')
291-
error(r{3});
291+
error(r{3:end})
292292
end
293293
end
294294
end

+srv/expServer.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ function expServer(useTimelineOverride, bgColour)
4343
timelineToggleKey = KbName('t');
4444
toggleBackground = KbName('b');
4545
rewardId = 1;
46+
% Function for constructing a full ID for warnings and errors
47+
fullID = @(id) strjoin([{'Rigbox:srv:expServer'}, ensureCell(id)],':');
4648

4749
%% Initialisation
4850
% Pull latest changes from remote
@@ -56,7 +58,7 @@ function expServer(useTimelineOverride, bgColour)
5658
required = {'stimWindow', 'timeline', 'daqController'};
5759
present = isfield(iff(isempty(rig), struct, rig), required);
5860
if ~all(present)
59-
error('rigbox:srv:expServer:missingHardware', ['Rig''s ''hardware.mat'''...
61+
error(fullID('missingHardware'), ['Rig''s ''hardware.mat'''...
6062
' file not set up correctly. The following objects are missing:\n\r%s'],...
6163
strjoin(required(~present), '\n'))
6264
end
@@ -84,6 +86,7 @@ function expServer(useTimelineOverride, bgColour)
8486
@() delete(listener),...
8587
@() rig.stimWindow.close(),...
8688
@() aud.close(rig.audio),...
89+
@() rig.scale.cleanup()
8790
}));
8891

8992
% OpenGL
@@ -235,7 +238,7 @@ function handleMessage(id, data, host)
235238
end
236239
else
237240
log('Failed because experiment ref ''%s'' does not exist', expRef);
238-
communicator.send(id, {'fail', expRef,...
241+
communicator.send(id, {'fail', expRef, fullID('expRefNotFound') ...
239242
sprintf('Experiment ref ''%s'' does not exist', expRef)});
240243
end
241244
case 'quit'
@@ -337,7 +340,6 @@ function calibrateWaterDelivery()
337340
ul = [calibration.volumeMicroLitres];
338341
log('Delivered volumes ranged from %.1ful to %.1ful', min(ul), max(ul));
339342

340-
% rigData = load(fullfile(pick(dat.paths, 'rigConfig'), 'hardware.mat'));
341343
rigHwFile = fullfile(pick(dat.paths, 'rigConfig'), 'hardware.mat');
342344

343345
save(rigHwFile, 'daqController', '-append');

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
Starting after Rigbox 2.2.0, this file contains a curated, chronologically ordered list of notable changes made to the master branch. Each bullet point in the list is followed by the accompanying commit hash, and the date of the commit. This changelog is based on [keep a changelog](https://keepachangelog.com)
44

5-
## [Most Recent Commits](https://github.com/cortex-lab/Rigbox/commits/master) 2.4.0
5+
## [Most Recent Commits](https://github.com/cortex-lab/Rigbox/commits/master) 2.5.0
6+
7+
- Added change scale port helper; fixed issue with scale cleanup on calibrate error `01e394b` 2019-11-27
8+
- Added support for remote error ids in srv.StimulusControl `9d31eea` 2019-11-27
9+
10+
11+
## [2.4.1]
612

713
- patch to readme linking to most up-to-date documentation `4ff1a21` 2019-09-16
814
- updates to `+git` package and its tests `5841dd6` 2019-09-24
@@ -19,6 +25,7 @@ Starting after Rigbox 2.2.0, this file contains a curated, chronologically order
1925
- bug fix for rounding negative numbers in AlyxPanel `31641f1` 2019-10-17
2026
- stricter and more accurate tolerance in AlyxPanel_test `31641f1` 2019-10-17
2127
- added tests for dat.mpepMessageParse and tl.bindMpepServer `bd15b95` 2019-10-21
28+
- HOTFIX to error when plotting supressed in Window calibrate `7d6b601` 2019-11-15
2229

2330
## [2.3.0](https://github.com/cortex-lab/Rigbox/releases/tag/v2.3.0)
2431

cortexlab/+hw/setScalePort.m

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
function scale = setScalePort(port, rigname)
2+
% CHANGESCALEPORT Set the port of the scale in the hardware object
3+
% Sets the COM port of the scale and saves it into the hardware file.
4+
%
5+
% Inputs:
6+
% port (char|numerical) : which port to set the hardware scale to
7+
% rigname (char) : the host name of the rig whose scale port to change
8+
%
9+
% Output:
10+
% scale (hw.WeighingScale) : the edited scale object
11+
%
12+
% Examples:
13+
% scale = setScalePort('COM3')
14+
% setScalePort(3, 'ZREDONE')
15+
%
16+
% See also HW.DEVICES
17+
if nargin < 2
18+
rigname = upper(hostname);
19+
end
20+
21+
hwPath = fullfile(getOr(dat.paths,'globalConfig'),rigname,'hardware.mat');
22+
load(hwPath, 'scale')
23+
scale.ComPort = iff(upper(port(1)) == 'C', upper(port), ['COM',num2str(port)]);
24+
save(hwPath, 'scale', '-append')

tests/Contents.m

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,38 @@
66
% check the coverage of a given test, use `checkCoverage`.
77
%
88
% Files:
9-
% runall - gathers and runs all tests in Rigbox
10-
% checkCoverage - Check the coverage of a given test
11-
% AlyxPanel_test - Tests for eui.AlyxPanel
12-
% ParamEditor_test - Tests for eui.ParamEditor
13-
% Parameters_test - Tests for exp.Parameters
14-
% calibrate_test - Tests for hw.calibrate
15-
% catStructs_test - Tests for catStructs
16-
% cellflat_test - Tests for cellflat
17-
% cellsprintf_test - Tests for cellsprintf
18-
% dat_test - Tests for the +dat package
19-
% emptyElems_test - Tests for emptyElems
20-
% ensureCell_test - Tests for ensureCell
21-
% expServer_test - Tests for srv.expServer
22-
% fileFunction_test - Tests for fileFunction
23-
% file_test - Tests for the +file package
24-
% fun_test - Tests for the +fun package
25-
% iff_test - Tests for iff
26-
% inferParams_test - inferParams test
27-
% loadVar_test - loadVar test
28-
% mapToCell_test - Tests for mapToCell function
29-
% mergeStructs_test - mergeStructs test
30-
% namedArg_test - namedArg test
31-
% nop_test - Tests for nop
32-
% num2cellstr_test - Tests for num2cellstr
33-
% obj2json_test - Tests for obj2struct
34-
% pick_test - pick test
35-
% repelems_test - repelems test
36-
% structAssign_test - structAssign test
37-
% superSave_test - superSave test
38-
% tabulateArgs_test - Tests for tabulateArgs
39-
% varName_test - varName test
9+
% runall - gathers and runs all tests in Rigbox
10+
% checkCoverage - Check the coverage of a given test
11+
% AlyxPanel_test - Tests for eui.AlyxPanel
12+
% ParamEditor_test - Tests for eui.ParamEditor
13+
% Parameters_test - Tests for exp.Parameters
14+
% StimulusControl_test - Tests for srv.StimulusControl and
15+
% srv.stimulusControllers
16+
% calibrate_test - Tests for hw.calibrate
17+
% catStructs_test - Tests for catStructs
18+
% cellflat_test - Tests for cellflat
19+
% cellsprintf_test - Tests for cellsprintf
20+
% dat_test - Tests for the +dat package
21+
% emptyElems_test - Tests for emptyElems
22+
% ensureCell_test - Tests for ensureCell
23+
% expServer_test - Tests for srv.expServer
24+
% fileFunction_test - Tests for fileFunction
25+
% file_test - Tests for the +file package
26+
% fun_test - Tests for the +fun package
27+
% iff_test - Tests for iff
28+
% inferParams_test - inferParams test
29+
% loadVar_test - loadVar test
30+
% mapToCell_test - Tests for mapToCell function
31+
% mergeStructs_test - mergeStructs test
32+
% namedArg_test - namedArg test
33+
% nop_test - Tests for nop
34+
% num2cellstr_test - Tests for num2cellstr
35+
% obj2json_test - Tests for obj2struct
36+
% pick_test - pick test
37+
% repelems_test - repelems test
38+
% structAssign_test - structAssign test
39+
% superSave_test - superSave test
40+
% tabulateArgs_test - Tests for tabulateArgs
41+
% varName_test - varName test
42+
4043

tests/StimulusControl_test.m

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
%STIMULUSCONTROL_TEST Tests for srv.StimulusControl and
2+
%srv.stimulusControllers
3+
% TODO Create tests for remaining methods
4+
classdef (SharedTestFixtures={ % add 'fixtures' folder as test fixture
5+
matlab.unittest.fixtures.PathFixture('fixtures'),...
6+
matlab.unittest.fixtures.PathFixture(['fixtures' filesep 'util'])})...
7+
StimulusControl_test < matlab.unittest.TestCase & matlab.mock.TestCase
8+
9+
properties (SetAccess = protected)
10+
% An experiment reference for the test
11+
Ref
12+
% A list of StimulusControl names for testing the remote file
13+
RemoteNames = {'Rig1', 'Sevvan', 'Reet'}
14+
end
15+
16+
methods (TestClassSetup)
17+
function setupFolder(testCase)
18+
% SETUPFOLDER Set up subject, queue and config folders for test
19+
% Creates a few folders for saving parameters and hardware. Adds
20+
% teardowns for deletion of these folders. Also creates a custom
21+
% paths file to deactivate Alyx.
22+
%
23+
% TODO Make into shared fixture
24+
25+
assert(endsWith(which('dat.paths'),...
26+
fullfile('tests', 'fixtures', '+dat', 'paths.m')));
27+
28+
% Set INTEST flag to true
29+
testCase.setTestFlag(true)
30+
testCase.addTeardown(@testCase.setTestFlag, false)
31+
32+
% Create a rig config folder
33+
configDir = getOr(dat.paths, 'rigConfig');
34+
assert(mkdir(configDir), 'Failed to create config directory')
35+
36+
% Clear loadVar cache
37+
addTeardown(testCase, @clearCBToolsCache)
38+
39+
% Create a remote file for one of the tests
40+
globalConfigDir = getOr(dat.paths, 'globalConfig');
41+
stimulusControllers = cellfun(@srv.StimulusControl.create, testCase.RemoteNames);
42+
save(fullfile(globalConfigDir, 'remote'), 'stimulusControllers')
43+
assert(file.exists(fullfile(globalConfigDir, 'remote.mat')))
44+
45+
% Add teardown to remove folders
46+
rmFcn = @()assert(rmdir(globalConfigDir, 's'), ...
47+
'Failed to remove test config folder');
48+
addTeardown(testCase, rmFcn)
49+
50+
% Set some default behaviours for some of the objects; create a ref
51+
testCase.Ref = dat.constructExpRef('test', now, randi(10000));
52+
end
53+
54+
end
55+
56+
methods (Test)
57+
58+
function test_create(testCase)
59+
% Test for constructor defaults
60+
name = testCase.RemoteNames{1};
61+
sc = srv.StimulusControl.create(name);
62+
testCase.verifyMatches(sc.Name, name, 'Failed to set Name')
63+
testCase.verifyMatches(sc.Uri, ['.*',name,':',num2str(sc.DefaultPort)])
64+
65+
uri = 'ws://rig:1428';
66+
sc = srv.StimulusControl.create(name, uri);
67+
testCase.verifyMatches(sc.Name, name, 'Failed to set Name')
68+
testCase.verifyEqual(sc.Uri, uri, 'Failed to set provided uri')
69+
end
70+
71+
function test_errorOnFail(testCase)
72+
% A message array to test
73+
id = 'test:error:failSent';
74+
msg = 'Fail message';
75+
r = {'success', testCase.Ref, id, msg};
76+
77+
srv.StimulusControl.errorOnFail('This is no error') % Test char input
78+
srv.StimulusControl.errorOnFail(r) % Test array input without fail
79+
r{1} = 'fail'; % Change message to fail state
80+
testCase.verifyError(@()srv.StimulusControl.errorOnFail(r), id, ...
81+
'Failed to throw error with ID')
82+
ex.message = [];
83+
r(3) = []; % Remove ID
84+
try srv.StimulusControl.errorOnFail(r), catch ex, end
85+
testCase.verifyMatches(ex.message, msg, 'Failed to throw error without ID')
86+
end
87+
88+
function test_stimulusControllers(testCase)
89+
% Test the loading of saved StimulusControl objects via dat.paths
90+
sc = srv.stimulusControllers;
91+
testCase.verifyLength(sc, length(testCase.RemoteNames))
92+
testCase.verifyTrue(isa(sc, 'srv.StimulusControl'))
93+
testCase.verifyEqual({sc.Name}, sort(testCase.RemoteNames), ...
94+
'Failed to return array sorted by Name')
95+
end
96+
end
97+
98+
methods (Static)
99+
function setTestFlag(TF)
100+
% SETTESTFLAG Set global INTEST flag
101+
% Allows setting of test flag via callback function
102+
global INTEST
103+
INTEST = TF;
104+
end
105+
end
106+
end

tests/expServer_test.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function test_quit(testCase)
224224
function test_devices_fail(testCase)
225225
% Set hw.devices to return empty
226226
clear devices;
227-
id = 'rigbox:srv:expServer:missingHardware';
227+
id = 'Rigbox:srv:expServer:missingHardware';
228228
testCase.verifyError(@srv.expServer, id, ...
229229
'Expected error for misconfigured hardware');
230230
end

0 commit comments

Comments
 (0)