Commit 243f0f4b authored by Yori Fournier's avatar Yori Fournier
Browse files

removed MplData and corrected tests. Should pass.

parent 0acfa465
Pipeline #658 failed with stage
in 8 minutes and 5 seconds
......@@ -20,7 +20,6 @@ D_FIGNUM = 0 # default figure number
D_FIGSIZE = (8., 6.) # default figure size
D_REFORMAT = True # default reformat value
D_FORMATTED = False # default formatted value
D_RAWDATA = MplData() # default raw data
D_INPUTARG = 'current' # default Input argument
# myIOs
......
before_script:
- apt-get update -q -y
- apt-get install python-dev python-tk -q -y
- apt-get install python3 python3-dev python3-tk -q -y
- wget https://bootstrap.pypa.io/get-pip.py
- python get-pip.py
- python -m pip --version
......
......@@ -227,13 +227,13 @@ class MplAxes(metaclass=AxesClassFactory, context=CONTEXT.lower()):
# PLOTTING ---------------------------------------------------------
def plotting(self):
raise(NotImplementedError, 'You should have overwrite the'
raise NotImplementedError('You should have overwrite the'
' plotting function.')
return(False)
# FORMATTING -------------------------------------------------------
def format_rawdata(self, rawdata):
raise(NotImplementedError, 'You should have overwritten the '
raise NotImplementedError('You should have overwritten the '
'format_rawdata method.')
return(False)
......@@ -241,12 +241,12 @@ class MplAxes(metaclass=AxesClassFactory, context=CONTEXT.lower()):
# PARENT CONSTRUCTOR -----------------------------------------------
def parent_constructor(self, fig, rect, **kwargs):
raise(NotImplementedError, 'You should have overwritten the '
raise NotImplementedError('You should have overwritten the '
'parent_constructor method.')
# UPDATE -----------------------------------------------------------
def update(self, *args, **kwargs):
raise(NotImplementedError, 'You should have overwritten the '
raise NotImplementedError('You should have overwritten the '
'update method.')
# --- LOCAL/CLIENT CONTEXT METHODS ---------------------------------
......
......@@ -578,11 +578,13 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
After the rawdata is successfully set, it will be formatted.
"""
#from collections import Iterable
self.formatted = False
status = False
# DEFAULT: one item per axes in figure
if isinstance(rawdata, list):
if isinstance(rawdata, tuple):
if len(rawdata) == len(self.get_axes()):
if(self.debug):
......@@ -606,6 +608,7 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
".format(sevr=SEVR))
self.rawdata = None
status = False
raise TypeError('rawdata must be an tuple of the length of the number of axes.')
if not status:
print("{sevr} set_rawdata: I could not set the rawdata...\
......@@ -991,13 +994,13 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
status = False
# DEFAULT: one item per axes in figure
if isinstance(rawdata, list):
if isinstance(rawdata, tuple):
if len(rawdata) == len(self.get_axes()):
if(self.debug):
print("{dbug} set_rawdata: one item per axes\
".format(dbug=DBUG))
self.rawdata = [self.server._rawdata[name] for name in rawdata]
self.rawdata = [self.server._rawdata[name] for name in rawdata]
status = self.format_rawdata()
else:
......@@ -1015,6 +1018,7 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
".format(sevr=SEVR))
self.rawdata = None
status = False
raise TypeError('rawdata must be an tuple of the length of the number of axes.')
if not status:
print("{sevr} set_rawdata: I could not set the rawdata...\
......@@ -1022,7 +1026,7 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
self.rawdata = None
return(status)
_format_rawdata_server = _format_rawdata_local
def _get_fig_id_server(self):
......
......@@ -190,7 +190,7 @@ class MplHandler(socketserver.StreamRequestHandler):
def treat_list_data(self, content):
""" list the keys
(and possibly (later)the location) from _rawdata """
return Answer(self.server._rawdata.keys())
return Answer(list(self.server._rawdata.keys()))
def treat_get_data(self, content):
""" from _figures """
......
......@@ -22,14 +22,14 @@ class FormatterListToLine(Formatter):
def shape(self, rawdata):
ydata = rawdata.data
xdata = range(0, len(ydata))
ydata = rawdata
xdata = list(range(0, len(ydata)))
data = {'ydatas': [ydata],
'xdata': xdata,
'xlabel': self.xlabel,
'ylabel': self.ylabel,
'name': rawdata.name}
}
return(data)
......@@ -46,17 +46,17 @@ class FormatterArrayToLines(Formatter):
def shape(self, rawdata):
if self.xdata_index is not None:
ydatas = rawdata.data[:]
ydatas = rawdata[:]
xdata = ydatas.pop(self.xdata_index)
else:
ydatas = rawdata.data
xdata = range(0, len(ydatas[0])) # generic xdata
ydatas = rawdata
xdata = list(range(0, len(ydatas[0]))) # generic xdata
data = {'ydatas': ydatas,
'xdata': xdata,
'xlabel': self.xlabel,
'ylabel': self.ylabel,
'name': rawdata.name}
}
return(data)
......@@ -74,16 +74,16 @@ class FormatterAppendToLines(Formatter):
xdata = []
if self.with_label:
labels = rawdata.data[0]
labels = rawdata[0]
i_index = 1
else:
i_index = 0
labels = []
for item in rawdata.data[i_index]:
for item in rawdata[i_index]:
ydatas.append([item])
for line in rawdata.data[i_index+1:]:
for line in rawdata[i_index+1:]:
for i in range(0, len(line)):
ydatas[i].append(line[i])
......@@ -98,14 +98,14 @@ class FormatterAppendToLines(Formatter):
else:
labels = repeat(None)
else:
xdata = range(0, len(ydatas[0])) # generic xdata
xdata = list(range(0, len(ydatas[0]))) # generic xdata
data = {'ydatas': ydatas,
'xdata': xdata,
'xlabel': self.xlabel,
'ylabel': self.ylabel,
'labels': labels,
'name': rawdata.name}
}
return(data)
......
import unittest
from test_formatter import FormatterListToLineTestCase
from test_formatter import FormatterArrayToLinesTestCase
from test_formatter import FormatterAppendToLinesTestCase
from .test_formatter import FormatterListToLineTestCase
from .test_formatter import FormatterArrayToLinesTestCase
from .test_formatter import FormatterAppendToLinesTestCase
from test_weighted_grid import WeightedGridTestCase
from .test_weighted_grid import WeightedGridTestCase
from __init__ import *
from .__init__ import *
verbose = 0
failed = []
......
......@@ -5,14 +5,13 @@ import unittest
sys.path.append('../../')
from myplotlib import MplData
from myplotlib.mpl_toolbox import FormatterListToLine, FormatterArrayToLines, FormatterAppendToLines
class FormatterListToLineTestCase(unittest.TestCase):
def setUp(self):
self.data_line = MplData(data=[0., 1., 2., 3., 4., 5.,],
name='data_line')
self.data_line = [0., 1., 2., 3., 4., 5.,]
def test_formatter_list_to_line(self):
formatter = FormatterListToLine()
......@@ -25,7 +24,7 @@ class FormatterListToLineTestCase(unittest.TestCase):
'xdata': [0., 1., 2., 3., 4., 5.,],
'xlabel': None,
'ylabel': None,
'name': 'data_line'}
}
self.assertEqual(data, correct_data)
......@@ -40,17 +39,17 @@ class FormatterListToLineTestCase(unittest.TestCase):
'xdata': [0., 1., 2., 3., 4., 5.],
'xlabel': r'x-axis',
'ylabel': r'y-axis',
'name': 'data_line'}
}
self.assertEqual(data, correct_data)
class FormatterArrayToLinesTestCase(unittest.TestCase):
def setUp(self):
self.data_lines = MplData(data=[[0., 1., 2., 3., 4., 5.],
[0., 2., 4., 6., 8., 10.],
[0., 3., 6., 9., 12., 15.]],
name='data_lines')
self.data_lines = [[0., 1., 2., 3., 4., 5.],
[0., 2., 4., 6., 8., 10.],
[0., 3., 6., 9., 12., 15.]]
def test_formatter_array_to_lines(self):
formatter = FormatterArrayToLines()
......@@ -66,7 +65,7 @@ class FormatterArrayToLinesTestCase(unittest.TestCase):
'xdata': [0., 1., 2., 3., 4., 5.],
'xlabel': None,
'ylabel': None,
'name': 'data_lines'}
}
self.assertEqual(data, correct_data)
......@@ -83,29 +82,29 @@ class FormatterArrayToLinesTestCase(unittest.TestCase):
'xdata': [0., 2., 4., 6., 8., 10.],
'xlabel': r'x-axis',
'ylabel': r'y-axis',
'name': 'data_lines'}
}
self.assertEqual(data, correct_data)
class FormatterAppendToLinesTestCase(unittest.TestCase):
def setUp(self):
self.data_cols = MplData(data=[[0., 0., 0.],
[1., 2., 3.],
[2., 4., 6.],
[3., 6., 9.],
[4., 8., 12.],
[5., 10., 15.]],
name='data_cols')
self.data_labeled_cols = MplData(data=[['y0', 'y1', 'y2'],
[0., 0., 0.],
[1., 2., 3.],
[2., 4., 6.],
[3., 6., 9.],
[4., 8., 12.],
[5., 10., 15.]],
name='data_labeled_cols')
self.data_cols = [[0., 0., 0.],
[1., 2., 3.],
[2., 4., 6.],
[3., 6., 9.],
[4., 8., 12.],
[5., 10., 15.]]
self.data_labeled_cols = [['y0', 'y1', 'y2'],
[0., 0., 0.],
[1., 2., 3.],
[2., 4., 6.],
[3., 6., 9.],
[4., 8., 12.],
[5., 10., 15.]]
def test_formatter_append_to_lines(self):
formatter = FormatterAppendToLines()
......@@ -122,7 +121,7 @@ class FormatterAppendToLinesTestCase(unittest.TestCase):
'xlabel': None,
'ylabel': None,
'labels': [],
'name': 'data_cols'}
}
self.assertEqual(data, correct_data)
......@@ -141,7 +140,7 @@ class FormatterAppendToLinesTestCase(unittest.TestCase):
'xlabel': 'y0',
'ylabel': None,
'labels': ['y1', 'y2'],
'name': 'data_labeled_cols'}
}
self.assertEqual(data, correct_data)
......@@ -159,7 +158,7 @@ class FormatterAppendToLinesTestCase(unittest.TestCase):
'xlabel': r'x-axis',
'ylabel': r'y-axis',
'labels': ['y0', 'y2'],
'name': 'data_labeled_cols'}
}
self.assertEqual(data, correct_data)
......@@ -178,7 +177,7 @@ class FormatterAppendToLinesTestCase(unittest.TestCase):
'xlabel': r'x-axis',
'ylabel': r'y-axis',
'labels': ['y0', 'y1', 'y2'],
'name': 'data_labeled_cols'}
}
self.assertEqual(data, correct_data)
......
......@@ -5,13 +5,13 @@ import unittest
sys.path.append('../../')
from myplotlib import EmptyFig, MplData
from myplotlib import EmptyFig
from myplotlib.mpl_toolbox import WeightedGrid, Ax2dPlots
class WeightedGridTestCase(unittest.TestCase):
def setUp(self):
self.rawdata = MplData(data=[-1., 1.])
self.rawdata = [-1., 1.]
self.foo_fig = EmptyFig()
self.foo_grid = WeightedGrid()
self.foo_grid2 = WeightedGrid()
......@@ -97,7 +97,7 @@ class WeightedGridTestCase(unittest.TestCase):
class HorizontalWeightedGridTestCase(unittest.TestCase):
def setUp(self):
self.rawdata = MplData(data=[-1., 1.])
self.rawdata = [-1., 1.]
self.foo_fig = EmptyFig()
self.foo_grid = HorizontalWeightedGrid()
self.foo_axes = Ax2dPlots(self.foo_fig)
......@@ -115,7 +115,7 @@ class HorizontalWeightedGridTestCase(unittest.TestCase):
class VerticalWeightedGridTestCase(unittest.TestCase):
def setUp(self):
self.rawdata = MplData(data=[-1., 1.])
self.rawdata = [-1., 1.]
self.foo_fig = EmptyFig()
self.foo_grid = VerticalWeightedGrid()
self.foo_axes = Ax2dPlots(self.foo_fig)
......
import unittest
from test_tutorials import TutorialsTestCase
from .test_tutorials import TutorialsTestCase
from __init__ import *
from .__init__ import *
verbose = 0
failed = []
......
......@@ -2,12 +2,12 @@
import unittest
from tuto000 import script as sc000
from tuto001 import script as sc001
from tuto002 import script as sc002
from tuto003 import script as sc003
from tuto004 import script as sc004
from tuto005 import script as sc005
from .tuto000 import script as sc000
from .tuto001 import script as sc001
from .tuto002 import script as sc002
from .tuto003 import script as sc003
from .tuto004 import script as sc004
from .tuto005 import script as sc005
class TutorialsTestCase(unittest.TestCase):
......
......@@ -7,11 +7,9 @@ def script(with_print=False):
sys.path.append('../../')
from myplotlib.mpl_toolbox import Ax2dPlots
from myplotlib import EmptyFig, MplData
from myplotlib import EmptyFig
data = [0.1, 0.2, 0.4, 0.6, 1., 0.9, 1.2, 1.3, 1.2]
rawdata = MplData(data=data, name='just-a-list')
rawdata = [0.1, 0.2, 0.4, 0.6, 1., 0.9, 1.2, 1.3, 1.2]
fig = EmptyFig()
fig.add_axes(Ax2dPlots(fig), 'ax1')
......
......@@ -7,15 +7,12 @@ def script(with_print=False):
sys.path.append('../../')
from myplotlib.mpl_toolbox import Ax2dPlots, FormatterArrayToLines
from myplotlib import EmptyFig, MplData, VerticalGrid
from myplotlib import EmptyFig, VerticalGrid
# rawdata set
data = [[0.1, 0.2, 0.4, 0.6, 1., 0.9, 1.2, 1.3, 1.2],
rawdata = [[0.1, 0.2, 0.4, 0.6, 1., 0.9, 1.2, 1.3, 1.2],
[0.1, 0.3, 1.0, 3.0, 10., 30., 100., 300., 1000.]]
# pack into MplData
rawdata = MplData(data=data, name='just-a-list')
# Create an empty figure
fig = EmptyFig()
......
......@@ -7,17 +7,14 @@ def script(with_print=False):
sys.path.append('../../')
from myplotlib.mpl_toolbox import Ax2dPlots, FormatterArrayToLines
from myplotlib import EmptyFig, MplData, VerticalGrid
from myplotlib import EmptyFig, VerticalGrid
# rawdata set
data = [[0.1, 0.2, 0.4, 0.6, 1., 0.9, 1.2, 1.3, 1.2],
rawdata = [[0.1, 0.2, 0.4, 0.6, 1., 0.9, 1.2, 1.3, 1.2],
[0.1, 0.22, 0.44, 0.65, 1.05, 0.96, 1.27, 1.34, 1.28],
[0.12, 0.21, 0.41, 0.59, 1.01, 0.88, 1.17, 1.31, 1.22],
[0.1, 0.3, 1.0, 3.0, 10., 30., 100., 300., 1000.]]
# pack into MplData
rawdata = MplData(data=data, name='just-a-list')
# Create an empty figure
fig = EmptyFig()
......
......@@ -7,21 +7,18 @@ def script(with_print=False):
sys.path.append('../../')
from myplotlib.mpl_toolbox import Ax2dPlots, FormatterAppendToLines
from myplotlib import EmptyFig, MplData, VerticalGrid
from myplotlib import EmptyFig, VerticalGrid
# rawdata set
data = [[0.1, 0.1, 0.12, 0.1],
[0.3, 0.2, 0.22, 0.21],
[1.0, 0.4, 0.44, 0.41],
[3.0, 0.6, 0.65, 0.59],
[10., 1.0, 1.05, 1.01],
[30., 0.9, 0.96, 0.88],
[100., 1.2, 1.27, 1.17],
[300., 1.3, 1.34, 1.31],
[1000., 1.2, 1.28, 1.22]]
# pack into MplData
rawdata = MplData(data=data, name='just-a-list')
rawdata = [[0.1, 0.1, 0.12, 0.1],
[0.3, 0.2, 0.22, 0.21],
[1.0, 0.4, 0.44, 0.41],
[3.0, 0.6, 0.65, 0.59],
[10., 1.0, 1.05, 1.01],
[30., 0.9, 0.96, 0.88],
[100., 1.2, 1.27, 1.17],
[300., 1.3, 1.34, 1.31],
[1000., 1.2, 1.28, 1.22]]
# Create an empty figure
fig = EmptyFig()
......
......@@ -7,21 +7,18 @@ def script(with_print=False):
sys.path.append('../../')
from myplotlib.mpl_toolbox import Ax2dPlots, FormatterAppendToLines, VerticalWeightedGrid, HorizontalWeightedGrid
from myplotlib import EmptyFig, MplData
from myplotlib import EmptyFig
# rawdata set
data = [[0.1, 0.1, 0.12, 0.1],
[0.3, 0.2, 0.22, 0.21],
[1.0, 0.4, 0.44, 0.41],
[3.0, 0.6, 0.65, 0.59],
[10., 1.0, 1.05, 1.01],
[30., 0.9, 0.96, 0.88],
[100., 1.2, 1.27, 1.17],
[300., 1.3, 1.34, 1.31],
[1000., 1.2, 1.28, 1.22]]
# pack into MplData
rawdata = MplData(data=data, name='just-a-list')
rawdata = [[0.1, 0.1, 0.12, 0.1],
[0.3, 0.2, 0.22, 0.21],
[1.0, 0.4, 0.44, 0.41],
[3.0, 0.6, 0.65, 0.59],
[10., 1.0, 1.05, 1.01],
[30., 0.9, 0.96, 0.88],
[100., 1.2, 1.27, 1.17],
[300., 1.3, 1.34, 1.31],
[1000., 1.2, 1.28, 1.22]]
# Create an empty figure
fig = EmptyFig(figsize=(16., 12.))
......
......@@ -7,21 +7,18 @@ def script(with_print=False):
sys.path.append('../../')
from myplotlib.mpl_toolbox import Ax2dPlots, FormatterAppendToLines
from myplotlib import EmptyFig, MplData, VerticalGrid, HorizontalGrid
from myplotlib import EmptyFig, VerticalGrid, HorizontalGrid
# rawdata set
data = [[0.1, 0.1, 0.12, 0.1],
[0.3, 0.2, 0.22, 0.21],
[1.0, 0.4, 0.44, 0.41],
[3.0, 0.6, 0.65, 0.59],
[10., 1.0, 1.05, 1.01],
[30., 0.9, 0.96, 0.88],
[100., 1.2, 1.27, 1.17],
[300., 1.3, 1.34, 1.31],
[1000., 1.2, 1.28, 1.22]]
# pack into MplData
rawdata = MplData(data=data, name='just-a-list')
rawdata = [[0.1, 0.1, 0.12, 0.1],
[0.3, 0.2, 0.22, 0.21],
[1.0, 0.4, 0.44, 0.41],
[3.0, 0.6, 0.65, 0.59],
[10., 1.0, 1.05, 1.01],
[30., 0.9, 0.96, 0.88],
[100., 1.2, 1.27, 1.17],
[300., 1.3, 1.34, 1.31],
[1000., 1.2, 1.28, 1.22]]
# Create an empty figure
fig = EmptyFig(figsize=(16., 12.))
......
......@@ -69,8 +69,8 @@ class AxTest(MplAxes):
# give value to data a dict
# with xdata, ydata1, zdata, ydata2 ...
try:
self.data = {'x_data': [rawdata.data[0], rawdata.data[1]],
'y_data': [rawdata.data[2], rawdata.data[3]]}
self.data = {'x_data': [rawdata[0], rawdata[1]],
'y_data': [rawdata[2], rawdata[3]]}
except(TypeError, KeyError, IndexError):
......
Markdown is supported
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