示例#1
0
 def test_mpl_bokeh_mpl_via_builders_opts_method(self):
     img = Image(np.random.rand(10,10))
     mpl_opts = opts.Image(cmap='Blues', backend='matplotlib')
     bokeh_opts = opts.Image(cmap='Purple', backend='bokeh')
     self.assertEqual(mpl_opts.kwargs['backend'], 'matplotlib')
     self.assertEqual(bokeh_opts.kwargs['backend'], 'bokeh')
     img.opts(mpl_opts, bokeh_opts)
     mpl_lookup = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_lookup['cmap'], 'Blues')
     bokeh_lookup = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_lookup['cmap'], 'Purple')
     self.assert_output_options_group_empty(img)
示例#2
0
 def test_opts_clear_clone(self):
     im = Image(np.random.rand(10, 10))
     styled_im = im.opts(style=dict(cmap='jet',
                                    interpolation='nearest',
                                    option1='A',
                                    option2='B'),
                         clone=False)
     self.assertEqual(
         self.lookup_options(im, 'style').options, {
             'cmap': 'jet',
             'interpolation': 'nearest',
             'option1': 'A',
             'option2': 'B'
         })
     assert styled_im is im
     cleared = im.opts.clear(clone=True)
     assert cleared is not im
     self.assertEqual(
         self.lookup_options(im, 'style').options, {
             'cmap': 'jet',
             'interpolation': 'nearest',
             'option1': 'A',
             'option2': 'B'
         })
     cleared_options = self.lookup_options(cleared, 'style').options
     self.assertEqual(
         not any(k in ['option1', 'option2']
                 for k in cleared_options.keys()), True)
示例#3
0
    def test_opts_method_with_utility(self):
        im = Image(np.random.rand(10,10))
        imopts = opts.Image(cmap='Blues')
        styled_im = im.opts(imopts)

        assert styled_im is im
        self.assertEqual(self.lookup_options(im, 'style').options,
                         {'cmap': 'Blues', 'interpolation': 'nearest'})
示例#4
0
    def test_opts_method_with_utility(self):
        im = Image(np.random.rand(10,10))
        imopts = opts.Image(cmap='Blues')
        styled_im = im.opts(imopts)

        assert styled_im is im
        self.assertEqual(self.lookup_options(im, 'style').options,
                         {'cmap': 'Blues', 'interpolation': 'nearest'})
示例#5
0
    def test_simple_clone_disabled(self):
        im = Image(np.random.rand(10,10))
        styled_im = im.opts(interpolation='nearest', cmap='jet', clone=False)

        self.assertEqual(self.lookup_options(im, 'plot').options, {})
        self.assertEqual(self.lookup_options(styled_im, 'plot').options, {})

        assert styled_im is im
        self.assertEqual(self.lookup_options(im, 'style').options,
                         {'cmap': 'jet', 'interpolation': 'nearest'})
示例#6
0
    def test_simple_clone_disabled(self):
        im = Image(np.random.rand(10,10))
        styled_im = im.opts(interpolation='nearest', cmap='jet', clone=False)

        self.assertEqual(self.lookup_options(im, 'plot').options, {})
        self.assertEqual(self.lookup_options(styled_im, 'plot').options, {})

        assert styled_im is im
        self.assertEqual(self.lookup_options(im, 'style').options,
                         {'cmap': 'jet', 'interpolation': 'nearest'})
示例#7
0
    def test_simple_opts_clone_enabled(self):
        im = Image(np.random.rand(10, 10))
        styled_im = im.opts(interpolation='nearest', cmap='jet', clone=True)

        self.assertEqual(self.lookup_options(im, 'plot').options, {})
        self.assertEqual(self.lookup_options(styled_im, 'plot').options, {})

        assert styled_im is not im
        im_lookup = self.lookup_options(im, 'style').options
        self.assertEqual(im_lookup['cmap'] == 'jet', False)
        styled_im_lookup = self.lookup_options(styled_im, 'style').options
        self.assertEqual(styled_im_lookup['cmap'] == 'jet', True)
示例#8
0
    def test_simple_opts_clone_enabled(self):
        im = Image(np.random.rand(10,10))
        styled_im = im.opts(interpolation='nearest', cmap='jet', clone=True)

        self.assertEqual(self.lookup_options(im, 'plot').options, {})
        self.assertEqual(self.lookup_options(styled_im, 'plot').options, {})

        assert styled_im is not im
        im_lookup = self.lookup_options(im, 'style').options
        self.assertEqual(im_lookup['cmap'] == 'jet', False)
        styled_im_lookup =  self.lookup_options(styled_im, 'style').options
        self.assertEqual(styled_im_lookup['cmap'] == 'jet', True)
示例#9
0
 def test_opts_clear(self):
     im = Image(np.random.rand(10,10))
     styled_im = im.opts(style=dict(cmap='jet', interpolation='nearest',
                                    option1='A', option2='B'), clone=False)
     self.assertEqual(self.lookup_options(im, 'style').options,
                      {'cmap': 'jet', 'interpolation': 'nearest',
                       'option1':'A', 'option2':'B'})
     assert styled_im is im
     cleared = im.opts.clear()
     assert cleared is im
     cleared_options = self.lookup_options(cleared, 'style').options
     self.assertEqual(not any(k in ['option1', 'option2']
                              for k in cleared_options.keys()), True)
示例#10
0
    def test_custom_opts_to_default_inheritance(self):
        """
        Checks customs inheritance backs off to default tree correctly
        using .opts.
        """
        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')
        expected_obj =  {'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest'}
        obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(obj_lookup.kwargs, expected_obj)

        # Customize this particular object
        custom_obj = obj.opts(style=dict(clims=(0, 0.5)))
        expected_custom_obj =  dict(clims=(0,0.5), **expected_obj)
        custom_obj_lookup = Store.lookup_options('matplotlib', custom_obj, 'style')
        self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)
示例#11
0
    def test_custom_opts_to_default_inheritance(self):
        """
        Checks customs inheritance backs off to default tree correctly
        using .opts.
        """
        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')
        expected_obj =  {'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest'}
        obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(obj_lookup.kwargs, expected_obj)

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