當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。