Skip to content
Permalink
Browse files

Added unit test to check %%opts magic inheritance

  • Loading branch information...
jlstevens committed Jul 26, 2016
1 parent 1957484 commit 20b05388158f4d7d2d74fa8448519a67145598d0
Showing with 28 additions and 0 deletions.
  1. +28 −0 tests/testoptions.py
@@ -356,6 +356,34 @@ def test_custom_call_to_default_inheritance(self):
custom_obj_lookup = Store.lookup_options('matplotlib', custom_obj, 'style')
self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)

def test_custom_magic_to_default_inheritance(self):
"""
Checks customs inheritance backs off to default tree correctly
simulating the %%opts cell magic.
"""
if 'matplotlib' not in Store.renderers:
raise SkipTest("Custom magic inheritance test requires matplotlib")
options = self.initialize_option_tree()
options.Image.A.B = Options('style', alpha=0.2)

obj = Image(np.random.rand(10, 10), group='A', label='B')

# Before customizing...
expected_obj = {'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest'}
obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
self.assertEqual(obj_lookup.kwargs, expected_obj)

custom_tree = {0: OptionTree(groups=['plot', 'style', 'norm'],
style={'Image' : dict(clims=(0, 0.5))})}
Store._custom_options['matplotlib'] = custom_tree
obj.id = 0 # Manually set the id to point to the tree above

# Customize this particular object
expected_custom_obj = dict(clims=(0,0.5), **expected_obj)
custom_obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)



class TestStoreInheritance(ComparisonTestCase):
"""

0 comments on commit 20b0538

Please sign in to comment.
You can’t perform that action at this time.