-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathtestplotlyupdate.m
More file actions
204 lines (190 loc) · 7.57 KB
/
testplotlyupdate.m
File metadata and controls
204 lines (190 loc) · 7.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
classdef testplotlyupdate < matlab.unittest.TestCase
%NOTE: read and write permission on all plotly/matlab toolbox paths
%required to run testplotlyupdate.m
methods(TestMethodSetup)
function setupPlotlyVersion(testCase)
pv = which('plotly_version.m','-all');
for d = 1:length(pv)
copyfile(pv{d},fullfile(fileparts(pv{d}),'plotly_version_temp.m'));
end
end
end
methods(TestMethodTeardown)
function tearDownPlotlyVersion(testCase)
pvtemp = which('plotly_version_temp.m','-all');
pv = which('plotly_version.m','-all');
for d = 1:length(pv)
copyfile(pvtemp{d},pv{d});
delete(pvtemp{d});
end
end
end
methods (Test)
%test no version found
function testNoVersion(testCase)
pv = which('plotly_version.m','-all');
for d = 1:length(pv);
rmpath(genpath(fileparts(pv{d})))
end
except = plotlyupdate;
actual = except.identifier;
expected = 'plotly:noVersion';
testCase.verifyEqual(actual,expected);
for d = 1:length(pv);
addpath(genpath(fileparts(pv{d})))
end
end
%test Plotly not found
function testPlotlyNotFound(testCase)
ply = which('plotly.m','-all');
pv = which('plotly_version.m');
pu = which('plotlyupdate.m');
for d = 1:length(ply);
tempdir{d} = fullfile(fileparts(ply{d}),'testplotlyupdate_temp');
mkdir(tempdir{d});
movefile(ply{d},tempdir{d});
end
except = plotlyupdate;
actual = except.identifier;
expected = 'plotly:missingScript';
testCase.verifyEqual(actual,expected);
for d = 1:length(ply);
movefile(fullfile(tempdir{d},'plotly.m'),fileparts(ply{d}));
rmdir(tempdir{d})
end
end
%test Plotly already up to date
function testAlreadyUp2Date(testCase)
% remote Plotly API MATLAB Library url
remote = ['https://raw.githubusercontent.com/plotly/MATLAB-api/',...
'plotlyclass/plotly/plotly_aux/plotly_version.m'];
pvContent = urlread(remote);
pvBounds = strfind(pvContent,'''');
pvRemote = pvContent(pvBounds(1)+1:pvBounds(2)-1);
clear plotly_version.m
testCase.setversion(pvRemote);
except = plotlyupdate;
actual = except.identifier;
expected = 'plotly:alreadyUpdated';
testCase.verifyEqual(actual,expected);
end
%test create temp update dir. no permission attempt
function testTempUpdateWriteNoPermission(testCase)
%change plotly_version
clear plotly_version.m;
testCase.setversion('1.3.1');
fileattrib(pwd,'-w');
pu = which('plotlyupdate.m');
addpath(genpath(fileparts(pu)));
fprintf('\nTESTING UPDATE: HIT Y + ENTER\n\n');
except = plotlyupdate;
actual = except.identifier;
expected = 'plotlyupdate:makeUpdateDir';
testCase.verifyEqual(actual,expected);
fileattrib(pwd,'+w');
end
%test proper update
function testProperUpdate(testCase)
pvOld = '1.3.1';
clear plotly_version.m;
testCase.setversion(pvOld);
remote = ['https://raw.githubusercontent.com/plotly/MATLAB-api/',...
'plotlyclass/plotly/plotly_aux/plotly_version.m'];
pvContent = urlread(remote);
pvBounds = strfind(pvContent,'''');
pvRemote = pvContent(pvBounds(1)+1:pvBounds(2)-1);
fprintf('\nTESTING UPDATE: HIT Y + ENTER\n\n');
plotlyupdate;
pv = which('plotly_version.m','-all');
actual = cell(1,length(pv));
expected = cell(1,length(pv));
for d = 1:length(pv)
clear plotly_version.m;
actual{d} = plotly_version;
expected{d} = pvRemote;
end
testCase.verifyEqual(actual,expected);
end
%test no overwrite of Plotly dir files
function testNoOverwritePlotly(testCase)
pvOld = '1.3.1';
clear plotly_version.m;
testCase.setversion(pvOld);
ply = which('plotly','-all');
for d = 1:length(ply)
mkdir(fullfile(fileparts(ply{d}),'testOverwrite'));
end
actual = cell(1,length(ply));
expected = cell(1,length(ply));
fprintf('\nTESTING UPDATE: HIT Y + ENTER\n\n');
plotlyupdate;
for d = 1:length(ply);
actual{d} = exist(fullfile(fileparts(ply{d}),'testOverwrite'),'dir');
expected{d} = 7;%name is a folder id
end
testCase.verifyEqual(actual,expected);
for d = 1:length(ply);
rmpath(fullfile(fileparts(ply{d}),'testOverwrite'));
rmdir(fullfile(fileparts(ply{d}),'testOverwrite'));
end
end
%test no overwrite of root rep files
function testNoOverwriteRepoRoot(testCase)
pvOld = '1.3.1';
clear plotly_version.m;
testCase.setversion(pvOld);
plyset = which('plotlysetup','-all');
for d = 1:length(plyset)
mkdir(fullfile(fileparts(plyset{d}),'testOverwrite'));
end
actual = cell(1,length(plyset));
expected = cell(1,length(plyset));
fprintf('\nTESTING UPDATE: HIT Y + ENTER\n\n');
plotlyupdate;
for d = 1:length(plyset);
actual{d} = exist(fullfile(fileparts(plyset{d}),'testOverwrite'),'dir');
expected{d} = 7;%name is a folder id
end
testCase.verifyEqual(actual,expected);
for d = 1:length(plyset);
rmdir(fullfile(fileparts(plyset{d}),'testOverwrite'));
end
end
%test file cleanup
function testCleanUpFiles(testCase)
pvOld = '1.3.1';
clear plotly_version.m;
testCase.setversion(pvOld);
plyset = which('plotlysetup','-all');
for d = 1:length(plyset)
%NEED TO ADD testclean.m TO CLEANUP REMOVEFILES!!
testplyclean{d} = fullfile(fileparts(plyset{d}),'testclean.m');
copyfile(plyset{d},testplyclean{d});
end
actual = cell(1,length(plyset));
expected = cell(1,length(plyset));
fprintf('\nTESTING UPDATE: HIT Y + ENTER\n\n');
plotlyupdate;
for d = 1:length(plyset);
actual{d} = exist(testplyclean{d},'file');
expected{d} = 0;
end
testCase.verifyEqual(actual,expected);
if(~isequal(actual,expected))
for d = 1:length(plyset)
delete(testplyclean{d});
end
end
end
end
methods (Static)
function setversion(ver)
pv = which('plotly_version.m','-all');
for d = 1:length(pv)
fid = fopen(pv{d},'w');
fprintf(fid,'%s',['function version=plotly_version();version = ''' ver ''';end']);
fclose(fid);
end
end
end
end