Commit 55ba4e8a authored by Philipp Gast's avatar Philipp Gast
Browse files

try to make the tests work again. errors all around :-(

parent 31713b2f
Pipeline #487 failed with stage
in 5 minutes and 35 seconds
......@@ -81,7 +81,7 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
from matplotlib.pyplot import close as mpclose
from matplotlib.pyplot import fignum_exists, savefig
from matplotlib.axes import Axes
from matplotlib.figure import FigureType
from matplotlib.figure import Figure
from matplotlib import is_interactive
from matplotlib import use
......@@ -115,10 +115,10 @@ if D_HIERARCHY in ('CLIENT', 'client', 'LOCAL', 'local'):
if D_HIERARCHY in ('CLIENT', 'client'):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_client import MyAxes_client as MyAxes
from .myAxes_client import MyAxesClient as MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig_client import MyFig_client as MyFig
from .myFig_client import MyFigClient as MyFig
from .progressbar import ProgressBar
......@@ -127,10 +127,10 @@ if D_HIERARCHY in ('CLIENT', 'client'):
elif(D_HIERARCHY in ('SERVER', 'server')):
# MyAxes: Overlay on matplotlib.Axes class
from .myAxes_server import MyAxes_server as MyAxes
from .myAxes_server import MyAxesServer as MyAxes
# MyFig: Overlay on matplotlib.Figure class
from .myFig_server import MyFig_server as MyFig
from .myFig_server import MyFigServer as MyFig
# from .test import FigTestServer
# from .test import FigTest
......
......@@ -272,7 +272,7 @@ class MplClient2():
return False
# SYNC FIGURE FORMAT RAWDATA ---------------------------------------
def sync_fig_format_raw_data(self, sync_id):
def sync_fig_format_rawdata(self, sync_id):
''' Send a FORMAT_SYNC_FIGURE query to the server.
wait for the answer
if answer not empty then set data to answer's value.'''
......
......@@ -209,21 +209,21 @@ class MplHandler(SocketServer.StreamRequestHandler):
request = unpickler.load()
if isinstance(request, Query):
if request.queryType == request.READDATA:
if request.query_type == request.READDATA:
reply = self.treat_read_data(request.content)
elif request.queryType == request.NEWSYNCFIGURE:
elif request.query_type == request.NEWSYNCFIGURE:
reply = self.treat_new_sync_figure(request.content)
elif request.queryType == request.UPDATESYNCFIGURE:
elif request.query_type == request.UPDATESYNCFIGURE:
reply = self.treat_update_sync_figure(request.content)
elif request.queryType == request.SYNCFIGFORMATRAWDATA:
elif request.query_type == request.SYNCFIGFORMATRAWDATA:
reply = self.treat_sync_fig_format_rawData(request.content)
elif request.queryType == request.DELETESYNCFIGURE:
elif request.query_type == request.DELETESYNCFIGURE:
reply = self.treat_delete_sync_figure(request.content)
elif request.queryType == request.LISTDATA:
elif request.query_type == request.LISTDATA:
reply = self.treat_list_data(request.content)
elif request.queryType == request.GETDATA:
elif request.query_type == request.GETDATA:
reply = self.treat_get_data(request.content)
elif request.queryType == request.LISTFIG:
elif request.query_type == request.LISTFIG:
reply = self.treat_list_data(request.content)
else:
self.servPrint('received unknown query type')
......
......@@ -63,11 +63,11 @@ class MyAxesServer(object):
self.keywords = {}
# FORMATTING ---------------------------------------------------------
def format_raw_data(self, rawdata):
def format_rawdata(self, rawdata):
return(True)
# TESTING THE RAWDATA ------------------------------------------------
def test_raw_data(self, rawdata):
def test_rawdata(self, rawdata):
return(True)
# UPDATE -------------------------------------------------------------
......
......@@ -77,7 +77,7 @@ from . import Figure
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFig_client(Figure):
class MyFigClient(Figure):
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -87,7 +87,7 @@ class MyFig_client(Figure):
def __init__(self, rawdata, *args, **kwargs):
# for the update function
self._attributesToUpdateKeys = [
self._attributes_to_update_keys = [
'fignum', 'reformat', 'debug', 'formatted', 'aliases']
# initialise the attribute default values and remove them from kwargs
......@@ -113,7 +113,7 @@ class MyFig_client(Figure):
self._initialize(*args, **kwargs)
self.set_rawdata(rawdata)
def deSyncFig(self):
def de_sync_fig(self):
if self.client is not None:
if self.client.deleteSyncFigure(self.syncID):
print('The figure was successfully deleted on the server Side')
......@@ -124,7 +124,7 @@ class MyFig_client(Figure):
print(
'The client is not connected to a server yet. Please use the client to set up a sync conection.')
def getState(self):
def get_state(self):
""" this function collects the current state of in the figure by creating a dict that holds all keyword,value pairs (taking the aliases into account)
Warning: myplotlib allows in a transparent manner to modify the axes directly. Those changes can not be covert.
......@@ -143,13 +143,13 @@ class MyFig_client(Figure):
# collect all keywords of the axes and replace the keys with the
# aliases
axKeywords = ax.keywords.copy()
ax_keywords = ax.keywords.copy()
for mask in masks:
if mask in axKeywords:
axKeywords[masks[mask]] = axKeywords.pop(mask)
if mask in ax_keywords:
ax_keywords[masks[mask]] = ax_keywords.pop(mask)
# Test if kewords are already set by an other axes
for key in axKeywords.keys():
for key in ax_keywords.keys():
if key in state.keys():
print(
'Warning: The keyword \"',
......@@ -157,11 +157,11 @@ class MyFig_client(Figure):
'\" appears in multiple axes. The Defaults will be overwritten. Prevent this by using aliases')
# update the global keyword index
state.update(axKeywords)
state.update(ax_keywords)
return state
def reSyncFig(self):
def re_sync_fig(self):
if self.client is not None:
......@@ -197,7 +197,7 @@ class MyFig_client(Figure):
for keyword in kwargs.keys():
# if it is an attribute
if keyword in self._attributesToUpdateKeys:
if keyword in self._attributes_to_update_keys:
# update value
setattr(self, keyword, kwargs[keyword])
......@@ -209,7 +209,7 @@ class MyFig_client(Figure):
for keyword in kwargs.keys():
# ignore figure attributes
if keyword in self._attributesToUpdateKeys:
if keyword in self._attributes_to_update_keys:
pass
# Check if a key of kwargs has an alias for this axes
......@@ -252,11 +252,11 @@ class MyFig_client(Figure):
return(False)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
def declare_aliases(self):
pass
# ADD AXES ---------------------------------------------------------
def addAxes(self, *arg, **kwargs):
def add_axes(self, *arg, **kwargs):
pass
# This overwrites MPL add_axes. It gives a name to the axis added so that
......@@ -281,7 +281,7 @@ class MyFig_client(Figure):
return True
# GET AXES BY NAME -------------------------------------------------
def getAxesByName(self, name):
def get_axes_by_name(self, name):
for ax in self.get_axes():
if ax.name == name:
......@@ -306,7 +306,7 @@ class MyFig_client(Figure):
self.remote_rawdata = rawdata
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
def format_rawdata(self):
# HEre comes a function that send a signal to the server
# and tells him to execute the format rawdata of the
# synchronized figure (server-side)
......@@ -314,7 +314,7 @@ class MyFig_client(Figure):
# try:
if (True):
datas = self.client.syncFigFormatRawData(self.syncID)
datas = self.client.sync_fig_format_raw_data(self.syncID)
# except:
# print(SEVR+'The server-side figure could not format the data...')
# return(False)
......@@ -339,7 +339,7 @@ class MyFig_client(Figure):
print(DBUG + "currently formatting the data...")
if((self.reformat) or (not self.formatted)):
status = self.formatRawData()
status = self.format_raw_data()
if(not status):
return(False)
......@@ -353,8 +353,8 @@ class MyFig_client(Figure):
ax.cla()
# plot
plottingStatus = ax.plotting()
status = status and plottingStatus
plotting_status = ax.plotting()
status = status and plotting_status
return(status)
......@@ -365,9 +365,9 @@ class MyFig_client(Figure):
self.plot()
# DEBUG --------------------------------------------------------------
def printDebug(self):
className = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(className))
def print_debug(self):
class_name = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(class_name))
print(SPCE + " ID the figure: " + str(self.fignum))
print(SPCE + "Size of the figure: " + str(self.FIGSIZE) + ' [inch] \n')
......@@ -392,9 +392,9 @@ class MyFig_client(Figure):
# if the figure is boundedToWin
# save to canvas in a local variable and restore after saving to file.
if self.boundedToWin:
winCanvas = self.canvas
win_canvas = self.canvas
else:
winCanvas = None
win_canvas = None
canvas = FigureCanvas(self) # the canvas of the figure changed
......@@ -451,7 +451,7 @@ class MyFig_client(Figure):
return(False)
# restore the former canvas
if winCanvas is not None:
self.canvas = winCanvas
if win_canvas is not None:
self.canvas = win_canvas
return(True)
......@@ -76,7 +76,7 @@ from . import MyData
# Class MyFig Overwriting Matplotlib.figure.Figure
class MyFig_server(object):
class MyFigServer(object):
# Set the size of the Figure in inch
# (private variable can not be updated)
......@@ -172,11 +172,11 @@ class MyFig_server(object):
return str(self.fignum)
# DECLARE ALIASES -------------------------------------------------
def declareAliases(self):
def declare_aliases(self):
pass
# ADD AXES ---------------------------------------------------------
def addAxes(self, *arg, **kwargs):
def add_axes(self, *arg, **kwargs):
pass
# GET_AXES ---------------------------------------------------------
......@@ -205,7 +205,7 @@ class MyFig_server(object):
return True
# GET AXES BY NAME -------------------------------------------------
def getAxesByName(self, name):
def get_axes_by_name(self, name):
for ax in self.get_axes():
if ax.name == name:
......@@ -231,7 +231,7 @@ class MyFig_server(object):
if(self.debug):
print(DBUG + "set_rawdata: one item per axes")
self.rawdata = rawdata
status = self.formatRawData()
status = self.format_rawdata()
else:
self.rawdata = None
......@@ -248,7 +248,7 @@ class MyFig_server(object):
print(DBUG + "set_rawdata: one item for all axes")
# This is the trick rawdata becomes a generator (so smart)
self.rawdata = repeat(rawdata)
status = self.formatRawData()
status = self.format_rawdata()
else:
print(SEVR + "set_rawdata: I could not set the rawdata...")
......@@ -262,7 +262,7 @@ class MyFig_server(object):
return(status)
# FORMAT RAW DATA --------------------------------------------------
def formatRawData(self):
def format_rawdata(self):
if self.rawdata is not None:
......@@ -280,12 +280,12 @@ class MyFig_server(object):
rawdata.name)
status = ax.testRawData(rawdata)
if status:
status = ax.formatRawData(rawdata)
status = ax.format_rawdata(rawdata)
else:
status = ax.testRawData(rawdata)
if status:
try:
status = ax.formatRawData(rawdata)
status = ax.format_rawdata(rawdata)
except BaseException:
print(SEVR +
"The " +
......@@ -307,7 +307,7 @@ class MyFig_server(object):
return(False)
# DEBUG --------------------------------------------------------------
def printDebug(self):
def print_debug(self):
className = str(self.__class__.__name__)
print('\n' + DBUG + " {0} PARAMETERS: ".format(className))
print(SPCE + " Raw data: " + str(self.rawdata))
......
......@@ -60,7 +60,7 @@ class Query(Signal):
class Status(Signal):
def __init__(self, value, error):
if (value is True) or (value is True):
if (value == True) or (value == False):
self.value = value
else:
print('value parameter of a status signal'
......
......@@ -32,8 +32,8 @@ class FigTest2(MyFig): # Fig wi
# 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.getAxesByName("p1")
p2 = self.getAxesByName("p2")
p1 = self.get_axes_by_name("p1")
p2 = self.get_axes_by_name("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
......
......@@ -32,8 +32,8 @@ class FigTest2(MyFig): # Fig wi
# 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.getAxesByName("p1")
p2 = self.getAxesByName("p2")
p1 = self.get_axes_by_name("p1")
p2 = self.get_axes_by_name("p2")
self.aliases = {'xRange_p1': (p1, "xRange"),
'xRange_p2': (p2, "xRange")}
......
from time import sleep
from serverside.myIOs import readStupidData
from serverside.myIOs import readStupidData2
from serverside.figTest import FigTest as FigTests
from clientside.figTest import FigTest as FigTestc
# This is for the double figure
from serverside.figTest import FigTest2 as FigTests2
from clientside.figTest import FigTest2 as FigTestc2
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData,'readStupidData2': readStupidData2}
SERVER_FIGURES = {'FigTest': FigTests,'FigTest2': FigTests2}
import serverside.myplotlib as mpl_server
import clientside.myplotlib as mpl_client
server = mpl_server.MplServer2(port=12345, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
client = mpl_client.MplClient2()
server.run(as_daemon=True)
print("Server loop running in thread:", server.server_thread.name)
client.connect(('localhost', 12345))
print("Client is now connected")
client.readData('readStupidData', 'data1')
fig1 = client.newSyncFigure(FigTestc, ('data1',))
win=mpl_client.MyWin(fig1)
sleep(2)
# update test
fig1.update(xRange=[-2, 2],yRange=[-2, 2])
win.refresh()
sleep(2)
# multiple figures with multiple data
client.readData('readStupidData2', 'data2')
print("known datasets: ",client.listRemoteData())
fig2 = client.newSyncFigure(FigTestc2, ('data1','data2'), xRange_p1=[-2.0, 2.0], xRange_p2=[-3, 3], yRange=[-2.0, 2.0])
print('current state:::',fig2.getState())
win=mpl_client.MyWin(fig2)
sleep(2)
# desync resync test
fig1.deSyncFig()
fig1.reSyncFig()
......@@ -23,7 +23,7 @@ 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, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
self.server = mpl_server.MplServer2(port=12345, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.client = mpl_client.MplClient2()
self.server.run(as_daemon=True)
......@@ -48,7 +48,7 @@ class ComSetupTestCase(unittest.TestCase):
class RemoteFigTestCase(unittest.TestCase):
def setUp(self):
self.server = mpl_server.MplServer2(port=12347, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
self.server = mpl_server.MplServer2(port=12347, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
self.client = mpl_client.MplClient2()
self.client.host = 'localhost'
......@@ -58,34 +58,34 @@ class RemoteFigTestCase(unittest.TestCase):
self.client.connect(('localhost', 12347))
self.datanames = ['data1','data2']
self.client.readData('readStupidData', self.datanames[0])
self.client.readData('readStupidData2', self.datanames[1])
self.client.read_data('readStupidData', self.datanames[0])
self.client.read_data('readStupidData2', self.datanames[1])
def test_Readdata(self):
rm_data = self.client.listRemoteData()
rm_data = self.client.list_remote_data()
self.assertEqual(rm_data,self.datanames)
def test_NewSyncFig(self):
fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
fig1 = self.client.new_sync_figure(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])
fig2 = self.client.new_sync_figure(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])
self.assertEqual(fig2.get_axes_by_name('p1').keywords['xRange'],[-2.0, 2.0])
self.assertEqual(fig2.get_axes_by_name('p2').keywords['xRange'],[-3, 3])
self.assertEqual(fig2.get_axes_by_name('p1').keywords['yRange'],[-2.0, 2.0])
self.assertEqual(fig2.get_axes_by_name('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])
self.assertEqual(fig1.get_axes_by_name('p1').keywords['xRange'],[-2, 2])
self.assertEqual(fig1.get_axes_by_name('p1').keywords['yRange'],[-2, 2])
#~ def test_ReSync(self):
#~ fig1 = self.client.newSyncFigure(FigTestc, ('data1',))
......
......@@ -16,7 +16,7 @@ class ServerTestCase(unittest.TestCase):
SERVER_IOFUNCTIONS = {'readStupidData': readStupidData,'readStupidData2': readStupidData2}
SERVER_FIGURES = {'FigTest': FigTest,'FigTest2': FigTest2}
self.server = mpl_server.MplServer2(port=12345, knownFunctions=SERVER_IOFUNCTIONS, knownFigures=SERVER_FIGURES)
self.server = mpl_server.MplServer2(port=12345, known_functions=SERVER_IOFUNCTIONS, known_figures=SERVER_FIGURES)
def test_ServerSetup(self):
self.assertIsInstance(self.server,mpl_server.MplServer2)
......
......@@ -7,28 +7,28 @@ sys.path.append('../')
from clientside.myplotlib.signal import Signal, Query, Status, Answer
class SignalTestCase(unittest.TestCase):
def setUp(self):
self.signalbase = Signal('some type')
def test_signal(self) :
self.assertEqual(self.signalbase.content,'some type','basic assignment of Signal class content failed')
def tearDown(self):
del self.signalbase
class QueryTestCase(unittest.TestCase):
def test_readdataQuery(self):
rdQuery = Query(1,{1 : 'some', 2: 'content'})
self.assertIsInstance(rdQuery,Query)
self.assertEqual(rdQuery.content,{1 : 'some', 2: 'content'})
# only dict is accepted as an input for readdata Query
with self.assertRaises(UserWarning):
Query(1, [])
# not working as expected
#~ self.assertRaises(UserWarning,Query, (1, []),{})
......@@ -37,45 +37,45 @@ class QueryTestCase(unittest.TestCase):
#~ Query(1, [])
#~ except Exception as e:
#~ self.assertEqual(type(e),UserWarning)
def test_newsyncfigureQuery(self):
nsfQuery = Query(2,{1 : 'some', 2: 'content'})
self.assertIsInstance(nsfQuery,Query)
self.assertEqual(nsfQuery.content,{1 : 'some', 2: 'content'})
def test_otherQuery(self):
for index in range(3,Query.NBR_OF_QUERY_TYPES) :
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(9,"some type")
with self.assertRaises(UserWarning):
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(False,"some content")
self.assertEqual(stat.value,False)
self.assertIsInstance(stat,Status)
with self.assertRaises(UserWarning):
Status( 9,"some content")
Status( None,"some content")
class AnswerTestCase(unittest.TestCase):
def test_answer(self):
answ = Answer('some content')
self.assertIsInstance(answ,Answer)
self.assertEqual(answ.content,'some content')
if __name__ == '__main__':
unittest.main()
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