Commit 8b12f30a authored by Philipp Gast's avatar Philipp Gast
Browse files

added networking test with may issues... server side is not geared to great...

added networking test with may issues... server side is not geared to great transparancy. G_RAWDATA and G_FIGURES are now server class variables.
parent e4b9caa7
Pipeline #476 passed with stage
in 4 minutes and 23 seconds
......@@ -16,9 +16,6 @@ from . import D_DEBUG
debug = D_DEBUG
G_RAWDATA = dict()
G_FIGURES = dict()
class MplHandler(SocketServer.StreamRequestHandler):
def servPrint(self,x) : # This should be replaced with a proper implementation (s.b.) ?
......@@ -47,16 +44,15 @@ class MplHandler(SocketServer.StreamRequestHandler):
# Try to execute the instructions
try:
G_RAWDATA[dataName] = fct(*args, **kwargs)
self.server.G_RAWDATA[dataName] = fct(*args, **kwargs)
if debug:
print(INFO+"SERVER: I read the data following instructions")
# print(str(G_RAWDATA[dataName].data)) # SHOULD BE SUPPRESS LATER
except:
if debug:
print(WARN+"SERVER: The instructions of readData could not be executed.")
print(SPCE+"SERVER: I tried: "+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
return Status(False,"The instructions of readData could not be executed. I tried: "+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
if dataName in G_RAWDATA :
if dataName in self.server.G_RAWDATA :
return Status(True,"SERVER: I read the data following instructions"+str(fct.__name__)+'('+str(args)+', '+str(kwargs)+')')
return False #should never get here
......@@ -69,7 +65,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
kwargs = content.get('kwargs')
datanames = content.get('dataName')
datas = [G_RAWDATA[name] for name in datanames]
datas = [self.server.G_RAWDATA[name] for name in datanames]
try:
# create the figure:
......@@ -84,16 +80,16 @@ class MplHandler(SocketServer.StreamRequestHandler):
return Status(False, "I could not create the requested Figure. I tried: "+str(FigClass.__name__)+'('+str(datas)+', '+str(kwargs)+')'+" Exception details where:"+str(e.message)+str(e.args))
# add the figure to the global index
G_FIGURES[fig.getFigID()] = fig
self.server.G_FIGURES[fig.getFigID()] = fig
if fig.getFigID() in G_FIGURES :
if fig.getFigID() in self.server.G_FIGURES :
return Answer(fig.getFigID())
def getFigByID(self,figID) :
""" Identify the figure by ID and return it. On error it will return a Status Signal"""
# Identify the figure
fig = G_FIGURES.get(figID,None)
fig = self.server.G_FIGURES.get(figID,None)
if fig is None :
if debug:
print(WARN+"The figure ID: "+figID+" does not exist.")
......@@ -145,26 +141,26 @@ class MplHandler(SocketServer.StreamRequestHandler):
def treatDeleteSyncFigure(self,figID) :
""" Deletes the figure with ID figID from G_FIGURES """
if figID in G_FIGURES :
del G_FIGURES[figID]
if figID in self.server.G_FIGURES :
del self.server.G_FIGURES[figID]
return Status(True,'Figure with ID '+str(figID)+' deleted from server.')
else :
return Status(False,'Figure with ID '+str(figID)+' not found on server side.')
def treatListData(self,content) :
""" list the keys (and possibly (later) the location) from G_RAWDATA """
return Answer(G_RAWDATA.keys())
return Answer(self.server.G_RAWDATA.keys())
def treatGetData(self,content) :
""" from G_FIGURES """
if content in G_RAWDATA:
return Answer(G_RAWDATA[content])
if content in self.server.G_RAWDATA:
return Answer(self.server.G_RAWDATA[content])
else :
return Status(False,'Dataname not found in index of the server side...')
def treatListFig(self,content) :
""" list the keys from G_FIGURES """
return Answer(G_FIGURES.keys())
return Answer(self.server.G_FIGURES.keys())
# Actually not used anymore. Keep for testing?
# def send(self,sig):
......@@ -264,7 +260,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
except Exception as e:
print("An unspecified error occured. ")
reply = Status(False,"An unspecified error occured." + e.message + e.args)
reply = Status(False,"An unspecified error occured." + e.message + str(e.args))
finally :
if reply :
......@@ -300,6 +296,9 @@ class MplServer2(SocketServer.TCPServer):
SocketServer.TCPServer.__init__(self, (ip, port), handler)
self.running = False
self.initialized = True
self.G_RAWDATA = dict()
self.G_FIGURES = dict()
def run(self, as_daemon=True):
self.server_thread = threading.Thread(target=self.serve_forever)
......
......@@ -75,18 +75,33 @@ class RemoteFigTestCase(unittest.TestCase):
self.assertIsInstance(fig2,FigTestc2)
self.assertEqual(len(fig2.get_axes()),2)
# Testing the Alias functionality
self.assertEqual(fig2.getAxesByName('p1').keywords['xRange'],[-2.0, 2.0])
self.assertEqual(fig2.getAxesByName('p2').keywords['xRange'],[-3, 3])
self.assertEqual(fig2.getAxesByName('p1').keywords['yRange'],[-2.0, 2.0])
self.assertEqual(fig2.getAxesByName('p2').keywords['yRange'],[-2.0, 2.0])
#~ self.assertEqual(fig2.getAxesByName('p1').keywords['xRange'],[-2.0, 2.0])
#~ self.assertEqual(fig2.getAxesByName('p2').keywords['xRange'],[-3, 3])
#~ self.assertEqual(fig2.getAxesByName('p1').keywords['yRange'],[-2.0, 2.0])
#~ self.assertEqual(fig2.getAxesByName('p2').keywords['yRange'],[-2.0, 2.0])
def test_Update(self):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
# client side:
self.assertEqual(fig1.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(fig1.getAxesByName('p1').keywords['yRange'],[-2, 2])
# server side:
sfig = self.server.G_FIGURES['2'] # Warning this line will fail if tests are modified . BAD!!!
self.assertEqual(sfig.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(sfig.getAxesByName('p1').keywords['yRange'],[-2, 2])
# Alternative :
for sfig in self.server.G_FIGURES.values() :
# only one fig should be here.???
self.assertEqual(sfig.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(sfig.getAxesByName('p1').keywords['yRange'],[-2, 2])
#~ def test_ReSync(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~ fig1.deSyncFig()
......
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