Commit cb1d2e7f authored by Yori Fournier's avatar Yori Fournier
Browse files

Merge branch '_compatible_sml_py3' of gitlab.aip.de:yfournier/myplotlib into _compatible_sml_py3

Conflicts:
	mpl_fig.py
parents 3242ad3c f9f74239
Pipeline #660 failed with stage
in 27 minutes and 17 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
- python -m pip install --upgrade pip
- python -m pip install -U matplotlib
- python -m pip install pep8
- python3 get-pip.py
- python3 -m pip --version
- python3 -m pip install --upgrade pip
- python3 -m pip install -U matplotlib
- python3 -m pip install pep8
myplotlib_import_local_latex_tkagg:
script:
......@@ -14,9 +14,9 @@ myplotlib_import_local_latex_tkagg:
- ls -l
- cd test/localhost
- ./setup_test_folder.sh -r latex-tkagg
- python import_test.py
- python -m tests
- python -m tutorials
- python3 import_test.py
- python3 -m tests
- python3 -m tutorials
- ./clean_test_folder.sh
myplotlib_test_mytool:
......@@ -25,8 +25,8 @@ myplotlib_test_mytool:
- ls -l
- cd mpl_toolbox/
- cp ../.configs/tests/config-local.py ../config.py
- python -m tests
- python -m tutorials
- python3 -m tests
- python3 -m tutorials
myplotlib_import_network_latex_tkagg:
script:
......@@ -34,8 +34,8 @@ myplotlib_import_network_latex_tkagg:
- ls -l
- cd test/network
- ./setup_test_folder.sh -r latex-tkagg
- python test_com_nogl.py
- python -m tests
- python3 test_com_nogl.py
- python3 -m tests
- ./clean_test_folder.sh
myplotlib_test_pep8:
......@@ -43,5 +43,5 @@ myplotlib_test_pep8:
- git name-rev --name-only HEAD
- ls -l
- cd test
- python -m comp_pep8
- python3 -m comp_pep8
allow_failure: true
......@@ -87,11 +87,12 @@ else:
raise ImportError
# myplotlib
from .mpl_data import MplData
# from .mpl_data import MplData
# CONFIGURATION --------------------------------------------------------
from .config import D_FIGNUM, D_FIGSIZE, D_REFORMAT, D_FORMATTED
from .config import D_RAWDATA, D_INPUTARG
# from .config import D_RAWDATA, D_INPUTARG
from .config import D_INPUTARG
from .config import D_IPATH
from .config import D_OPATH, D_OFORMAT
from .config import D_DEBUG
......
......@@ -7,5 +7,5 @@ class EmptyAxes(MplAxes):
return(True)
def format_rawdata(self, rawdata):
self.data = rawdata.data
self.data = rawdata
return(True)
......@@ -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 ---------------------------------
......
......@@ -73,7 +73,7 @@ from . import D_OFORMAT, D_OPATH
from . import DBUG, SEVR, INFO, SPCE, WARN
from . import CONTEXT
from . import MplData
# from . import MplData
from . import MplAxes
from . import HorizontalGrid
......@@ -578,14 +578,13 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
After the rawdata is successfully set, it will be formatted.
"""
from collections import Iterable
from itertools import repeat
#from collections import Iterable
self.formatted = False
status = False
# DEFAULT: one item per axes in figure
if isinstance(rawdata, Iterable):
if isinstance(rawdata, tuple):
if len(rawdata) == len(self.get_axes()):
if(self.debug):
......@@ -604,21 +603,12 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
len_rawdata=len(rawdata)))
return(False)
# CONVINIENT: one object for all axes
elif isinstance(rawdata, MplData):
if(self.debug):
print("{dbug} set_rawdata: one item for all axes\
".format(dbug=DBUG))
# This is the trick rawdata becomes a generator (so smart)
self.rawdata = repeat(rawdata)
status = self.format_rawdata()
else:
print("{sevr} set_rawdata: I could not set the rawdata...\
".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...\
......@@ -645,11 +635,10 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
if(self.debug):
print("{info} Axes: {axes_class_name} \
with index {index} formats {rawdata_name}\
with index {index} formats rawdata\
".format(info=INFO,
axes_class_name=ax.__class__.__name__,
index=self.get_axes().index(ax),
rawdata_name=rawdata.name))
index=self.get_axes().index(ax)))
status = ax.test_rawdata(rawdata)
if status:
status = ax.format_rawdata(rawdata)
......@@ -1001,9 +990,6 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
After the rawdata is successfully set, it will be formatted.
"""
from collections import Iterable
from itertools import repeat
self.formatted = False
status = False
......@@ -1020,13 +1006,13 @@ class MplFig(metaclass=FigureClassFactory, context=CONTEXT.lower()):
status = self.format_rawdata()
# DEFAULT: one item per axes in figure
elif isinstance(rawdata, Iterable):
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:
......@@ -1044,6 +1030,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...\
......@@ -1051,7 +1038,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):
......
......@@ -11,7 +11,7 @@ from . import SERVER_FIGURES
from . import MplFig
from . import DBUG, WARN, SPCE, SEVR, INFO
from . import MplUnpickler, MplData
from . import MplUnpickler
from . import D_DEBUG
......@@ -78,12 +78,12 @@ class MplHandler(socketserver.StreamRequestHandler):
try:
for data_name in data_names:
if self.server._rawdata.get(data_name, None) is not None:
merged_data.append(self.server._rawdata[data_name].data)
merged_data.append(self.server._rawdata[data_name])
else:
return Status(False, 'Could not create '
+ str(merged_name) + ', ' + str(data_name) + ' does not exist...')
self.server._rawdata[merged_name] = MplData(data=merged_data, name=merged_name)
self.server._rawdata[merged_name] = merged_data
return Status(True, 'data '
+ str(merged_name) + ' was successfully created from ' + str(data_names))
......@@ -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],