from .. import os from .. import D_OFORMAT, D_OPATH from .. import MyFig, MyWin from .. import SEVR, WARN, DBUG, SPCE from .. import _G_WINDOWS from . import readStupidData, readStupidData2 # 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) # TEST 1.* for testing MyData # TEST 2.* for testing MyAxes # TEST 3.* for testing MyFig # TEST 4.* for testing MyWin # TEST 5.* for testing myTool # TEST 4.00: test create of MyFig and PRINT TO SCREEN (EXPECTED: TRUE) def test400(debug): status = True data1 = readStupidData('data1') fig = MyFig(inputarg=data1) win = MyWin(fig) try: if win.canvas.figure.keywords['debug']: pass status = True except: print(SEVR + "I can not access the figure from the manager...") status = False win.close() del win del fig del data1 return(status) # TEST 300: test the update of inputarg (EXPECTED: TRUE) def test300(debug): 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) # 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) # 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) # TEST 401: Verify the well behaving of MyWin::close (EXPECTED: TRUE) def test401(debug): # create figure data1 = readStupidData('data1') fig = MyFig(inputarg=data1) if debug: print(DBUG + "An object MyFig with data1 has been created.") win = MyWin(fig) win.close() if debug: print(DBUG + "The window 0 has been closed.") # verify that window suppressed from _G_WINDOWS try: _G_WINDOWS[0].canvas.figure.clf() status = False except: status = True del win del fig del data1 return(status) # TEST 402: Test MyWin::refresh (EXPECTED: True) def test402(debug): status = True data1 = readStupidData('data1') data2 = readStupidData2('data2') fig = MyFig(inputarg=data1) if(debug): print(DBUG + "Created a MyFig object with data1.") win = MyWin(fig) if(debug): print(DBUG + "Created window num=0 for fig.") fig.update(inputarg=data2) if(debug): print(DBUG + "Updated fig with data2") win.refresh() if(debug): print(DBUG + "Refreshed the window with actualized fig.") if(win.canvas.figure.keywords['inputarg'] != data2): status = False win.close() del win del fig del data1 del data2 return(status) # TEST 403: Test MyFig::print2file And MyWin::refresh (EXPECTED: True) 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)