From b97318707b3868dadc1eaaee85381dc6d8dc53e8 Mon Sep 17 00:00:00 2001
From: Philipp Rudiger
Date: Sun, 8 Oct 2017 17:23:12 +0100
Subject: [PATCH] Added unit tests for Element constructors signature
---
tests/testelementconstructors.py | 95 +++++++++++++++++++++++++++++++-
1 file changed, 94 insertions(+), 1 deletion(-)
diff --git a/tests/testelementconstructors.py b/tests/testelementconstructors.py
index f3d33b324a..3bbafeb609 100644
--- a/tests/testelementconstructors.py
+++ b/tests/testelementconstructors.py
@@ -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):
@@ -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')])
+
+