Commit 6af6f954 authored by Yori Fournier's avatar Yori Fournier
Browse files

add raise NotImplemetedError in the plotting and formatRawData functions of myAxes.py

This is meant to prevent the user from overseeing a typo in the functions names

Added infrastructure for testsuites for myAxes and myFig

myAxes Test suite started
myFig  Test suite not started
parent 116adef8
......@@ -67,8 +67,7 @@ class MyAxes(Axes):
# set a default name. Should be individualized by instance
self.name = 'default'
# COMPUTE RECT -------------------------------------------------------
def computeRect(self, ratio, frameRect, *args, **kwargs):
......@@ -98,7 +97,8 @@ class MyAxes(Axes):
# PLOTTING ---------------------------------------------------------
def plotting(self):
return(True)
raise(NotImplementedError, 'You should have overwrite the plotting function.')
return(False)
# UNPACKING --------------------------------------------------------
def unpackFormattedData(self, packedData):
......@@ -112,7 +112,8 @@ class MyAxes(Axes):
# FORMATTING -------------------------------------------------------
def formatRawData(self, rawdata):
return(True)
raise(NotImplementedError, 'You should have overwrite the formatRawData function.')
return(False)
# TESTING THE RAWDATA ----------------------------------------------
def testRawData(self, rawdata):
......@@ -120,7 +121,7 @@ class MyAxes(Axes):
# UPDATE -----------------------------------------------------------
def update(self, *args, **kwargs):
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!!)
if args: # catch matplotlib kwargs
kwargs = args[0]
......
......@@ -97,3 +97,31 @@ class AxTest(MyAxes):
if (yRange): self.set_ylim(yRange)
return(True)
class AxBroken(MyAxes):
def FormatRawdata(self, rawdata):
return(True)
def Plottting(self):
return(True)
class AxMinimumImplementation(MyAxes):
def formatRawData(self, rawdata):
return(True)
def plotting(self):
return(True)
class AxWithKeywords(MyAxes):
def declareKeywords(self):
self.keywords = {'xRange': [-1., 1.],
'yRange': [-1., 1.]}
def formatRawData(self, rawdata):
return(True)
def plotting(self):
return(True)
......@@ -12,3 +12,10 @@ class FigTest(MyFig):
frame1 = [0.1, 0.1, 0.8, 0.8] # part of the fig that is available
self.add_axes(AxTest(self, ratio, frame1), "p1")
class EmptyFig(MyFig):
FIGSIZE = (8., 6.)
def addAxes(self):
pass
import unittest
from .test_myaxes import TestMyAxes
from .test_myfig import TestMyFig
from __init__ import *
verbose = 0
failed = []
states = {}
# MyAxes
suite_myaxes = unittest.TestLoader().loadTestsFromTestCase(TestMyAxes)
states.update({'MyAxes': unittest.TextTestRunner(verbosity=verbose).run(suite_myaxes).wasSuccessful()})
# MyFig
suite_myfig = unittest.TestLoader().loadTestsFromTestCase(TestMyFig)
states.update({'MyFig': unittest.TextTestRunner(verbosity=verbose).run(suite_myfig).wasSuccessful()})
for success in states.items():
if not success[1]:
failed.append(success[0])
if len(failed):
raise(Exception('Failing tests suites: '+str(failed)))
#!/usr/bin/env python
import os, sys
import unittest
sys.path.append('../')
from myplotlib import MyAxes
from myIOs import readStupidData
from figTest import EmptyFig
from axTest import AxBroken, AxMinimumImplementation, AxWithKeywords, AxTest
class TestMyAxes(unittest.TestCase):
def setUp(self):
self.data1 = readStupidData('data1')
self.fig = EmptyFig(())
def test_constructor_axbroken(self):
'''Verify that a NotImplementedError is raised
when the user designed class does not implement
plotting or formatRawData (to prevent typos issues).
'''
ax = AxBroken(self.fig, 0.3, [0., 0., 1., 1.])
with self.assertRaises(NotImplementedError):
ax.plotting()
with self.assertRaises(NotImplementedError):
ax.formatRawData(())
def test_constructor_axminimum(self):
'''Verify the required assignments of the constructor.
'''
ax = AxMinimumImplementation(self.fig, 0.3, [0., 0., 1., 1.])
self.assertEquals(ax.fig, self.fig)
self.assertEquals(ax.keywords, {})
self.assertEquals(ax.name, 'default')
self.assertEquals(ax.get_position().bounds, (0., 0., 1., 1.))
def test_constructor_axwithkeywords(self):
'''Verify the keywords assignments of the constructor.
'''
ax1 = AxWithKeywords(self.fig, 0.3, [0., 0., 1., 1.])
self.assertEquals(ax1.keywords, {'xRange': [-1., 1.], 'yRange': [-1., 1.]})
ax2 = AxWithKeywords(self.fig, 0.3, [0., 0., 1., 1.], xRange=[1., 2.], yRange=[0., 1.])
self.assertEquals(ax2.keywords, {'xRange': [1., 2.], 'yRange': [0., 1.]})
def test_compute_rect_default(self):
'''Test the computeRect function without keywords.
'''
implemented=False
self.assertTrue(implemented)
def test_compute_rect_force_ratio_on_width(self):
'''Test the computeRect function with forceRatioOnWidth.
'''
implemented=False
self.assertTrue(implemented)
def test_compute_rect_force_ratio_on_height(self):
'''Test the computeRect function with forceRatioOnHeight.
'''
implemented=False
self.assertTrue(implemented)
def test_update_with_matplotlib_args(self):
'''Test the update function.
'''
implemented=False
self.assertTrue(implemented)
def test_update_with_kwargs(self):
'''Test the update function.
'''
implemented=False
self.assertTrue(implemented)
if __name__ == '__main__':
unittest.main()
#!/usr/bin/env python
import os, sys
import unittest
sys.path.append('../')
class TestMyFig(unittest.TestCase):
def setUp(self):
pass
def test_dummy(self):
'''
'''
implemented=False
self.assertTrue(implemented)
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