Commit 184f16ea authored by Yori Fournier's avatar Yori Fournier
Browse files

Now all test passes, I am not yet sure is the network tests are all passing

properly but no error found.
parent 511d78c8
Pipeline #498 failed with stage
in 5 minutes and 45 seconds
......@@ -203,7 +203,7 @@ class MplClient():
if not status:
print('something went wrong '
'with the sending of newSincFigure request...')
'with the sending of new_sync_figure request...')
answer = self.wait_for_signal()
self.disconnect()
......@@ -220,6 +220,7 @@ class MplClient():
elif isinstance(answer, Status):
self.test_status_sig(query, answer)
print('>>>>>>>>>>>>>>>>>>>>>>>>>> response is not an Answer!!!')
return None
else:
print('an unknown error occured')
......
......@@ -308,7 +308,7 @@ class MplFigClient(Figure):
# try:
if (True):
datas = self.client.sync_fig_format_raw_data(self.sync_id)
datas = self.client.sync_fig_format_rawdata(self.sync_id)
# except:
# print(SEVR+'The server-side figure could not format the data...')
# return(False)
......
......@@ -92,7 +92,7 @@ class MplFigServer(object):
# initialise the attribute default values and remove them from kwargs
# need to be hard coded for interactive mode
self.fignum = kwargs.pop('fignum', MyFigServer.G_FIGNUM)
self.fignum = kwargs.pop('fignum', MplFigServer.G_FIGNUM)
self.reformat = kwargs.pop('reformat', D_REFORMAT)
self.debug = kwargs.pop('debug', D_DEBUG)
self.formatted = kwargs.pop('formatted', D_FORMATTED)
......
......@@ -97,7 +97,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
+ str(e.message) + str(e.args))
# add the figure to the global index
self.server._figures[fig.getFigID()] = fig
self.server._figures[fig.get_fig_id()] = fig
if fig.get_fig_id() in self.server._figures :
return Answer(fig.get_fig_id())
......@@ -106,7 +106,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
This function forwards the request to the corresponding figure"""
fig_id, kwargs = content
fig = self.get_fig_by_id(fig_id)
fig = self.server.get_fig_by_id(fig_id)
# if an error occured forward the signal
if isinstance(fig, Signal):
......@@ -121,7 +121,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
return Status(False, 'Kewords of figure ID: '
+ fig_id + ' could not be updated')
def treat_sync_fig_format_raw_data(self, fig_id):
def treat_sync_fig_format_rawdata(self, fig_id):
# Identify the figure
fig = self.server.get_fig_by_id(fig_id)
......@@ -132,15 +132,15 @@ class MplHandler(SocketServer.StreamRequestHandler):
# Format the rawdata
try:
fig.format_raw_data()
fig.format_rawdata()
except Exception as e:
if debug:
print(WARN + "I couldn't format the rawdata.")
print(SPCE + "SERVER: Exception details where:",
e.message,
e.args)
return Status(False, "I couldn't format the rawdata."
" Exception details where:", e.message, e.args)
return Status(False, "I couldn't format the rawdata."\
" Exception details where:" + str(e.message) + str(e.args))
# compose the formated data
datas = tuple(ax.data for ax in fig.get_axes())
......@@ -196,7 +196,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
elif request.query_type == request.UPDATESYNCFIGURE:
reply = self.treat_update_sync_figure(request.content)
elif request.query_type == request.SYNCFIGFORMATRAWDATA:
reply = self.treat_sync_fig_format_rawData(request.content)
reply = self.treat_sync_fig_format_rawdata(request.content)
elif request.query_type == request.DELETESYNCFIGURE:
reply = self.treat_delete_sync_figure(request.content)
elif request.query_type == request.LISTDATA:
......@@ -296,7 +296,7 @@ class MplServer(SocketServer.TCPServer):
print(WARN + "The figure ID: " + fig_id + " does not exist.")
return Status(False, "The figure ID: "
+ fig_id + " does not exist.")
elif isinstance(fig, MyFig):
elif isinstance(fig, MplFig):
if debug:
print('Figure ', fig_id, ' found in database')
return fig
......@@ -43,7 +43,7 @@
#
# IMPORT ---------------------------------------------------------------
from myplotlib import MyAxes
from myplotlib import MplAxes
D_XRANGE = None
D_YRANGE = None
......@@ -52,13 +52,13 @@ D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest(MyAxes):
class AxTest(MplAxes):
# DECLARE KEYWORDS -------------------------------------------------
def declare_keywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
self.keywords = {'x_range': D_XRANGE,
'y_range': D_YRANGE}
return(True)
......@@ -83,8 +83,8 @@ class AxTest(MyAxes):
def plotting(self):
xRange = self.keywords.get('xRange')
yRange = self.keywords.get('yRange')
x_range = self.keywords.get('x_range')
y_range = self.keywords.get('y_range')
try:
self.plot(self.data['xdata'], self.data['ydata'])
......@@ -92,7 +92,7 @@ class AxTest(MyAxes):
print(SEVR + 'The formatting of the data was apparently wrong. --> EXIT')
return(False)
if (xRange): self.set_xlim(xRange)
if (yRange): self.set_ylim(yRange)
if (x_range): self.set_xlim(x_range)
if (y_range): self.set_ylim(y_range)
return(True)
# IMPORT ---------------------------------------------------------------
from myplotlib import MyFig
from axTest import AxTest
from myplotlib import MplFig
from axes_tests import AxTest
class FigTest(MyFig):
class FigTest(MplFig):
FIGSIZE = (8., 6.)
......@@ -13,7 +13,7 @@ class FigTest(MyFig):
self.add_axes(AxTest(self, ratio, frame1), "p1")
class FigTest2(MyFig): # Fig with two Axes
class FigTest2(MplFig): # Fig with two Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -25,17 +25,17 @@ class FigTest2(MyFig): # Fig wi
frame1 = [0.1, 0.1, 0.4, 0.8] # part of the fig that is available
frame2 = [0.6, 0.1, 0.4, 0.8] # part of the fig that is available
self.add_axes(AxTest(self, ratio, frame1),"p1")
self.add_axes(AxTest(self, ratio, frame2),"p2")
self.add_axes(AxTest(self, ratio, frame1), "p1")
self.add_axes(AxTest(self, ratio, frame2), "p2")
def declare_aAliases(self):
def declare_aliases(self):
# it is important to not hold additional references to an axes in the figure to avoid memory leaks. use the this function
# get the plot added above
p1 = self.get_axes_by_name("p1")
p2 = self.get_axes_by_name("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
self.aliases = {'x_range_p1': (p1, "x_range"),
'x_range_p2': (p2, "x_range")}
return(True)
......@@ -35,31 +35,31 @@ from .. import MplData
# READ STUPID DATA -----------------------------------------------------
def readStupidData(ipath=D_IPATH, *args, **kwargs):
def read_stupid_data(ipath=D_IPATH, *args, **kwargs):
debug = kwargs.get('debug', 0)
lrawdata = MplData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., 1, -1.]
l_rawdata = MplData()
l_rawdata.name = str(ipath)
l_rawdata.data = [-1., 1., 1, -1.]
if(debug):
print(DBUG + 'I read the raw data with readStupidData')
return(lrawdata)
return(l_rawdata)
# READ STUPID DATA 2 ---------------------------------------------------
def readStupidData2(ipath=D_IPATH, *args, **kwargs):
def read_stupid_data_2(ipath=D_IPATH, *args, **kwargs):
debug = kwargs.get('debug', 0)
lrawdata = MplData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., -2., 2.]
l_rawdata = MplData()
l_rawdata.name = str(ipath)
l_rawdata.data = [-1., 1., -2., 2.]
if(debug):
print(DBUG + 'I read the raw data with readStupidData2')
return(lrawdata)
return(l_rawdata)
......@@ -43,7 +43,7 @@
#
# IMPORT ---------------------------------------------------------------
from . import INFO, DBUG, WARN, SEVR, SPCE
from myplotlib import MyAxes
from myplotlib import MplAxes
D_XRANGE = None
D_YRANGE = None
......@@ -51,13 +51,13 @@ D_LOGY = False
D_LOGX = False
# Class MyAxes Overwriting Matplotlib.figure.Axes
class AxTest(MyAxes):
class AxTest(MplAxes):
# DECLARE KEYWORDS -------------------------------------------------
def declare_keywords(self):
self.keywords = {'xRange': D_XRANGE,
'yRange': D_YRANGE}
self.keywords = {'x_range': D_XRANGE,
'y_range': D_YRANGE}
return(True)
......
# IMPORT ---------------------------------------------------------------
from myplotlib import MyFig
from axTest import AxTest
from myplotlib import MplFig
from axes_tests import AxTest
class FigTest(MyFig):
class FigTest(MplFig):
FIGSIZE = (8., 6.)
......@@ -13,7 +13,7 @@ class FigTest(MyFig):
self.add_axes(AxTest(self, ratio, frame1), "p1")
class FigTest2(MyFig): # Fig with two Axes
class FigTest2(MplFig): # Fig with two Axes
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -35,7 +35,7 @@ class FigTest2(MyFig): # Fig wi
p1 = self.get_axes_by_name("p1")
p2 = self.get_axes_by_name("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
self.aliases = {'x_range_p1': (p1, "x_range"),
'x_range_p2': (p2, "x_range")}
return(True)
......@@ -35,31 +35,31 @@ from myplotlib import MplData
# READ STUPID DATA -----------------------------------------------------
def readStupidData(ipath=D_IPATH, *args, **kwargs):
def read_stupid_data(ipath=D_IPATH, *args, **kwargs):
debug = kwargs.get('debug', 0)
lrawdata = MplData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., 1, -1.]
l_rawdata = MplData()
l_rawdata.name = str(ipath)
l_rawdata.data = [-1., 1., 1, -1.]
if(debug):
print(DBUG + 'I read the raw data with readStupidData')
return(lrawdata)
return(l_rawdata)
# READ STUPID DATA 2 ---------------------------------------------------
def readStupidData2(ipath=D_IPATH, *args, **kwargs):
def read_stupid_data_2(ipath=D_IPATH, *args, **kwargs):
debug = kwargs.get('debug', 0)
lrawdata = MplData()
lrawdata.name = str(ipath)
lrawdata.data = [-1., 1., -2., 2.]
l_rawdata = MplData()
l_rawdata.name = str(ipath)
l_rawdata.data = [-1., 1., -2., 2.]
if(debug):
print(DBUG + 'I read the raw data with readStupidData2')
return(lrawdata)
return(l_rawdata)
......@@ -5,17 +5,17 @@ sys.path.append('../')
import clientside.myplotlib as mpl_client
from clientside.figTest import FigTest
from clientside.figTest import FigTest2
from clientside.figures_tests import FigTest
from clientside.figures_tests import FigTest2
class ClientTestCase(unittest.TestCase):
def setUp(self):
self.client = mpl_client.MplClient2()
self.client = mpl_client.MplClient()
def test_ServerSetup(self):
self.assertIsInstance(self.client,mpl_client.MplClient2)
def test_client_setup(self):
self.assertIsInstance(self.client, mpl_client.MplClient)
def tearDown(self) :
del self.client
......
......@@ -3,16 +3,16 @@ import unittest
import sys
sys.path.append('../')
from serverside.myIOs import readStupidData
from serverside.myIOs import readStupidData2
from serverside.figTest import FigTest as FigTests
from clientside.figTest import FigTest as FigTestc
from serverside.ios_tests import read_stupid_data
from serverside.ios_tests import read_stupid_data_2
from serverside.figures_tests import FigTest as FigTests
from clientside.figures_tests import FigTest as FigTestc
# This is for the double figure
from serverside.figTest import FigTest2 as FigTests2
from clientside.figTest import FigTest2 as FigTestc2
from serverside.figures_tests import FigTest2 as FigTests2
from clientside.figures_tests import FigTest2 as FigTestc2
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData,'readStupidData2': readStupidData2}
SERVER_IOFUNCTIONS = {'read_stupid_data': read_stupid_data,'read_stupid_data_2': read_stupid_data_2}
SERVER_FIGURES = {'FigTest': FigTests,'FigTest2': FigTests2}
import serverside.myplotlib as mpl_server
......@@ -23,8 +23,8 @@ class ComSetupTestCase(unittest.TestCase):
def setUp(self):
# The setup of server and client is tested in their individual testsuits - so it is assumed to work here
self.server = mpl_server.MplServer2(port=12345, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.client = mpl_client.MplClient2()
self.server = mpl_server.MplServer(port=12345, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.client = mpl_client.MplClient()
self.server.run(as_daemon=True)
......@@ -49,8 +49,8 @@ class ComSetupTestCase(unittest.TestCase):
class RemoteFigTestCase(unittest.TestCase):
def setUp(self):
self.server = mpl_server.MplServer2(port=12347, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.client = mpl_client.MplClient2()
self.server = mpl_server.MplServer(port=12347, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.client = mpl_client.MplClient()
self.client.host = 'localhost'
self.client.port = 12345
......@@ -58,55 +58,58 @@ class RemoteFigTestCase(unittest.TestCase):
self.server.run(as_daemon=True)
self.client.connect(('localhost',12347))
self.datanames = ['data1','data2']
self.client.read_data('readStupidData', self.datanames[0])
self.client.read_data('readStupidData2', self.datanames[1])
self.data_names = ['data1','data2']
self.client.read_data('read_stupid_data', self.data_names[0])
self.client.read_data('read_stupid_data_2', self.data_names[1])
def test_read_data(self):
""" Check wether the reading of remote data results in the server creating the datasets """
rm_data = self.client.list_remote_data()
self.assertEqual(rm_data,self.datanames)
self.assertEqual(rm_data,self.data_names)
def test_new_sync_fig(self):
''' Create a frist synced figure. Test if formating it will result in clinetside.fig.ax.data holding the expected data.'''
fig1 = self.client.new_sync_figure(FigTestc, ('data1',))
self.assertIsInstance(fig1,FigTestc)
self.assertIsInstance(fig1, FigTestc)
fig1.format_rawdata()
print('>>>>>>>>> ' + str(fig1.axes[0].data))
self.assertEqual(fig1.get_axes_by_name('p1').data,
{'xdata': [-1, 1],'ydata': [1, -1]})
{'xdata': [-1, 1], 'ydata': [1, -1]})
def test_multi_fig(self):
""" test if a figure with two axes is created correctly and if the alias set the axis keywords correct during creation """
fig2 = self.client.newSyncFigure(FigTestc2, ('data1','data2'), xRange_p1=[-2.0, 2.0], xRange_p2=[-3, 3], yRange=[-2.0, 2.0])
self.assertIsInstance(fig2,FigTestc2)
self.assertEqual(len(fig2.get_axes()),2)
fig2 = self.client.new_sync_figure(FigTestc2, ('data1', 'data2'), x_range_p1=[-2.0, 2.0], x_range_p2=[-3, 3], y_range=[-2.0, 2.0])
self.assertEqual(self.server.getFigByID(str(fig2.syncID)).getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(self.server.getFigByID(str(fig2.syncID)).getAxesByName('p1').keywords['yRange'],[-2, 2])
self.assertEqual(self.server.getFigByID(str(fig2.syncID)).getAxesByName('p2').keywords['xRange'],[-3, 3])
self.assertEqual(self.server.getFigByID(str(fig2.syncID)).getAxesByName('p2').keywords['yRange'],[-2, 2])
self.assertIsInstance(fig2, FigTestc2)
self.assertEqual(len(fig2.get_axes()), 2)
self.assertEqual(self.server.get_fig_by_id(str(fig2.sync_id)).get_axes_by_name('p1').keywords['x_range'], [-2, 2])
self.assertEqual(self.server.get_fig_by_id(str(fig2.sync_id)).get_axes_by_name('p1').keywords['y_range'], [-2, 2])
self.assertEqual(self.server.get_fig_by_id(str(fig2.sync_id)).get_axes_by_name('p2').keywords['x_range'], [-3, 3])
self.assertEqual(self.server.get_fig_by_id(str(fig2.sync_id)).get_axes_by_name('p2').keywords['y_range'], [-2, 2])
# compare client and server side keywords
self.assertEqual(fig2.getAxesByName('p1').keywords,self.server.getFigByID(str(fig2.syncID)).getAxesByName('p1').keywords)
self.assertEqual(fig2.getAxesByName('p2').keywords,self.server.getFigByID(str(fig2.syncID)).getAxesByName('p2').keywords)
self.assertEqual(fig2.get_axes_by_name('p1').keywords, self.server.get_fig_by_id(str(fig2.sync_id)).get_axes_by_name('p1').keywords)
self.assertEqual(fig2.get_axes_by_name('p2').keywords, self.server.get_fig_by_id(str(fig2.sync_id)).get_axes_by_name('p2').keywords)
def test_update(self):
""" test wether a serarate update call will set keywords correct"""
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
fig1 = self.client.new_sync_figure(FigTestc, ('data1',))
fig1.update(x_range=[-2, 2], y_range=[-2, 2])
self.assertEqual(self.server.getFigByID(str(fig1.syncID)).getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(self.server.getFigByID(str(fig1.syncID)).getAxesByName('p1').keywords['yRange'],[-2, 2])
self.assertEqual(self.server.get_fig_by_id(str(fig1.sync_id)).get_axes_by_name('p1').keywords['x_range'], [-2, 2])
self.assertEqual(self.server.get_fig_by_id(str(fig1.sync_id)).get_axes_by_name('p1').keywords['y_range'], [-2, 2])
# compare client and server side keywords
self.assertEqual(fig1.getAxesByName('p1').keywords,self.server.getFigByID(str(fig1.syncID)).getAxesByName('p1').keywords)
self.assertEqual(fig1.get_axes_by_name('p1').keywords,self.server.get_fig_by_id(str(fig1.sync_id)).get_axes_by_name('p1').keywords)
#~ def test_re_sync(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~ fig1.deSyncFig()
#~ fig1.reSyncFig()
def test_re_sync(self):
fig1 = self.client.new_sync_figure(FigTestc, ('data1',))
fig1.de_sync_fig()
fig1.re_sync_fig()
def tearDown(self) :
self.client.disconnect()
......
......@@ -4,22 +4,22 @@ import sys
sys.path.append('../')
import serverside.myplotlib as mpl_server
from serverside.myIOs import readStupidData
from serverside.myIOs import readStupidData2
from serverside.figTest import FigTest
from serverside.figTest import FigTest2
from serverside.ios_tests import read_stupid_data
from serverside.ios_tests import read_stupid_data_2
from serverside.figures_tests import FigTest
from serverside.figures_tests import FigTest2
class ServerTestCase(unittest.TestCase):
def setUp(self):
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData,'readStupidData2': readStupidData2}
SERVER_IOFUNCTIONS = {'read_stupid_data': read_stupid_data,'read_stupid_data_2': read_stupid_data_2}
SERVER_FIGURES = {'FigTest': FigTest,'FigTest2': FigTest2}
self.server = mpl_server.MplServer2(port=12345, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.server = mpl_server.MplServer(port=12345, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
def test_ServerSetup(self):
self.assertIsInstance(self.server,mpl_server.MplServer2)
def test_server_setup(self):
self.assertIsInstance(self.server, mpl_server.MplServer)
def tearDown(self) :
del self.server
......
......@@ -9,21 +9,21 @@ from clientside.myplotlib.signal import Signal, Query, Status, Answer
class SignalTestCase(unittest.TestCase):
def setUp(self):
self.signalbase = Signal('some type')
self.signal_base = Signal('some type')
def test_signal(self) :
self.assertEqual(self.signalbase.content,'some type','basic assignment of Signal class content failed')
self.assertEqual(self.signal_base.content, 'some type', 'basic assignment of Signal class content failed')
def tearDown(self):
del self.signalbase
del self.signal_base
class QueryTestCase(unittest.TestCase):
def test_readdataQuery(self):
def test_readdata_query(self):
rdQuery = Query(1,{1 : 'some', 2: 'content'})
self.assertIsInstance(rdQuery,Query)
self.assertEqual(rdQuery.content,{1 : 'some', 2: 'content'})
rd_query = Query(1, {'1': 'some', '2': 'content'})
self.assertIsInstance(rd_query, Query)
self.assertEqual(rd_query.content, {'1': 'some', '2': 'content'})
# only dict is accepted as an input for readdata Query
with self.assertRaises(UserWarning):
......@@ -38,44 +38,44 @@ class QueryTestCase(unittest.TestCase):
#~ except Exception as e:
#~ self.assertEqual(type(e),UserWarning)
def test_newsyncfigureQuery(self):
def test_new_sync_figure_query(self):
nsfQuery = Query(2,{1 : 'some', 2: 'content'})
self.assertIsInstance(nsfQuery,Query)
self.assertEqual(nsfQuery.content,{1 : 'some', 2: 'content'})
nsf_query = Query(2, {'1' : 'some', '2': 'content'})
self.assertIsInstance(nsf_query, Query)
self.assertEqual(nsf_query.content, {'1' : 'some', '2': 'content'})
def test_otherQuery(self):
def test_other_query(self):
for index in range(3,Query.NBR_OF_QUERY_TYPES):
query = Query(index,"some type")
self.assertEqual(query.content,"some type")
for index in range(3, Query.NBR_OF_QUERY_TYPES):
query = Query(index, "some type")
self.assertEqual(query.content, "some type")
# same problem as above...
with self.assertRaises(UserWarning):
Query(Query.NBR_OF_QUERY_TYPES+1,"some type")
Query(Query.NBR_OF_QUERY_TYPES + 1, "some type")
class StatusTestCase(unittest.TestCase):
def test_status(self):
stat = Status(True,"some content")
self.assertEqual(stat.value,True)
stat = Status(True, "some content")
self.assertEqual(stat.value, True)
stat = Status(False,"some content")
self.assertEqual(stat.value,False)
stat = Status(False, "some content")
self.assertEqual(stat.value, False)
self.assertIsInstance(stat,Status)