tests.py 7.39 KB
Newer Older
1
2
3
4
5
from .. import os
from .. import D_OFORMAT, D_OPATH
from .. import MyFig, MyWin
from .. import SEVR, WARN, DBUG, SPCE
from .. import _G_WINDOWS
6

7
from . import readStupidData, readStupidData2
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

# TESTER
def myTest(function, expected, failed, debug):
    
    if debug:
        status = function(debug)
        if status is not expected:
            failed.append(str(function.__name__))
            return(False)
        else:
            return(True)
    else:
        try:
            status = function(debug)
            if status is not expected:
                failed.append(str(function.__name__))
                return(False)
            else:
                return(True)
        except:
            print(WARN + str(function.__name__) + " caught exception.")
            failed.append(str(function.__name__))
            return(False)
        
    return(True)

34
35
36
37
# TEST 1.* for testing MyData
# TEST 2.* for testing MyAxes
# TEST 3.* for testing MyFig
# TEST 4.* for testing MyWin
38
# TEST 5.* for testing myTool
39

40
41
42

# TEST 4.00: test create of MyFig and PRINT TO SCREEN (EXPECTED: TRUE)
def test400(debug):
43
44
45
46
47
    
    status = True
    
    data1 = readStupidData('data1')
    fig = MyFig(inputarg=data1)
48
    win = MyWin(fig)
49
50
    
    try:
51
        if win.canvas.figure.keywords['debug']:
52
53
54
55
56
57
58
            pass
        
        status = True
    except:
        print(SEVR + "I can not access the figure from the manager...")
        status = False
    
59
60
    win.close()
    del win
61
62
63
64
65
66
    del fig
    del data1
    
    return(status)


67
68
# TEST 300: test the update of inputarg (EXPECTED: TRUE)
def test300(debug):
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
    
    status = True
    
    data1 = readStupidData('data1')
    data2 = readStupidData2('data2')
    fig = MyFig(inputarg=data1)
    
    fig.update(inputarg=data2)
    
    if(fig.keywords['inputarg'] != data2):
        status = False
    
    del fig
    del data1
    del data2
    
    return(status)


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
204
205
206
207
# TEST 301: Test MyFig::print2file (EXPECTED: True)
def test301(debug):
    
    if os.path.exists("./myplotlib/img/test301.png"):
        os.remove("./myplotlib/img/test301.png")
    
    status = True
    
    data1 = readStupidData('data1')
    
    fig = MyFig(inputarg=data1)
    fig.print2file('test301.png', opath='myplotlib/img/')  # create img/test301.png
    
    if not os.path.exists("./myplotlib/img/test301.png"):
        status = False
    
    del fig
    del data1
    
    return(status)


# TEST 302: Test MyFig::print2file (EXPECTED: True)
def test302(debug):
    
    if os.path.exists("./myplotlib/img/test302.eps"):
        os.remove("./myplotlib/img/test302.eps")
    
    status = True
    
    data1 = readStupidData('data1')
    
    fig = MyFig(inputarg=data1)
    
    if debug:
        print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test302.eps")
    
    fig.print2file('test302.eps', opath='myplotlib/img/')  # create img/test302.eps
    
    if not os.path.exists("./myplotlib/img/test302.eps"):
        status = False
    
    del fig
    del data1
    
    return(status)


# TEST 303: Test MyFig::print2file (EXPECTED: True)
def test303(debug):
    
    status = True
    
    data1 = readStupidData('data1')
    
    fig = MyFig(inputarg=data1)
    
    if debug:
        print(DBUG + "Try to print MyFig with data1 in a non existing file.")
    
    status = fig.print2file('test303', opath='somePathThatDoesNotExists/NoWhere')  # should return False
    
    del fig
    del data1
    
    return(not status)


# TEST 304: Test MyFig::print2file (EXPECTED: True)
def test304(debug):
    
    if os.path.exists("./myplotlib/img/test304.eps"):
        os.remove("./myplotlib/img/test304.eps")
    
    status = True
    
    data1 = readStupidData('data1')
    
    fig = MyFig(inputarg=data1)
    
    if debug:
        print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test304.eps")
    
    fig.print2file('test304', oformat='.eps', opath='myplotlib/img/')  # create img/test304.eps
    
    if not os.path.exists("./myplotlib/img/test304.eps"):
        status = False
    
    del fig
    del data1
    
    return(status)


