当前位置: 首页>>代码示例>>Python>>正文


Python traitlets.TraitError方法代码示例

本文整理汇总了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 
开发者ID:K3D-tools,项目名称:K3D-jupyter,代码行数:23,代码来源:stl.py

示例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) 
开发者ID:sinhrks,项目名称:cesiumpy,代码行数:24,代码来源:test_color.py

示例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)) 
开发者ID:sinhrks,项目名称:cesiumpy,代码行数:20,代码来源:test_entity.py

示例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) 
开发者ID:sinhrks,项目名称:cesiumpy,代码行数:20,代码来源:test_entity.py

示例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) 
开发者ID:sinhrks,项目名称:cesiumpy,代码行数:18,代码来源:test_entity.py

示例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) 
开发者ID:sinhrks,项目名称:cesiumpy,代码行数:20,代码来源:test_entity.py

示例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) 
开发者ID:jupyter-widgets,项目名称:traittypes,代码行数:19,代码来源:traittypes.py

示例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)
                ) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:20,代码来源:trait_types.py

示例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" 
开发者ID:cta-observatory,项目名称:ctapipe,代码行数:21,代码来源:test_tool.py

示例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) 
开发者ID:jupyter,项目名称:telemetry,代码行数:7,代码来源:test_eventlog.py

示例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
        ) 
开发者ID:jupyter,项目名称:telemetry,代码行数:9,代码来源:test_traits.py

示例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
        ) 
开发者ID:jupyter,项目名称:telemetry,代码行数:11,代码来源:test_traits.py

示例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__)
        ) 
开发者ID:jupyter,项目名称:telemetry,代码行数:8,代码来源:traits.py

示例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'] 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:13,代码来源:generator.py

示例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'] 
开发者ID:power-system-simulation-toolbox,项目名称:psst,代码行数:12,代码来源:generator.py


注:本文中的traitlets.TraitError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。