Skip to content

Commit

Permalink
Added unit tests for Element constructors signature
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 8, 2017
1 parent 936f000 commit b973187
Showing 1 changed file with 94 additions and 1 deletion.
95 changes: 94 additions & 1 deletion tests/testelementconstructors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import numpy as np

from holoviews import Dataset, Curve, Path, Histogram, HeatMap
from holoviews import (Dimension, Dataset, Curve, Path, Histogram,
HeatMap, Contours, Scatter, Points, Polygons,
VectorField, Spikes, Area, Bars, ErrorBars,
BoxWhisker, Raster, Image, QuadMesh, RGB)
from holoviews.element.comparison import ComparisonTestCase

class ElementConstructorTest(ComparisonTestCase):
Expand Down Expand Up @@ -82,3 +85,93 @@ def test_heatmap_construct_and_sort(self):
'z': [[np.NaN, 0, 0], [0, np.NaN, 2], [0, 2, np.NaN]]},
kdims=['x', 'y'], vdims=['z'])
self.assertEqual(hmap.gridded, dataset)



class ElementSignatureTest(ComparisonTestCase):
"""
Test that Element signatures are consistent.
"""

def test_curve_string_signature(self):
curve = Curve([], 'a', 'b')
self.assertEqual(curve.kdims, [Dimension('a')])
self.assertEqual(curve.vdims, [Dimension('b')])

def test_area_string_signature(self):
area = Area([], 'a', 'b')
self.assertEqual(area.kdims, [Dimension('a')])
self.assertEqual(area.vdims, [Dimension('b')])

def test_errorbars_string_signature(self):
errorbars = ErrorBars([], 'a', ['b', 'c'])
self.assertEqual(errorbars.kdims, [Dimension('a')])
self.assertEqual(errorbars.vdims, [Dimension('b'), Dimension('c')])

def test_bars_string_signature(self):
bars = Bars([], 'a', 'b')
self.assertEqual(bars.kdims, [Dimension('a')])
self.assertEqual(bars.vdims, [Dimension('b')])

def test_boxwhisker_string_signature(self):
boxwhisker = BoxWhisker([], 'a', 'b')
self.assertEqual(boxwhisker.kdims, [Dimension('a')])
self.assertEqual(boxwhisker.vdims, [Dimension('b')])

def test_scatter_string_signature(self):
scatter = Scatter([], 'a', 'b')
self.assertEqual(scatter.kdims, [Dimension('a')])
self.assertEqual(scatter.vdims, [Dimension('b')])

def test_points_string_signature(self):
points = Points([], ['a', 'b'], 'c')
self.assertEqual(points.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(points.vdims, [Dimension('c')])

def test_vectorfield_string_signature(self):
vectorfield = VectorField([], ['a', 'b'], ['c', 'd'])
self.assertEqual(vectorfield.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(vectorfield.vdims, [Dimension('c'), Dimension('d')])

def test_path_string_signature(self):
path = Path([], ['a', 'b'])
self.assertEqual(path.kdims, [Dimension('a'), Dimension('b')])

def test_spikes_string_signature(self):
spikes = Spikes([], 'a')
self.assertEqual(spikes.kdims, [Dimension('a')])

def test_contours_string_signature(self):
contours = Contours([], ['a', 'b'])
self.assertEqual(contours.kdims, [Dimension('a'), Dimension('b')])

def test_polygons_string_signature(self):
polygons = Polygons([], ['a', 'b'])
self.assertEqual(polygons.kdims, [Dimension('a'), Dimension('b')])

def test_heatmap_string_signature(self):
heatmap = HeatMap([], ['a', 'b'], 'c')
self.assertEqual(heatmap.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(heatmap.vdims, [Dimension('c')])

def test_raster_string_signature(self):
raster = Raster(np.array([[0]]), ['a', 'b'], 'c')
self.assertEqual(raster.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(raster.vdims, [Dimension('c')])

def test_image_string_signature(self):
img = Image(np.array([[0, 1], [0, 1]]), ['a', 'b'], 'c')
self.assertEqual(img.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(img.vdims, [Dimension('c')])

def test_rgb_string_signature(self):
img = RGB(np.zeros((2, 2, 3)), ['a', 'b'], ['R', 'G', 'B'])
self.assertEqual(img.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(img.vdims, [Dimension('R'), Dimension('G'), Dimension('B')])

def test_quadmesh_string_signature(self):
qmesh = QuadMesh(([0, 1], [0, 1], np.array([[0, 1], [0, 1]])), ['a', 'b'], 'c')
self.assertEqual(qmesh.kdims, [Dimension('a'), Dimension('b')])
self.assertEqual(qmesh.vdims, [Dimension('c')])


0 comments on commit b973187

Please sign in to comment.