# TEST 305: Test MyFig::print2file (EXPECTED: True)
def test305(debug):
    
    if os.path.exists("./myplotlib/img/test305.png"):
        os.remove("./myplotlib/img/test305.png")
    
    status = True
    
    data1 = readStupidData('data1')
    
    fig = MyFig(inputarg=data1)
    
    if debug:
        print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test305.png")
    
    fig.print2file('test305', oformat='png', opath='myplotlib/img/')  # create img/test305.png
    
    if not os.path.exists("./myplotlib/img/test305.png"):
        status = False
    
    del fig
    del data1
    
    return(status)


208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# TEST 306: Test MyFig::print2file (EXPECTED: True)
def test306(debug):
    
    if os.path.exists("./myplotlib/img/test306.png"):
        os.remove("./myplotlib/img/test306.png")
    
    status = True
    
    data1 = readStupidData('data1')
    
    fig = MyFig(inputarg=data1)
    
    if debug:
        print(DBUG + "Try to print MyFig with data1 in myplotlib/img/test306.png")
    
    fig.print2file('myplotlib/img/test306.png')  # create img/test306.png
    
    if not os.path.exists("./myplotlib/img/test306.png"):
        status = False
    
    del fig
    del data1
    
    return(status)


234
# TEST 401: Verify the well behaving of MyWin::close (EXPECTED: TRUE)
235
def test401(debug):
236
237
238
239
240
241
242
    
    # create figure
    data1 = readStupidData('data1')
    fig = MyFig(inputarg=data1)
    if debug:
        print(DBUG + "An object MyFig with data1 has been created.")
    
243
244
245
    win = MyWin(fig)
    win.close()
    if debug:
246
247
        print(DBUG + "The window 0 has been closed.")
    
248
    # verify that window suppressed from _G_WINDOWS
249
    try:
250
251
        _G_WINDOWS[0].canvas.figure.clf()
        status = False
252
253
254
    except:
        status = True
    
255
    del win
256
257
258
259
260
261
    del fig
    del data1
    
    return(status)


262
# TEST 402: Test MyWin::refresh (EXPECTED: True)
263
def test402(debug):
264
265
266
267
268
269
270
271
272
    
    status = True
    
    data1 = readStupidData('data1')
    data2 = readStupidData2('data2')
    
    fig = MyFig(inputarg=data1)
    if(debug): print(DBUG + "Created a MyFig object with data1.")
    
273
    win = MyWin(fig)
274
275
276
277
278
    if(debug): print(DBUG + "Created window num=0 for fig.")
    
    fig.update(inputarg=data2)
    if(debug): print(DBUG + "Updated fig with data2")
    
279
    win.refresh()
280
281
282
283
284
    if(debug): print(DBUG + "Refreshed the window with actualized fig.")
    
    if(win.canvas.figure.keywords['inputarg'] != data2):
        status = False
    
285
    win.close()
286
    
287
    del win
288
289
290
291
292
    del fig
    del data1
    del data2
    
    return(status)
293
294


295
# TEST 403: Test MyFig::print2file And MyWin::refresh (EXPECTED: True)
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
def test403(debug):
    
    status = True
    
    data1 = readStupidData('data1')
    data2 = readStupidData2('data2')
    
    fig = MyFig(inputarg=data1)
    
    if(debug):
        print(DBUG + "Put a MyFig into a MyWin with data1")
    win = MyWin(fig)
    
    if(debug):
        print(SPCE + "Now print the fig into dummyTestFile.png")
    fig.print2file('dummyTestFile.png', opath='myplotlib/img/')
    
    if(debug):
        print(SPCE + "Update inputarg to data2")
    fig.update(inputarg=data2)
    
    if(debug):
        print(SPCE + "Now refresh the window.")
    # refresh the window (This should return True)
    status = win.refresh()
    
    fig.print2file('dummyTestFile2.png', opath='myplotlib/img/')
    
    win.close()
    del fig
    del data1
    del data2
    
    return(status)