本文整理汇总了Python中traitlets.TraitError方法的典型用法代码示例。如果您正苦于以下问题:Python traitlets.TraitError方法的具体用法?Python traitlets.TraitError怎么用?Python traitlets.TraitError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类traitlets
的用法示例。
在下文中一共展示了traitlets.TraitError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def validate(self, owner, stl):
stl = super(BinaryStlData, self).validate(owner, stl)
if len(stl) < self.HEADER + self.COUNT_SIZE:
raise TraitError(
'Given bytestring is too short ({}) for Binary STL data.'
.format(len(stl))
)
(num_facets,) = struct.unpack('<I', stl[self.HEADER : self.HEADER + self.COUNT_SIZE])
expected_size = self.HEADER + self.COUNT_SIZE + num_facets * self.FACET_SIZE
if len(stl) != expected_size:
raise TraitError(
'Given bytestring has wrong length ({}) for Binary STL data. '
'For {} facets {} bytes were expected.'
.format(len(stl), num_facets, expected_size)
)
return stl
示例2: test_alpha
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_alpha(self):
aqua = cesiumpy.color.AQUA
res = aqua.set_alpha(0.3)
exp = "Cesium.Color.AQUA.withAlpha(0.3)"
self.assertEqual(res.script, exp)
res = aqua.withAlpha(0.3)
exp = "Cesium.Color.AQUA.withAlpha(0.3)"
self.assertEqual(res.script, exp)
res = aqua.withAlpha(1.0)
exp = "Cesium.Color.AQUA.withAlpha(1.0)"
self.assertEqual(res.script, exp)
res = aqua.withAlpha(0.0)
exp = "Cesium.Color.AQUA.withAlpha(0.0)"
self.assertEqual(res.script, exp)
msg = "The value of the 'alpha' trait of a ColorConstant instance should"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
aqua.withAlpha(1.1)
示例3: test_ellipsoid
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_ellipsoid(self):
e = cesiumpy.Ellipsoid(position=(-70, 40, 0), radii=(20, 30, 40), material=cesiumpy.color.GREEN)
exp = "{position : Cesium.Cartesian3.fromDegrees(-70.0, 40.0, 0.0), ellipsoid : {radii : new Cesium.Cartesian3(20.0, 30.0, 40.0), material : Cesium.Color.GREEN}}"
self.assertEqual(e.script, exp)
e = e.copy()
self.assertEqual(e.script, exp)
e = cesiumpy.Ellipsoid(position=(-70, 40, 0), radii=(20, 30, 40), material=cesiumpy.color.RED, name='XXX')
exp = '{name : "XXX", position : Cesium.Cartesian3.fromDegrees(-70.0, 40.0, 0.0), ellipsoid : {radii : new Cesium.Cartesian3(20.0, 30.0, 40.0), material : Cesium.Color.RED}}'
self.assertEqual(e.script, exp)
e = e.copy()
self.assertEqual(e.script, exp)
msg = "The 'radii' trait of an Ellipsoid instance must be a Cartesian3"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
cesiumpy.Ellipsoid(position=(-70, 40, 0), radii=(20, 30, 40, 10, 50))
示例4: test_material_property
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_material_property(self):
msg = "The 'material' trait of a Box instance must be a Material or None"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
cesiumpy.Box(position=[-120, 40, 0], dimensions=(10, 20, 30),
material=1)
b = cesiumpy.Box(position=[-120, 40, 0], dimensions=(10, 20, 30),
material='red')
exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(10.0, 20.0, 30.0), material : Cesium.Color.RED}}"""
self.assertEqual(b.script, exp)
msg = "The 'material' trait of a Box instance must be a Material or None"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
b.material = 1
b.material = 'blue'
exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(10.0, 20.0, 30.0), material : Cesium.Color.BLUE}}"""
self.assertEqual(b.script, exp)
示例5: test_color_property
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_color_property(self):
msg = "The 'color' trait of a Point instance must be a Color or None"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
cesiumpy.Point(position=[-120, 40, 0], color=1)
b = cesiumpy.Point(position=[-120, 40, 0], color='red')
exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), point : {pixelSize : 10.0, color : Cesium.Color.RED}}"""
self.assertEqual(b.script, exp)
msg = "The 'color' trait of a Point instance must be a Color or None"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
b.color = 1
b.color = 'blue'
exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), point : {pixelSize : 10.0, color : Cesium.Color.BLUE}}"""
self.assertEqual(b.script, exp)
示例6: test_outlineColor_property
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_outlineColor_property(self):
msg = "The 'outlineColor' trait of a Box instance must be a Color or None"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
cesiumpy.Box(position=[-120, 40, 0], dimensions=(10, 20, 30),
outlineColor=1)
b = cesiumpy.Box(position=[-120, 40, 0], dimensions=(10, 20, 30),
outlineColor='red')
exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(10.0, 20.0, 30.0), outlineColor : Cesium.Color.RED}}"""
self.assertEqual(b.script, exp)
msg = "The 'outlineColor' trait of a Box instance must be a Color or None"
with nose.tools.assert_raises_regexp(traitlets.TraitError, msg):
b.outlineColor = 1
b.outlineColor = 'blue'
exp = """{position : Cesium.Cartesian3.fromDegrees(-120.0, 40.0, 0.0), box : {dimensions : new Cesium.Cartesian3(10.0, 20.0, 30.0), outlineColor : Cesium.Color.BLUE}}"""
self.assertEqual(b.script, exp)
示例7: validate
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def validate(self, obj, value):
if value is None and not self.allow_none:
self.error(obj, value)
if value is None or value is Undefined:
return super(Array, self).validate(obj, value)
try:
r = np.asarray(value, dtype=self.dtype)
if isinstance(value, np.ndarray) and r is not value:
warnings.warn(
'Given trait value dtype "%s" does not match required type "%s". '
'A coerced copy has been created.' % (
np.dtype(value.dtype).name,
np.dtype(self.dtype).name))
value = r
except (ValueError, TypeError) as e:
raise TraitError(e)
return super(Array, self).validate(obj, value)
示例8: validate
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def validate(self, obj, value):
value = super(NumberFormat, self).validate(obj, value)
re_match = _number_format_re.match(value)
if re_match is None:
self.error(obj, value)
else:
format_type = re_match.group(9)
if format_type is None:
return value
elif format_type in _number_format_types:
return value
else:
raise traitlets.TraitError(
'The type specifier of a NumberFormat trait must '
'be one of {}, but a value of \'{}\' was '
'specified.'.format(
list(_number_format_types), format_type)
)
示例9: test_tool_simple
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_tool_simple():
"""test the very basic functionality of a Tool"""
class MyTool(Tool):
description = "test"
userparam = Float(5.0, help="parameter").tag(config=True)
tool = MyTool()
tool.userparam = 1.0
tool.log_level = "DEBUG"
tool.log.info("test")
with pytest.raises(SystemExit) as exc:
tool.run([])
assert exc.value.code == 0
# test parameters changes:
tool.userparam = 4.0
with pytest.raises(TraitError):
tool.userparam = "badvalue"
示例10: test_bad_config_file
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_bad_config_file(tmp_path):
cfg = get_config_from_file(tmp_path, BAD_CONFIG)
with pytest.raises(TraitError):
e = EventLog(config=cfg)
示例11: test_bad_handlers_values
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_bad_handlers_values():
handlers = [0, 1]
with pytest.raises(TraitError):
HasHandlers(
handlers=handlers
)
示例12: test_mixed_handlers_values
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def test_mixed_handlers_values():
handlers = [
logging.NullHandler(),
1
]
with pytest.raises(TraitError):
HasHandlers(
handlers=handlers
)
示例13: element_error
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def element_error(self, obj):
raise TraitError(
"Elements in the '{}' trait of an {} instance "
"must be Python `logging` handler instances."
.format(self.name, obj.__class__.__name__)
)
示例14: _validate_max_length
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def _validate_max_length(self, proposal):
if not len(proposal['value']) == self._npoints:
raise t.TraitError(
'len({class_name}().{trait_name}) must be equal to {class_name}().nsegments + 1. Proposed {trait_name} is {proposal}'.format(
class_name=proposal['owner'].__class__.__name__,
trait_name=proposal['trait'].name,
proposal=proposal['value']
)
)
return proposal['value']
示例15: _less_than_maximum_real_power_check
# 需要导入模块: import traitlets [as 别名]
# 或者: from traitlets import TraitError [as 别名]
def _less_than_maximum_real_power_check(self, proposal):
if not proposal['value'] <= self.maximum_real_power:
raise t.TraitError(
'{class_name}().{trait_name} must be a less than or equal to {class_name}().maximum_real_power.'.format(
class_name=proposal['owner'].__class__.__name__,
trait_name=proposal['trait'].name
)
)
else:
return proposal['value']