Skip to content

Commit

Permalink
Added unit tests to test path resolution on Layout/Overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 23, 2017
1 parent e63d161 commit 6bf5d4e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
50 changes: 50 additions & 0 deletions tests/testcomposites.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,31 @@ def test_layouttree_quadruple_2(self):
('Element', 'LabelA', 'III'),
('Element', 'LabelA', 'IV')])

def test_layout_from_values_with_layouts(self):
layout1 = self.el1 + self.el4
layout2 = self.el2 + self.el5
paths = Layout.from_values([layout1, layout2]).keys()
self.assertEqual(paths, [('Element', 'I'), ('ValA', 'I'),
('Element', 'II'), ('ValB', 'I')])

def test_layout_from_values_with_mixed_types(self):
layout1 = self.el1 + self.el4 + self.el7
layout2 = self.el2 + self.el5 + self.el8
paths = Layout.from_values([layout1, layout2, self.el3]).keys()
self.assertEqual(paths, [('Element', 'I'), ('ValA', 'I'),
('ValA', 'LabelA'), ('Element', 'II'),
('ValB', 'I'), ('ValA', 'LabelB'),
('Element', 'III')])

def test_layout_from_values_retains_custom_path(self):
layout = Layout([('Custom', self.el1)])
paths = Layout.from_values([layout, self.el2]).keys()
self.assertEqual(paths, [('Custom', 'I'), ('Element', 'I')])

def test_layout_from_values_retains_custom_path_with_label(self):
layout = Layout([('Custom', self.el6)])
paths = Layout.from_values([layout, self.el2]).keys()
self.assertEqual(paths, [('Custom', 'LabelA'), ('Element', 'I')])


class OverlayTestCase(ElementTestCase):
Expand Down Expand Up @@ -253,6 +278,31 @@ def test_overlay_quadruple_2(self):
('Element', 'LabelA', 'III'),
('Element', 'LabelA', 'IV')])

def test_overlay_from_values_with_layouts(self):
layout1 = self.el1 + self.el4
layout2 = self.el2 + self.el5
paths = Layout.from_values([layout1, layout2]).keys()
self.assertEqual(paths, [('Element', 'I'), ('ValA', 'I'),
('Element', 'II'), ('ValB', 'I')])

def test_overlay_from_values_with_mixed_types(self):
overlay1 = self.el1 + self.el4 + self.el7
overlay2 = self.el2 + self.el5 + self.el8
paths = Layout.from_values([overlay1, overlay2, self.el3]).keys()
self.assertEqual(paths, [('Element', 'I'), ('ValA', 'I'),
('ValA', 'LabelA'), ('Element', 'II'),
('ValB', 'I'), ('ValA', 'LabelB'),
('Element', 'III')])

def test_overlay_from_values_retains_custom_path(self):
overlay = Overlay([('Custom', self.el1)])
paths = Overlay.from_values([overlay, self.el2]).keys()
self.assertEqual(paths, [('Custom', 'I'), ('Element', 'I')])

def test_overlay_from_values_retains_custom_path_with_label(self):
overlay = Overlay([('Custom', self.el6)])
paths = Overlay.from_values([overlay, self.el2]).keys()
self.assertEqual(paths, [('Custom', 'LabelA'), ('Element', 'I')])



Expand Down
51 changes: 49 additions & 2 deletions tests/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

from holoviews.core.util import (
sanitize_identifier_fn, find_range, max_range, wrap_tuple_streams,
deephash, merge_dimensions
deephash, merge_dimensions, get_path, make_path_unique
)
from holoviews import Dimension
from holoviews import Dimension, Element
from holoviews.streams import PositionXY
from holoviews.element.comparison import ComparisonTestCase

Expand Down Expand Up @@ -463,3 +463,50 @@ def test_merge_dimensions_with_values(self):
[Dimension('A', values=[1, 2]), Dimension('B')]])
self.assertEqual(dimensions, [Dimension('A'), Dimension('B')])
self.assertEqual(dimensions[0].values, [0, 1, 2])


class TestTreePathUtils(unittest.TestCase):

def test_get_path_with_label(self):
path = get_path(Element('Test', label='A'))
self.assertEqual(path, ('Element', 'A'))

def test_get_path_without_label(self):
path = get_path(Element('Test'))
self.assertEqual(path, ('Element',))

def test_get_path_with_custom_group(self):
path = get_path(Element('Test', group='Custom Group'))
self.assertEqual(path, ('Custom_Group',))

def test_get_path_with_custom_group_and_label(self):
path = get_path(Element('Test', group='Custom Group', label='A'))
self.assertEqual(path, ('Custom_Group', 'A'))

def test_get_path_from_item_with_custom_group(self):
path = get_path((('Custom',), Element('Test')))
self.assertEqual(path, ('Custom',))

def test_get_path_from_item_with_custom_group_and_label(self):
path = get_path((('Custom', 'Path'), Element('Test')))
self.assertEqual(path, ('Custom',))

def test_get_path_from_item_with_custom_group_and_matching_label(self):
path = get_path((('Custom', 'Path'), Element('Test', label='Path')))
self.assertEqual(path, ('Custom', 'Path'))

def test_make_path_unique_no_clash(self):
path = ('Element', 'A')
new_path = make_path_unique(path, {})
self.assertEqual(new_path, path)

def test_make_path_unique_clash_without_label(self):
path = ('Element',)
new_path = make_path_unique(path, {path: 1})
self.assertEqual(new_path, path+('I',))

def test_make_path_unique_clash_with_label(self):
path = ('Element', 'A')
new_path = make_path_unique(path, {path: 1})
self.assertEqual(new_path, path+('I',))

0 comments on commit 6bf5d4e

Please sign in to comment.