Commit e4b9caa7 authored by Philipp Gast's avatar Philipp Gast
Browse files

added query type listRemoteFig analogous to listRemoteData. Added...

added query type listRemoteFig analogous to listRemoteData. Added NBR_OF_QUERY_TYPES to Query class to better decouple testing and class. Enabled all test cases again. Added test for MultiFig (Fig with two axes) including updating functionality.
parent ae60a188
Pipeline #473 passed with stage
in 4 minutes and 31 seconds
......@@ -7,7 +7,9 @@ from . import DBUG,WARN,SPCE,SEVR,INFO
from . import MplUnpickler
from . import MyData
debug = True
from . import D_DEBUG
debug = D_DEBUG
class MplClient2():
......@@ -111,7 +113,26 @@ class MplClient2():
query = Query(Query.LISTDATA,None)
status = self.send(query)
if not status :
print('something went wrong with the sending of readData request...')
print('something went wrong with the sending of listRemoteData request...')
answer = self.waitForSignal()
self.disconnect()
if isinstance(answer,Answer) :
return answer.content
elif isinstance(answer,Status):
print(answer.content)
return None
def listRemoteFig(self):
""" The server retuns a list with the content of its G_FIGURES
"""
self.connect((self.host, self.port))
query = Query(Query.LISTFIG,None)
status = self.send(query)
if not status :
print('something went wrong with the sending of listRemoteFig request...')
answer = self.waitForSignal()
self.disconnect()
......@@ -158,7 +179,7 @@ class MplClient2():
print('something went wrong with the sending of newSincFigure request...')
answer = self.waitForSignal()
self.diconnect()
self.disconnect()
# try to create a figure of the same class on the client side
if isinstance(answer,Answer) :
......
......@@ -12,11 +12,13 @@ from . import MyFig
from . import DBUG,WARN,SPCE,SEVR,INFO
from . import MplUnpickler
from . import D_DEBUG
debug = D_DEBUG
G_RAWDATA = dict()
G_FIGURES = dict()
DEBUG = True
debug = True
class MplHandler(SocketServer.StreamRequestHandler):
def servPrint(self,x) : # This should be replaced with a proper implementation (s.b.) ?
......@@ -46,11 +48,11 @@ class MplHandler(SocketServer.StreamRequestHandler):
# Try to execute the instructions
try:
G_RAWDATA[dataName] = fct(*args, **kwargs)
if (DEBUG):
if debug:
print(INFO+"SERVER: I read the data following instructions")
# print(str(G_RAWDATA[dataName].data)) # SHOULD BE SUPPRESS LATER
except:
if(DEBUG):
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)+')')
......@@ -72,10 +74,10 @@ class MplHandler(SocketServer.StreamRequestHandler):
try:
# create the figure:
fig = FigClass(datas, **kwargs)
if (DEBUG):
if debug:
print(INFO+"SERVER: I created the requested Figure")
except Exception as e:
if (DEBUG):
if debug:
print(WARN+"SERVER: I could not create the requested Figure.")
print(SPCE+"SERVER: I tried: "+str(FigClass.__name__)+'('+str(datas)+', '+str(kwargs)+')')
print(SPCE+"SERVER: Exception details where:",e.message, e.args )
......@@ -93,11 +95,11 @@ class MplHandler(SocketServer.StreamRequestHandler):
# Identify the figure
fig = G_FIGURES.get(figID,None)
if fig is None :
if DEBUG:
if debug:
print(WARN+"The figure ID: "+figID+" does not exist.")
return Status(False,"The figure ID: "+figID+" does not exist.")
elif isinstance(fig,MyFig) :
if DEBUG :
if debug :
print('Figure ',figID,' found in database')
return fig
......@@ -131,7 +133,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
try:
fig.formatRawData()
except Exception as e:
if DEBUG:
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)
......@@ -150,7 +152,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
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 """
""" list the keys (and possibly (later) the location) from G_RAWDATA """
return Answer(G_RAWDATA.keys())
def treatGetData(self,content) :
......@@ -160,6 +162,10 @@ class MplHandler(SocketServer.StreamRequestHandler):
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())
# Actually not used anymore. Keep for testing?
# def send(self,sig):
# # pickel the signal
......@@ -170,7 +176,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
# try :
# pickle.dump(sig,wf)
# except Exception as e:
# if DEBUG:
# if debug:
# print(SPCE+"SERVER: Exception details where:",e.message, e.args )
# return False
# wf.close()
......@@ -185,7 +191,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
# try :
# unpickler = MplUnpickler(rf)
# response = unpickler.load()
# if DEBUG and isinstance(response,Signal):
# if debug and isinstance(response,Signal):
# print('CLIENT Received: {} with content \"{}\"'.format(type(response),response.content))
# except EOFError :
# print('no answer received - or connection closed unexpectedly')
......@@ -204,7 +210,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
reply = None
if DEBUG:
if debug:
print('SERVER: ' + str(self.wfile._sock.getsockname()))
print('CLIENT: ' + str(self.wfile._sock.getpeername()))
......@@ -227,6 +233,8 @@ class MplHandler(SocketServer.StreamRequestHandler):
reply = self.treatListData(request.content)
elif request.queryType == request.GETDATA :
reply = self.treatGetData(request.content)
elif request.queryType == request.LISTFIG :
reply = self.treatListData(request.content)
else :
self.servPrint('received unknown query type')
reply = Status(False,"received unknown query type")
......@@ -248,7 +256,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
reply = Status(False,"received something totally diffenent")
if isinstance(reply,Signal) :
if DEBUG:
if debug:
self.servPrint("returning {}-Signal:".format(type(reply)))
except EOFError:
......@@ -262,6 +270,7 @@ class MplHandler(SocketServer.StreamRequestHandler):
if reply :
pickle.dump(reply,self.wfile)
# these two lines are not needed
self.wfile.close()
self.rfile.close()
......
......@@ -12,9 +12,12 @@ class Query(Signal) :
DELETESYNCFIGURE = 5
LISTDATA = 6
GETDATA = 7
LISTFIG = 8
NBR_OF_QUERY_TYPES = 8
def __init__(self,queryType, content) :
if queryType in range(1,8) :
if queryType in range(1,Query.NBR_OF_QUERY_TYPES+1) :
self.queryType = queryType
if queryType == Query.READDATA :
if type(content) == dict :
......@@ -44,6 +47,9 @@ class Query(Signal) :
elif queryType == Query.GETDATA :
self.content = content
elif queryType == Query.LISTFIG :
self.content = content
else :
print('unknown query type!')
raise UserWarning
......
......@@ -5,28 +5,28 @@ failed = []
states = {}
# Signal
#suite_signal = unittest.TestLoader().loadTestsFromTestCase(SignalTestCase)
#states.update({'Signal': unittest.TextTestRunner(verbosity=verbose).run(suite_signal).wasSuccessful()})
suite_signal = unittest.TestLoader().loadTestsFromTestCase(SignalTestCase)
states.update({'Signal': unittest.TextTestRunner(verbosity=verbose).run(suite_signal).wasSuccessful()})
# Query
#suite_query = unittest.TestLoader().loadTestsFromTestCase(QueryTestCase)
#states.update({'Query': unittest.TextTestRunner(verbosity=verbose).run(suite_query).wasSuccessful()})
suite_query = unittest.TestLoader().loadTestsFromTestCase(QueryTestCase)
states.update({'Query': unittest.TextTestRunner(verbosity=verbose).run(suite_query).wasSuccessful()})
# Answer
#suite_answer = unittest.TestLoader().loadTestsFromTestCase(AnswerTestCase)
#states.update({'Answer': unittest.TextTestRunner(verbosity=verbose).run(suite_answer).wasSuccessful()})
suite_answer = unittest.TestLoader().loadTestsFromTestCase(AnswerTestCase)
states.update({'Answer': unittest.TextTestRunner(verbosity=verbose).run(suite_answer).wasSuccessful()})
# Status
#suite_status = unittest.TestLoader().loadTestsFromTestCase(StatusTestCase)
#states.update({'Status': unittest.TextTestRunner(verbosity=verbose).run(suite_status).wasSuccessful()})
suite_status = unittest.TestLoader().loadTestsFromTestCase(StatusTestCase)
states.update({'Status': unittest.TextTestRunner(verbosity=verbose).run(suite_status).wasSuccessful()})
# Server
#suite_server = unittest.TestLoader().loadTestsFromTestCase(ServerTestCase)
#states.update({'Server': unittest.TextTestRunner(verbosity=verbose).run(suite_server).wasSuccessful()})
suite_server = unittest.TestLoader().loadTestsFromTestCase(ServerTestCase)
states.update({'Server': unittest.TextTestRunner(verbosity=verbose).run(suite_server).wasSuccessful()})
# Client
#suite_client = unittest.TestLoader().loadTestsFromTestCase(ClientTestCase)
#states.update({'Client': unittest.TextTestRunner(verbosity=verbose).run(suite_client).wasSuccessful()})
suite_client = unittest.TestLoader().loadTestsFromTestCase(ClientTestCase)
states.update({'Client': unittest.TextTestRunner(verbosity=verbose).run(suite_client).wasSuccessful()})
# Connection Setup
suite_com = unittest.TestLoader().loadTestsFromTestCase(ComSetupTestCase)
......
......@@ -65,17 +65,30 @@ class RemoteFigTestCase(unittest.TestCase):
rm_data = self.client.listRemoteData()
self.assertEqual(rm_data,self.datanames)
#~ def test_NewSyncFig(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~
#~ def test_MultiFig(self):
#~ fig2 = self.client.newSyncFigure(FigTestc2, ('data1','data2'), xRange_p1=[-2.0, 2.0], xRange_p2=[-3, 3], yRange=[-2.0, 2.0])
#~
#~ def test_Update(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~ fig1.update(xRange=[-2, 2],yRange=[-2, 2])
#~
def test_NewSyncFig(self):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
self.assertIsInstance(fig1,FigTestc)
def test_MultiFig(self):
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)
# 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])
def test_Update(self):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
self.assertEqual(fig1.getAxesByName('p1').keywords['xRange'],[-2, 2])
self.assertEqual(fig1.getAxesByName('p1').keywords['yRange'],[-2, 2])
#~ def test_ReSync(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
#~ fig1.deSyncFig()
#~ fig1.reSyncFig()
......
......@@ -46,7 +46,7 @@ class QueryTestCase(unittest.TestCase):
def test_otherQuery(self):
for index in range(3,8) :
for index in range(3,Query.NBR_OF_QUERY_TYPES) :
query = Query(index,"some type")
self.assertEqual(query.content,"some type")
......
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