Skip to content

Commit

Permalink
Merge 087737f into 2458a13
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Jan 16, 2019
2 parents 2458a13 + 087737f commit 648a2b4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
8 changes: 5 additions & 3 deletions holoviews/core/tree.py
Expand Up @@ -218,12 +218,13 @@ def __delitem__(self, identifier):
def __setattr__(self, identifier, val):
# Getattr is skipped for root and first set of children
shallow = (self.parent is None or self.parent.parent is None)
if identifier[0].isupper() and self.fixed and shallow:

if util.tree_attribute(identifier) and self.fixed and shallow:
raise AttributeError(self._fixed_error % identifier)

super(AttrTree, self).__setattr__(identifier, val)

if identifier[0].isupper():
if util.tree_attribute(identifier):
if not identifier in self.children:
self.children.append(identifier)
self._propagate((identifier,), val)
Expand Down Expand Up @@ -254,7 +255,8 @@ def __getattr__(self, identifier):
if sanitized in self.children:
return self.__dict__[sanitized]

if not sanitized.startswith('_') and identifier[0].isupper():

if not sanitized.startswith('_') and util.tree_attribute(identifier):
self.children.append(sanitized)
dir_mode = self.__dict__['_dir_mode']
child_tree = self.__class__(identifier=sanitized,
Expand Down
13 changes: 13 additions & 0 deletions holoviews/core/util.py
Expand Up @@ -338,6 +338,19 @@ def deephash(obj):
return None


def tree_attribute(identifier):
"""
Predicate that returns True for custom attributes added to AttrTrees
that are not methods, properties or internal attributes.
These custom attributes start with a capitalized character when
applicable (not applicable to underscore or certain unicode characters)
"""
if identifier[0].upper().isupper() is False and identifier[0] != '_':
return True
else:
return identifier[0].isupper()

def argspec(callable_obj):
"""
Returns an ArgSpec object for functions, staticmethods, instance
Expand Down
17 changes: 15 additions & 2 deletions holoviews/tests/core/testlayouts.py
@@ -1,7 +1,13 @@
# -*- coding: utf-8 -*-
"""
Tests of Layout and related classes
"""

import sys
from holoviews import AdjointLayout, NdLayout, GridSpace, Layout, Element, HoloMap, Overlay
from holoviews.element import HLine
from holoviews.element import HLine, Curve
from holoviews.element.comparison import ComparisonTestCase

from unittest import SkipTest

class CompositeTest(ComparisonTestCase):
"For testing of basic composite element types"
Expand All @@ -19,6 +25,13 @@ def setUp(self):
def test_add_operator(self):
self.assertEqual(type(self.view1 + self.view2), Layout)

def test_add_unicode_py3(self):
"Test to avoid regression of #3403 where unicode characters don't capitalize"
if sys.version_info.major == 2: raise SkipTest
layout = Curve([-1,-2,-3]) + Curve([1,2,3]) .relabel('𝜗_1 vs th_2')
elements = list(layout)
self.assertEqual(len(elements), 2)


class AdjointLayoutTest(CompositeTest):

Expand Down
19 changes: 18 additions & 1 deletion holoviews/tests/core/testutils.py
Expand Up @@ -19,7 +19,7 @@
sanitize_identifier_fn, find_range, max_range, wrap_tuple_streams,
deephash, merge_dimensions, get_path, make_path_unique, compute_density,
date_range, dt_to_int, compute_edges, isfinite, cross_index, closest_match,
dimension_range
dimension_range, tree_attribute
)
from holoviews import Dimension, Element
from holoviews.streams import PointerXY
Expand Down Expand Up @@ -191,6 +191,23 @@ def test_prefix_test3_py3(self):
self.assertEqual(prefixed, True)


class TestTreeAttribute(ComparisonTestCase):

def test_simple_lowercase_string(self):
self.assertEqual(tree_attribute('lowercase'), False)

def test_simple_uppercase_string(self):
self.assertEqual(tree_attribute('UPPERCASE'), True)

def test_unicode_string(self):
if py_version != 2: raise SkipTest
self.assertEqual(tree_attribute('𝜗unicode'), True)

def test_underscore_string(self):
if py_version != 2: raise SkipTest
self.assertEqual(tree_attribute('_underscore'), True)


class TestSanitizationPy2(ComparisonTestCase):
"""
Tests of sanitize_identifier (Python 2)
Expand Down

0 comments on commit 648a2b4

Please sign in to comment.