Here are the examples of the python api bokeh.core.properties.List taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
3
View Source File : test_either.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_valid(self):
prop = bcpe.Either(Interval(Int, 0, 100), Regex("^x*$"), List(Int))
assert prop.is_valid(None)
assert prop.is_valid(0)
assert prop.is_valid(1)
assert prop.is_valid("")
assert prop.is_valid("xxx")
assert prop.is_valid([])
assert prop.is_valid([1, 2, 3])
assert prop.is_valid(100)
# TODO (bev) should fail
assert prop.is_valid(False)
assert prop.is_valid(True)
def test_invalid(self):
3
View Source File : test_either.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_invalid(self):
prop = bcpe.Either(Interval(Int, 0, 100), Regex("^x*$"), List(Int))
assert not prop.is_valid(0.0)
assert not prop.is_valid(1.0)
assert not prop.is_valid(1.0+1.0j)
assert not prop.is_valid(())
assert not prop.is_valid({})
assert not prop.is_valid(_TestHasProps())
assert not prop.is_valid(_TestModel())
assert not prop.is_valid(-100)
assert not prop.is_valid("yyy")
assert not prop.is_valid([1, 2, ""])
def test_has_ref(self):
3
View Source File : test_validation.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_List(self):
p = List(Float)
with pytest.raises(ValueError) as e:
p.validate("junk")
assert not str(e).endswith("ValueError")
def test_Seq(self):
3
View Source File : test_validation.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_List(self, detail):
p = List(Float)
with pytest.raises(ValueError) as e:
p.validate("junk", detail)
assert str(e).endswith("ValueError") == (not detail)
def test_Seq(self, detail):
3
View Source File : test_objects.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_list_default(self):
class HasListDefault(Model):
value = List(String, default=["hello"])
obj = HasListDefault()
assert obj.value == obj.value
# 'value' should not be included because we haven't modified it
assert 'value' not in obj.properties_with_values(include_defaults=False)
# (but should be in include_defaults=True)
assert 'value' in obj.properties_with_values(include_defaults=True)
obj.value.append("world")
# 'value' should now be included
assert 'value' in obj.properties_with_values(include_defaults=False)
def test_dict_default(self):
0
View Source File : test_descriptors.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test___delete__(self):
class Foo(Model):
foo = Int()
bar = List(Int, default=[10])
baz = Int(default=20)
quux = List(Int, default=[30])
f = Foo()
f.foo
f.bar
f.baz
f.quux
calls = []
def cb(attr, old, new):
calls.append(attr)
for name in ['foo', 'bar', 'baz', 'quux']:
f.on_change(name, cb)
assert f._property_values == {}
assert f._unstable_default_values == dict(bar=[10], quux=[30])
del f.foo
assert f._property_values == {}
assert f._unstable_default_values == dict(bar=[10], quux=[30])
assert calls == []
f.baz = 50
assert f.baz == 50
assert f._unstable_default_values == dict(bar=[10], quux=[30])
assert calls == ['baz']
del f.baz
assert f.baz == 20
assert f._unstable_default_values == dict(bar=[10], quux=[30])
assert calls == ['baz', 'baz']
del f.bar
assert f._property_values == {}
assert f._unstable_default_values == dict(quux=[30])
assert calls == ['baz', 'baz']
f.bar = [60]
assert f.bar == [60]
assert f._unstable_default_values == dict(quux=[30])
assert calls == ['baz', 'baz', 'bar']
del f.bar
assert f.bar == [10]
assert f._unstable_default_values == dict(bar=[10], quux=[30])
assert calls == ['baz', 'baz', 'bar', 'bar']
del f.quux
assert f._unstable_default_values == dict(bar=[10])
assert calls == ['baz', 'baz', 'bar', 'bar']
def test_class_default(self):
0
View Source File : test_properties.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_simple_class(self):
class Foo(HasProps):
x = Int(12)
y = String("hello")
z = List(Int, [1, 2, 3])
zz = Dict(String, Int)
s = String(None)
f = Foo()
assert f.x == 12
assert f.y == "hello"
assert np.array_equal(np.array([1, 2, 3]), f.z)
assert f.s is None
assert set(["x", "y", "z", "zz", "s"]) == f.properties()
with_defaults = f.properties_with_values(include_defaults=True)
assert dict(x=12, y="hello", z=[1,2,3], zz={}, s=None) == with_defaults
without_defaults = f.properties_with_values(include_defaults=False)
assert dict() == without_defaults
f.x = 18
assert f.x == 18
f.y = "bar"
assert f.y == "bar"
without_defaults = f.properties_with_values(include_defaults=False)
assert dict(x=18, y="bar") == without_defaults
f.z[0] = 100
without_defaults = f.properties_with_values(include_defaults=False)
assert dict(x=18, y="bar", z=[100,2,3]) == without_defaults
f.zz = {'a': 10}
without_defaults = f.properties_with_values(include_defaults=False)
assert dict(x=18, y="bar", z=[100,2,3], zz={'a': 10}) == without_defaults
def test_enum(self):
0
View Source File : test_properties.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_accurate_properties_sets(self):
class Base(HasProps):
num = Int(12)
container = List(String)
child = Instance(HasProps)
class Mixin(HasProps):
mixin_num = Int(12)
mixin_container = List(String)
mixin_child = Instance(HasProps)
class Sub(Base, Mixin):
sub_num = Int(12)
sub_container = List(String)
sub_child = Instance(HasProps)
b = Base()
assert set(["child"]) == b.properties_with_refs()
assert set(["container"]) == b.properties_containers()
assert set(["num", "container", "child"]) == b.properties()
assert set(["num", "container", "child"]) == b.properties(with_bases=True)
assert set(["num", "container", "child"]) == b.properties(with_bases=False)
m = Mixin()
assert set(["mixin_child"]) == m.properties_with_refs()
assert set(["mixin_container"]) == m.properties_containers()
assert set(["mixin_num", "mixin_container", "mixin_child"]) == m.properties()
assert set(["mixin_num", "mixin_container", "mixin_child"]) == m.properties(with_bases=True)
assert set(["mixin_num", "mixin_container", "mixin_child"]) == m.properties(with_bases=False)
s = Sub()
assert set(["child", "sub_child", "mixin_child"]) == s.properties_with_refs()
assert set(["container", "sub_container", "mixin_container"]) == s.properties_containers()
assert set(["num", "container", "child", "mixin_num", "mixin_container", "mixin_child", "sub_num", "sub_container", "sub_child"]) == s.properties()
assert set(
["num", "container", "child", "mixin_num", "mixin_container", "mixin_child", "sub_num", "sub_container", "sub_child"]
) == s.properties(with_bases=True)
assert set(["sub_num", "sub_container", "sub_child"]) == s.properties(with_bases=False)
# verify caching
assert s.properties_with_refs() is s.properties_with_refs()
assert s.properties_containers() is s.properties_containers()
assert s.properties() is s.properties()
assert s.properties(with_bases=True) is s.properties(with_bases=True)
# this one isn't cached because we store it as a list __properties__ and wrap it
# in a new set every time
#assert s.properties(with_bases=False) is s.properties(with_bases=False)
def test_accurate_dataspecs(self):
0
View Source File : test_properties.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_HasProps_equals():
class Foo(HasProps):
x = Int(12)
y = String("hello")
z = List(Int, [1,2,3])
class FooUnrelated(HasProps):
x = Int(12)
y = String("hello")
z = List(Int, [1,2,3])
v = Foo().equals(Foo())
assert v is True
v = Foo(x=1).equals(Foo(x=1))
assert v is True
v = Foo(x=1).equals(Foo(x=2))
assert v is False
v = Foo(x=1).equals(1)
assert v is False
v = Foo().equals(FooUnrelated())
assert v is False
def test_HasProps_clone():
0
View Source File : test_objects.py
License : MIT License
Project Creator : rthorst
License : MIT License
Project Creator : rthorst
def test_references_in_containers(self):
from bokeh.core.properties import Int, String, Instance, List, Tuple, Dict
# XXX: can't use Y, because of:
#
# Warning: Duplicate __view_model__ declaration of 'Y' for class Y.
# Previous definition: < class 'bokeh.tests.test_objects.Y'>
class U(self.pObjectClass):
a = Int
class V(self.pObjectClass):
u1 = Instance(U)
u2 = List(Instance(U))
u3 = Tuple(Int, Instance(U))
u4 = Dict(String, Instance(U))
u5 = Dict(String, List(Instance(U)))
u1, u2, u3, u4, u5 = U(a=1), U(a=2), U(a=3), U(a=4), U(a=5)
v = V(u1=u1, u2=[u2], u3=(3, u3), u4={"4": u4}, u5={"5": [u5]})
assert v.references() == set([v, u1, u2, u3, u4, u5])
def test_to_json(self):