Commit 0443382a authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '74-tests-make-the-tests-for-the-client-server-interface' into 'dev'

Resolve "TESTS - Make the tests for the client/server interface"

See merge request !55
parents 407689b8 bffe3878
Pipeline #474 passed with stage
in 4 minutes and 26 seconds
......@@ -33,4 +33,5 @@ myplotlib_import_network_latex_tkagg:
- cd test/network
- ./setup_test_folder.sh -r latex-tkagg
- python test_com_nogl.py
- python -m tests
- ./clean_test_folder.sh
......@@ -20,14 +20,14 @@ class Query(Signal) :
if type(content) == dict :
self.content = content
else :
print('parameter 2 of Query constructor is exspected to be of type dict')
raise
print('parameter 2 of Query constructor is expected to be of type dict')
raise(UserWarning)
elif queryType == Query.NEWSYNCFIGURE :
if type(content) == dict : # same as
self.content = content
else :
print('parameter 2 of Query constructor is exspected to be of type dict')
raise
print('parameter 2 of Query constructor is expected to be of type dict')
raise(UserWarning)
elif queryType == Query.UPDATESYNCFIGURE :
self.content = content
......@@ -37,22 +37,30 @@ class Query(Signal) :
elif queryType == Query.DELETESYNCFIGURE :
self.content = content
elif queryType == Query.LISTDATA :
self.content = content
elif queryType == Query.GETDATA :
self.content = content
else :
print('unknown query type!')
raise
else :
print('unknown query type!')
raise UserWarning
class Status(Signal):
def __init__(self,value,error) :
if (value == True) or (value == False) :
self.value = value
else :
print('value parameter of a status signal can only be True or False!')
raise UserWarning
if (type(error) == str) :
self.content = error
else :
print('error parameter of a status signal can only be of type string!')
raise UserWarning
class Answer(Signal):
def __init__(self,value) :
self.content = value
pass
......@@ -35,7 +35,7 @@
# @section History
#
# v 0.0.0 - MyAxes class for the myplotlib module, consists
# of a constructor, a pltting function and
# of a constructor, a plotting function and
# formatRawData.
#
# ======================================================================
......
import unittest
from .test_signal import QueryTestCase
from .test_signal import AnswerTestCase
from .test_signal import StatusTestCase
from .test_signal import SignalTestCase
from __init__ import *
verbose = 0
failed = []
states = {}
# Signal
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()})
# Answer
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()})
for success in states.items():
if not success[1]:
failed.append(success[0])
if len(failed):
raise(Exception('Failing tests suites: '+str(failed)))
import unittest
import sys
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, []),{})
# a syntactically nicer option:
#~ try :
#~ 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,8) :
query = Query(index,"some type")
self.assertEqual(query.content,"some type")
# same problem as above...
with self.assertRaises(UserWarning) :
Query(9,"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")
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