Commit 79a70a7a authored by Yori Fournier's avatar Yori Fournier
Browse files

Finished the tests for myAxes class (local version)

corrected an bug in the update function, to allow the user to pass
matplotlib properties as normal keywords and not like within matplotlib
with a dictionary. (So both have to be allowed!!!)
parent 8ae8beac
Pipeline #439 failed with stage
in 3 minutes and 6 seconds
......@@ -122,17 +122,18 @@ class MyAxes(Axes):
# UPDATE -----------------------------------------------------------
def update(self, *args, **kwargs):
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!!)
# Because matplotlib.axes.update expect kwargs and not **kwargs ... (stupid!! no, this is just WRONG!!)
if args: # catch matplotlib kwargs
kwargs = args[0]
# kwargs = args[0]
kwargs.update(args[0])
# kw_for_axes = {key: value for (key, value) in args[0].items() if key not in self.keywords} # Not compatible with python2.6
kw_for_axes = {}
for (key, value) in args[0].items():
if key not in self.keywords:
kw_for_axes.update({key: value})
kw_for_axes = {}
for (key, value) in kwargs.items():
if key not in self.keywords:
kw_for_axes.update({key: value})
Axes.update(self, kw_for_axes) # update matplotlib.Axes
Axes.update(self, kw_for_axes) # update matplotlib.Axes
# myplotlib update
# self.keywords.update({key: value for (key, value) in kwargs.items() if key in self.keywords}) # Not compatible with python2.6
......
......@@ -47,32 +47,41 @@ class TestMyAxes(unittest.TestCase):
def test_compute_rect_default(self):
'''Test the computeRect function without keywords.
'''
implemented=False
self.assertFalse(implemented)
ax = AxTest(self.fig, 0.3, [0., 0., 1., 1.])
self.assertEquals(ax.computeRect(42., [0., 0., 2., 2.]), [0., 0., 2., 2.])
def test_compute_rect_force_ratio_on_width(self):
'''Test the computeRect function with forceRatioOnWidth.
'''
implemented=False
self.assertFalse(implemented)
ax = AxTest(self.fig, 0.3, [0., 0., 1., 1.])
self.assertEquals(ax.computeRect(6./16., [0., 0., 12., 0.5], forceRatioOnWidth=True),
[0., 0., 1., 0.5])
def test_compute_rect_force_ratio_on_height(self):
'''Test the computeRect function with forceRatioOnHeight.
'''
implemented=False
self.assertFalse(implemented)
ax = AxTest(self.fig, 0.3, [0., 0., 1., 1.])
self.assertEquals(ax.computeRect(6./16., [0., 0., 1., 12.], forceRatioOnHeight=True),
[0., 0., 1., 0.5])
def test_update_with_matplotlib_args(self):
'''Test the update function.
'''Test the update function for matplotlib properties.
'''
implemented=False
self.assertFalse(implemented)
ax = AxTest(self.fig, 0.3, [0., 0., 1., 1.], axisbg='r', frameon=True)
self.assertEquals(ax._axisbg, 'r')
self.assertTrue(ax._frameon)
ax.update({'frame_on': False}) # <-- this is needed due to the bug in matplotlib.Axes.update(self, kwargs) [instead of **kwargs]
self.assertFalse(ax._frameon)
ax.update(frame_on=True)
self.assertTrue(ax._frameon)
def test_update_with_kwargs(self):
'''Test the update function.
'''
implemented=False
self.assertFalse(implemented)
ax = AxTest(self.fig, 0.3, [0., 0., 1., 1.])
self.assertIsNone(ax.keywords['xRange'])
ax.update(xRange=[-1., 1.])
self.assertEquals(ax.keywords['xRange'], [-1., 1.])
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