def test_Property_wrap() -> None: types = [ Bool(), Int(), Float(), Complex(), String(), Enum("Some", "a", "b"), Color(), Regex("^$"), Seq(Any), Tuple(Any, Any), Instance(_TestModel), Any(), Interval(Float, 0, 1), Either(Int, String), DashPattern(), Size(), Percent(), Angle(), MinMaxBounds(), ] for x in types: for y in (0, 1, 2.3, "foo", None, (), [], {}): r = x.wrap(y) assert r == y assert isinstance(r, type(y))
class FixedZoomOutTool(Action): __implementation__ = "fixedZoomOutTool.ts" dimensions = Enum(Dimensions, default="both") factor = Percent(default=0.1)
class BinnedColorMapper(ColorMapper): """ Map integers to the palette bin. """ __js_implementation__ = 'binned_color_mapper.coffee' alpha = Percent(default=1.0, help=""" The alpha (0.0 to 1.0) to apply to all colors. """)
def test_Percent(self, detail): p = Percent() with pytest.raises(ValueError) as e: p.validate(10, detail) assert str(e).endswith("ValueError") == (not detail)
def test_Percent(self): p = Percent() with pytest.raises(ValueError) as e: p.validate(10) assert not str(e).endswith("ValueError")
def test_Percent(self, detail) -> None: p = Percent() with pytest.raises(ValueError) as e: p.validate(10, detail) assert (str(e.value) == "") == (not detail)
def test_Percent(self) -> None: p = Percent() with pytest.raises(ValueError) as e: p.validate(10) assert matches(str(e.value), r"expected a value in range \[0, 1\], got 10")
or k.endswith('_color')) and not isinstance(v, (dict, dim)): with abbreviated_exception(): v = COLOR_ALIASES.get(v, v) if isinstance(v, tuple): with abbreviated_exception(): v = rgb2hex(v) new_properties[k] = v else: new_properties[k] = v new_properties.pop('cmap', None) return new_properties # Validation alpha = Percent() angle = Angle() color = Color() dash_pattern = DashPattern() font_size = FontSize() marker = MarkerType() size = Size() validators = { 'angle': angle.is_valid, 'alpha': alpha.is_valid, 'color': lambda x: (color.is_valid(x) or (isinstance(x, basestring) and RGB_HEX_REGEX.match(x))),
def test_Percent(self, detail): p = Percent() with pytest.raises(ValueError) as e: p.validate(10, detail) assert str(e).endswith("ValueError") == (not detail)
def test_Percent(self): p = Percent() with pytest.raises(ValueError) as e: p.validate(10) assert not str(e).endswith("ValueError")