Commit b8a434f4 authored by Yori 'AGy' Fournier's avatar Yori 'AGy' Fournier
Browse files

add the Tests for myTool, see test500, 501, 502, 503, 504, 505, 506, 507 and...

add the Tests for myTool, see test500, 501, 502, 503, 504, 505, 506, 507 and 508. I also added two functions in myTools: window_exists and getCurrentWindowIDs. corrected the bug that prevent fig.fignum to be actualized. It came from MyWin still using fig.keywords['fignum'] instead of fig.fignum. rmrk: in python fig.dict['key'] = value will not rise an error even if key does not exists.
parent e9aaf314
......@@ -114,6 +114,7 @@ else:
print(SEVR + "The backend you choosed is not supported interactive mode not available")
# myTool.*: interface functions to use myplotlib interactively
from .myTool import window_exists, getCurrentWindowIDs
from .myTool import print2file, print2screen, printListCurrentWindows
from .myTool import getWindow, getFigOnWindow, drawFigOnWindow, giveDataToWindow
from .myTool import closeWindow, closeAllWindows
......@@ -126,6 +127,8 @@ from .test import test200, test201, test202
from .test import test300, test301, test302, test303, test304, test305
from .test import test306, test307, test308, test309, test310
from .test import test400, test401, test402, test403
from .test import test500, test501, test502, test503, test504
from .test import test505, test506, test507, test508
from .test import test600
# the tests to run
......@@ -134,5 +137,7 @@ testList = [test100,
test300, test301, test302, test303, test304, test305,
test306, test307, test308, test309, test310,
test400, test401, test402,
test503, test506, test500, test507, test501, test502,
test504, test505, test508,
test600,
]
......@@ -33,6 +33,7 @@
# IMPORT ---------------------------------------------------------------
from .__init__ import INFO, SPCE, DBUG
from .__init__ import myTest, testList
from .__init__ import __dict__
import sys
import getopt
......@@ -67,9 +68,21 @@ for opt, arg in opts:
print(usage)
sys.exit(0)
elif opt in ("-t", "--test"):
elif opt in ("-t"):
run4Test = True
elif opt in ("--test"):
run4Test = True
tests = arg.split(', ')
testList = []
for test in tests:
if test in __dict__.keys():
testList.append(__dict__[test])
if len(testList) == 0:
print(" > sevr-: you need to give valid tests to be tested.")
exit(1)
elif opt in ("-p", "--plot"):
run4Plot = True
arg4Plot = str(arg)
......
......@@ -76,13 +76,37 @@ def print2screen(ClassName, inputArg, *args, **kwargs):
return(True)
def printListCurrentWindows():
def window_exists(ID):
if ID in getCurrentWindowIDs():
status = True
else:
status = False
return(status)
def getCurrentWindowIDs():
IDs = []
for window in _G_WINDOWS:
if window == _G_WINDOWS[0]:
print(INFO + "Figure " + window.num)
IDs.append(window.num)
return(IDs)
def printListCurrentWindows():
windowIDs = getCurrentWindowIDs()
for windowID in windowIDs:
if windowID == _G_WINDOWS[0].num:
print(INFO + "Figure " + str(windowID))
else:
print(SPCE + "Figure " + window.num)
print(SPCE + "Figure " + str(windowID))
return(True)
def getWindow(ID):
......@@ -107,7 +131,14 @@ def getFigOnWindow(ID):
def drawFigOnWindow(fig, ID):
return(MyWin(fig, fignum=ID))
if window_exists(ID):
win = getWindow(ID)
win.set_figure(fig)
win.refresh()
else:
win = MyWin(fig, fignum=ID)
return(win)
def giveDataToWindow(data, ID):
......
......@@ -104,7 +104,7 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
# bounded to another window
if fig.boundedToWin:
# if it is the case close the bounded window.
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[np.where([(window.num == fig.fignum) for window in _G_WINDOWS])[0][0]]
win.close()
# Call FigureManagerGTK class
......@@ -116,7 +116,7 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
# bound the figure to the window
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = num
self.canvas.figure.fignum = num
# add the window in the global variable _G_WINDOWS
# this guarenty that you never loose a window
......@@ -136,14 +136,14 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
fig.canvas = self.canvas
self.canvas.figure = fig
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = self.num
self.canvas.figure.fignum = self.num
# UNBOUND ----------------------------------------------------------
def _unboundFigure_(self):
self.canvas.figure.boundedToWin = False
self.canvas.figure.keywords['fignum'] = -1
self.canvas.figure.fignum = -1
# SETTERS ----------------------------------------------------------
......@@ -156,7 +156,7 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
# if the new figure is already bounded close
# its former container.
if fig.boundedToWin:
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[np.where([(window.num == fig.fignum) for window in _G_WINDOWS])[0][0]]
win.close()
# bound the new figure
......@@ -183,7 +183,7 @@ class MyWin_GTKAgg(FigureManagerGTKAgg):
def drawFigure(self, fig):
# if the figure is not the current one
if(fig.keywords['fignum'] != self.num):
if(fig.fignum != self.num):
# cleanly set the new figure
self.set_figure(fig)
......
......@@ -113,7 +113,7 @@ class MyWin_TkAgg(FigureManagerTkAgg):
# bounded to another window
if fig.boundedToWin:
# if it is the case close the bounded window.
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[np.where([(window.num == fig.fignum) for window in _G_WINDOWS])[0][0]]
win.close()
# Call FigureManagerTkAgg class
......@@ -133,7 +133,7 @@ class MyWin_TkAgg(FigureManagerTkAgg):
# bound the figure to the window
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = num
self.canvas.figure.fignum = num
# add the window in the global variable _G_WINDOWS
# this guarenty that you never loose a window
......@@ -152,14 +152,14 @@ class MyWin_TkAgg(FigureManagerTkAgg):
fig.canvas = self.canvas
self.canvas.figure = fig
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = self.num
self.canvas.figure.fignum = self.num
# UNBOUND ----------------------------------------------------------
def _unboundFigure_(self):
self.canvas.figure.boundedToWin = False
self.canvas.figure.keywords['fignum'] = -1
self.canvas.figure.fignum = -1
# SETTERS ----------------------------------------------------------
......@@ -172,7 +172,7 @@ class MyWin_TkAgg(FigureManagerTkAgg):
# if the new figure is already bounded close
# its former container.
if fig.boundedToWin:
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[np.where([(window.num == fig.fignum) for window in _G_WINDOWS])[0][0]]
win.close()
# bound the new figure
......@@ -199,7 +199,7 @@ class MyWin_TkAgg(FigureManagerTkAgg):
def drawFigure(self, fig):
# if the figure is not the current one
if(fig.keywords['fignum'] != self.num):
if(fig.fignum != self.num):
# cleanly set the new figure
self.set_figure(fig)
......
......@@ -107,7 +107,7 @@ class MyWin_WXAgg(FigureManagerWx):
# bounded to another window
if fig.boundedToWin:
# if it is the case close the bounded window.
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[np.where([(window.num == fig.fignum) for window in _G_WINDOWS])[0][0]]
win.close()
# Call the ugly FigureManagerWxAgg class
......@@ -129,7 +129,7 @@ class MyWin_WXAgg(FigureManagerWx):
# bound the figure to the window
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = num
self.canvas.figure.fignum = num
# add the window in the global variable _G_WINDOWS
# this guarenty that you never loose a window
......@@ -149,14 +149,14 @@ class MyWin_WXAgg(FigureManagerWx):
fig.canvas = self.canvas
self.canvas.figure = fig
self.canvas.figure.boundedToWin = True
self.canvas.figure.keywords['fignum'] = self.num
self.canvas.figure.fignum = self.num
# UNBOUND ----------------------------------------------------------
def _unboundFigure_(self):
self.canvas.figure.boundedToWin = False
self.canvas.figure.keywords['fignum'] = -1
self.canvas.figure.fignum = -1
# SETTERS ----------------------------------------------------------
......@@ -169,7 +169,7 @@ class MyWin_WXAgg(FigureManagerWx):
# if the new figure is already bounded close
# its former container.
if fig.boundedToWin:
win = _G_WINDOWS[np.where([(window.num == fig.keywords['fignum']) for window in _G_WINDOWS])[0][0]]
win = _G_WINDOWS[np.where([(window.num == fig.fignum) for window in _G_WINDOWS])[0][0]]
win.close()
# bound the new figure
......@@ -198,7 +198,7 @@ class MyWin_WXAgg(FigureManagerWx):
def drawFigure(self, fig):
# if the figure is not the current one
if(fig.keywords['fignum'] != self.num):
if(fig.fignum != self.num):
# cleanly set the new figure
self.set_figure(fig)
......
......@@ -11,5 +11,7 @@ from tests import test200, test201, test202
from tests import test300, test301, test302, test303, test304, test305
from tests import test306, test307, test308, test309, test310
from tests import test400, test401, test402, test403
from tests import test500, test501, test502, test503, test504
from tests import test505, test506, test507, test508
from tests import test600
......@@ -8,6 +8,12 @@ from .. import G_RAWDATAS, _G_WINDOWS
from . import readStupidData, readStupidData2
from . import FigTest2, AxTest1
from .. import window_exists, getCurrentWindowIDs
from .. import getFigOnWindow, getWindow
from .. import closeWindow, closeAllWindows
from .. import print2screen, print2file, printListCurrentWindows
from .. import drawFigOnWindow, giveDataToWindow
# TESTER
def myTest(function, expected, failed, debug):
......@@ -674,17 +680,176 @@ def test500(debug):
return(status)
# TEST 5.07: closeAllWindows
def test507(debug):
status = True
data = readStupidData('data1')
print2screen(FigTest2, (data,), fignum=1)
print2screen(FigTest2, (data,), fignum=4)
closeAllWindows()
if(len(_G_WINDOWS) != 0):
status = False
del data
return(status)
# TEST 5.01: printListCurrentWindows
def test501(debug):
status = True
data = readStupidData('data1')
print2screen(FigTest2, (data,), fignum=1)
print2screen(FigTest2, (data,), fignum=24)
print2screen(FigTest2, (data,), fignum=4)
print2screen(FigTest2, (data,), fignum=1)
IDs = getCurrentWindowIDs()
if(IDs != [24, 4, 1]):
status = False
if(debug):
print(DBUG + "IDs: " + str(IDs) + ", should be 24, 4, 1.")
closeAllWindows()
del data
return(status)
# TEST 5.02: getWindow
def test502(debug):
status = True
data = readStupidData('data1')
win = MyWin(FigTest2((data,)), fignum=2)
if(win != getWindow(2)):
status = False
win.close()
del data
return(status)
# TEST 5.04: drawFigOnWindow
def test504(debug):
status = True
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
fig1 = FigTest2((data1,))
win = drawFigOnWindow(fig1, 12)
if not (fig1.boundedToWin and fig1.fignum == 12):
status = False
if(debug): print(DBUG + "fig1 does not have the correct param.")
if(win.canvas.figure != fig1):
status = False
if(debug): print(DBUG + "fig1 is not the figure of the window's canvas.")
if(win.canvas != fig1.canvas):
status = False
if(debug): print(DBUG + "The canvas of fig1 is not the one of the window.")
fig2 = FigTest2((data2,))
if(win != drawFigOnWindow(fig2, 12)):
status = False
if(debug): print(DBUG + "The window changed...")
if(fig1.boundedToWin or fig1.fignum != -1):
status = False
if(debug): print(DBUG + "fig1 does not have the correct param.")
if not (fig2.boundedToWin and fig2.fignum == 12):
status = False
if(debug):
print(DBUG + "fig2 does not have the correct param.")
if(win.canvas.figure != fig2):
status = False
if(debug): print(DBUG + "fig2 is not the figure of the window's canvas.")
if(win.canvas != fig2.canvas):
status = False
if(debug): print(DBUG + "The canvas of fig2 is not the one of the window.")
win.close()
del fig1
del fig2
del data1
del data2
return(status)
# TEST 5.05: giveDataToWindow
def test505(debug):
status = True
data1 = readStupidData('data1')
data2 = readStupidData2('data2')
print2screen(FigTest2, (data1,))
giveDataToWindow((data2,), 0)
win = getWindow(0)
if(win.canvas.figure.rawdata != (data2,)):
status = False
if(debug): print(DBUG + "the rawdata of the figure are not correct.")
ax = win.canvas.figure.get_axes()[0]
if(ax.data != {'xdata': [data2.data[0], data2.data[1]],
'ydata': [data2.data[2], data2.data[3]]}):
print(DBUG + "ax.data = " + str(ax.data))
print(SPCE + "it should be " + str(data2.data))
status = False
if(debug): print(DBUG + "the data were not formatted by the axes.")
win.close()
del ax
del data1
del data2
return(status)
# TEST 5.07: closeAllWindows
# TEST 5.08: print2file
def test508(debug):
if os.path.exists("./myplotlib/img/test508.png"):
os.remove("./myplotlib/img/test508.png")
status = True
data1 = readStupidData('data1')
if debug:
print(DBUG + "Try to print FigTest2 with data1 in myplotlib/img/test508.png")
print2file(FigTest2, (data1,), "./myplotlib/img/test508.png")
if not os.path.exists("./myplotlib/img/test508.png"):
status = False
del data1
return(status)
# TEST 600: Test Adding Axes on the Fly (EXPECTED: True)
def test600(debug):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment