Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.curve1 = Curve([(0.1*i, np.sin(0.1*i)) for i in range(100)])
self.curve2 = Curve([(0.1*i, np.sin(0.1*i)) for i in range(101)])
def test_curves_equal(self):
self.assertEqual(self.curve1, self.curve1)
def test_curves_unequal(self):
try:
self.assertEqual(self.curve1, self.curve2)
except AssertionError as e:
if not str(e).startswith("Curve not of matching length."):
raise self.failureException("Curve mismatch error not raised.")
class BarsComparisonTest(ComparisonTestCase):
def setUp(self):
"Variations on the constructors in the Elements notebook"
key_dims1=[Dimension('Car occupants')]
key_dims2=[Dimension('Cyclists')]
value_dims1=['Count']
self.bars1 = Bars([('one',8),('two', 10), ('three', 16)],
kdims=key_dims1, vdims=value_dims1)
self.bars2 = Bars([('one',8),('two', 10), ('three', 17)],
kdims=key_dims1, vdims=value_dims1)
self.bars3 = Bars([('one',8),('two', 10), ('three', 16)],
kdims=key_dims2, vdims=value_dims1)
def test_bars_equal_1(self):
self.assertEqual(self.bars1, self.bars1)
expected= {'Layout':
{'norm': Options(axiswise=True, framewise=True)}}
self.assertEqual(OptsSpec.parse(line), expected)
def test_norm_opts_multiple_paths(self):
line = "Image Curve {+axiswise +framewise}"
expected = {'Image':
{'norm':
Options(axiswise=True, framewise=True)},
'Curve':
{'norm':
Options(axiswise=True, framewise=True)}}
self.assertEqual(OptsSpec.parse(line), expected)
class OptsSpecCombinedOptionsTests(ComparisonTestCase):
def test_combined_1(self):
line = "Layout plot[fig_inches=(3,3) foo='bar baz'] Layout (string='foo')"
expected= {'Layout':
{'plot':
Options(foo='bar baz', fig_inches=(3, 3)),
'style': Options(string='foo')}}
self.assertEqual(OptsSpec.parse(line), expected)
def test_combined_two_types_1(self):
line = "Layout plot[fig_inches=(3,3) foo='bar baz'] Image (string='foo')"
expected= {'Layout':
{'plot':
Options(foo='bar baz', fig_inches=(3, 3))},
'Image': {
'style': Options(string='foo')}}
def test_dmap_overlay_linked_operation_mul_dmap_ndoverlay(self):
mapped = operation(self.dmap_overlay, link_inputs=True)
test = mapped * self.dmap_ndoverlay
initialize_dynamic(test)
layers = [mapped, mapped, self.dmap_ndoverlay]
self.assertEqual(split_dmap_overlay(test), layers)
def test_dmap_overlay_linked_operation_mul_dmap_element_ndoverlay(self):
mapped = self.dmap_overlay.map(lambda x: x.get(0), Overlay)
test = mapped * self.element * self.dmap_ndoverlay
initialize_dynamic(test)
layers = [mapped, self.element, self.dmap_ndoverlay]
self.assertEqual(split_dmap_overlay(test), layers)
class TestPlotColorUtils(ComparisonTestCase):
def test_process_cmap_list_cycle(self):
colors = process_cmap(['#ffffff', '#959595', '#000000'], 4)
self.assertEqual(colors, ['#ffffff', '#959595', '#000000', '#ffffff'])
def test_process_cmap_cycle(self):
colors = process_cmap(Cycle(values=['#ffffff', '#959595', '#000000']), 4)
self.assertEqual(colors, ['#ffffff', '#959595', '#000000', '#ffffff'])
def test_process_cmap_invalid_str(self):
with self.assertRaises(ValueError):
process_cmap('NonexistentColorMap', 3)
def test_process_cmap_invalid_type(self):
with self.assertRaises(TypeError):
process_cmap({'A', 'B', 'C'}, 3)
ndmap = MultiDimensionalMapping([('A', nested1)])
nested2 = MultiDimensionalMapping([('B', 2)])
ndmap['A'] = nested2
self.assertEqual(ndmap['A'], nested2)
def test_setitem_nested_2(self):
nested1 = MultiDimensionalMapping([('B', 1)])
ndmap = MultiDimensionalMapping([('A', nested1)])
nested2 = MultiDimensionalMapping([('C', 2)])
nested_clone = nested1.clone()
nested_clone.update(nested2)
ndmap.update({'A': nested2})
self.assertEqual(ndmap['A'].data, nested_clone.data)
class HoloMapTest(ComparisonTestCase):
def setUp(self):
self.xs = range(11)
self.y_ints = [i*2 for i in range(11)]
self.ys = np.linspace(0, 1, 11)
self.columns = Dataset(np.column_stack([self.xs, self.y_ints]),
kdims=['x'], vdims=['y'])
def test_holomap_redim(self):
hmap = HoloMap({i: Dataset({'x':self.xs, 'y': self.ys * i},
kdims=['x'], vdims=['y'])
for i in range(10)}, kdims=['z'])
redimmed = hmap.redim(x='Time')
self.assertEqual(redimmed.dimensions('all', True),
['z', 'Time', 'y'])
xs = np.arange(30)[::-1]
ys = np.random.rand(30)
ds = Dataset((xs, ys), 'x', 'y')
sliced = ds[5:15]
self.assertEqual(sliced, Dataset((xs[15:25], ys[15:25]), 'x', 'y'))
def test_sample_2d(self):
xs = ys = np.linspace(0, 6, 50)
XS, YS = np.meshgrid(xs, ys)
values = np.sin(XS)
sampled = Dataset((xs, ys, values), ['x', 'y'], 'z').sample(y=0)
self.assertEqual(sampled, Curve((xs, values[0]), vdims='z'))
class GridDatasetTest(GridTests, HomogeneousColumnTypes, ComparisonTestCase):
def setUp(self):
self.restore_datatype = Dataset.datatype
Dataset.datatype = ['grid']
self.eltype = Dataset
self.data_instance_type = dict
self.init_grid_data()
self.init_column_data()
def test_dataset_dataframe_init_hm(self):
"Tests support for homogeneous DataFrames"
if pd is None:
raise SkipTest("Pandas not available")
exception = "None of the available storage backends "\
"were able to support the supplied data format."
with self.assertRaisesRegexp(Exception, exception):
import numpy as np
from holoviews import HoloMap, Image, GridSpace, Table, Curve, Store
from holoviews.plotting import Renderer
from holoviews.element.comparison import ComparisonTestCase
try:
from bokeh.io import curdoc
from holoviews.plotting.bokeh import BokehRenderer
from bokeh.themes.theme import Theme
except:
pass
@attr(optional=1)
class BokehRendererTest(ComparisonTestCase):
def setUp(self):
if 'bokeh' not in Store.renderers:
raise SkipTest("Bokeh required to test widgets")
self.image1 = Image(np.array([[0,1],[2,3]]), label='Image1')
self.image2 = Image(np.array([[1,0],[4,-2]]), label='Image2')
self.map1 = HoloMap({1:self.image1, 2:self.image2}, label='TestMap')
self.renderer = BokehRenderer.instance()
self.nbcontext = Renderer.notebook_context
Renderer.notebook_context = False
def tearDown(self):
Renderer.notebook_context = self.nbcontext
def test_save_html(self):
bytesio = BytesIO()
dim1 = Dimension(('test', 'label1'))
dim2 = Dimension(('test', 'label2'))
self.assertEqual(dim1==str(dim2), True)
def test_weak_dim_equality(self):
dim1 = Dimension('test', cyclic=True, unit='m', type=float)
dim2 = Dimension('test', cyclic=False, unit='km', type=int)
self.assertEqual(dim1==dim2, True)
def test_weak_str_equality(self):
dim1 = Dimension('test', cyclic=True, unit='m', type=float)
dim2 = Dimension('test', cyclic=False, unit='km', type=int)
self.assertEqual(dim1==str(dim2), True)
class DimensionValuesTest(ComparisonTestCase):
def setUp(self):
self.values1 = [0,1,2,3,4,5,6]
self.values2 = ['a','b','c','d']
self.duplicates1 = [0,1,0,2,3,4,3,2,5,5,6]
self.duplicates2 = ['a','b','b','a','c','a','c','d','d']
def test_dimension_values_list1(self):
dim = Dimension('test', values=self.values1)
self.assertEqual(dim.values, self.values1)
def test_dimension_values_list2(self):
dim = Dimension('test', values=self.values2)
self.assertEqual(dim.values, self.values2)
raise SkipTest("Not supported")
def test_dataset_sort_vdim_hm(self):
raise SkipTest("Not supported")
def test_dataset_sort_vdim_hm_alias(self):
raise SkipTest("Not supported")
def test_dataset_sort_string_ht(self):
raise SkipTest("Not supported")
def test_dataset_boolean_index(self):
raise SkipTest("Not supported")
class DictDatasetTest(HeterogeneousColumnTypes, ScalarColumnTypes, ComparisonTestCase):
"""
Test of the generic dictionary interface.
"""
datatype = 'dictionary'
def setUp(self):
self.restore_datatype = Dataset.datatype
Dataset.datatype = ['dictionary']
self.data_instance_type = (dict, cyODict, OrderedDict)
self.init_column_data()
def test_dataset_simple_dict_sorted(self):
dataset = Dataset({2: 2, 1: 1, 3: 3}, kdims=['x'], vdims=['y'])
self.assertEqual(dataset, Dataset([(i, i) for i in range(1, 4)],
kdims=['x'], vdims=['y']))
"""
from holoviews.element.comparison import ComparisonTestCase
from unittest import SkipTest
try:
import pyparsing # noqa (import test)
from holoviews.util.parser import OptsSpec
except ImportError:
raise SkipTest("Required dependencies not satisfied for testing parsers")
from holoviews.core.options import Options, Cycle
class OptsSpecPlotOptionsTests(ComparisonTestCase):
"""
Test the OptsSpec parser works correctly for plot options.
"""
def test_plot_opts_simple(self):
line = "Layout [fig_inches=(3,3) title_format='foo bar']"
expected= {'Layout':
{'plot':
Options(title_format='foo bar', fig_inches=(3, 3))}}
self.assertEqual(OptsSpec.parse(line), expected)
def test_plot_opts_with_space(self):
"Space in the tuple, see issue #77"
line = "Layout [fig_inches=(3, 3) title_format='foo bar']"
expected= {'Layout':
{'plot':
def __call__(self, *testargs):
return sum(testargs)
class ParamFunc(param.ParameterizedFunction):
a = param.Integer(default=1)
b = param.Number(default=1)
def __call__(self, a, **params):
p = param.ParamOverrides(self, params)
return a * p.b
class TestCallableName(ComparisonTestCase):
def test_simple_function_name(self):
def foo(x,y): pass
self.assertEqual(Callable(foo).name, 'foo')
def test_simple_lambda_name(self):
self.assertEqual(Callable(lambda x: x).name, '')
def test_partial_name(self):
py2match = '