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


Python Serializer._hash_name方法代码示例

本文整理汇总了Python中serializer.Serializer._hash_name方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer._hash_name方法的具体用法?Python Serializer._hash_name怎么用?Python Serializer._hash_name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在serializer.Serializer的用法示例。


在下文中一共展示了Serializer._hash_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestSerialize

# 需要导入模块: from serializer import Serializer [as 别名]
# 或者: from serializer.Serializer import _hash_name [as 别名]

#.........这里部分代码省略.........

    def test_explicit_call(self):
        enc = self.s.serialize("test.Test", *self.blank_args)

        def f(obj):
            self.assertTrue(obj.IsInitialized())
            for (_, value) in obj.ListFields():
                self.assertIn(value, self.blank_args)

        self.s.add_handler("Test", f)
        self.s.unserialize(enc)

    def test_negative_values(self):
        enc = self.s.serialize("Test", *self.neg_args)

        def f(obj):
            self.assertTrue(obj.IsInitialized())
            for (_, value) in obj.ListFields():
                self.assertIn(value, self.neg_args)

        self.s.add_handler("Test", f)
        self.s.unserialize(enc)

    def test_illegal_length_option(self):
        for args in self.illegal_len_args:
            with self.assertRaises(FieldLengthUnsupportedException):
                self.s.serialize("Test", *args)

    def test_too_long_option(self):
        for args in self.too_long_args:
            with self.assertRaises(FieldTooLongException):
                self.s.serialize("Test", *args)

    def test_unknown_message(self):
        with self.assertRaises(UnknownMessageException):
            self.s.serialize("Unknown")

    def test_unknown_message_explicit(self):
        with self.assertRaises(UnknownMessageException):
            self.s.serialize("test.Unknown")

    def test_unknown_message_explicit2(self):
        with self.assertRaises(UnknownMessageException):
            self.s.serialize("t.Unknown")

    def test_incomplete_definition_empty(self):
        with self.assertRaises(FieldNotDefinedException):
            self.s.serialize("Test")

    def test_incomplete_definition_unnamed(self):
        with self.assertRaises(FieldNotDefinedException):
            self.s.serialize("Test", 0)

    def test_incomplete_definition_named(self):
        with self.assertRaises(FieldNotDefinedException):
            self.s.serialize("Test", boolnolen = 0)

    def test_incomplete_definition_hybrid(self):
        with self.assertRaises(FieldNotDefinedException):
            self.s.serialize("Test", 0, boolnolen = 0)

    def test_wrong_type(self):
        args = self.blank_args[:]
        args[0] = ""
        with self.assertRaises(FieldWrongTypeException):
            self.s.serialize("Test", *args)

    def test_wrong_type_value(self):
        args = self.blank_args[:]
        args[5] = 9999999999999999
        with self.assertRaises(FieldWrongTypeException):
            self.s.serialize("Test", *args)

    def test_hash_name(self):
        name = "test"
        for i in range(1,9):
            self.assertEqual(len(self.s._hash_name(name, i)),
                                i)

    def test_reload_definitions(self):
        class T(logging.Filter):
            def filter(self, record):
                self.called = True
                return 0
        filter = T()
        filter.called = False
        logging.getLogger().addFilter(filter)

        self.assertIn("'test_pb2Test\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", self.s.messages)
        self.s.load_definitions()
        self.assertIn("'test_pb2Test\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00'", self.s.messages)
        self.assertTrue(filter.called)

        logging.getLogger().removeFilter(filter)

    def test_wrong_type_value_check(self):
        args = self.blank_args[:]
        args[1] = 1.10
        with self.assertRaises(FieldLengthUnsupportedException):
            self.s.serialize("Test", *args)
开发者ID:qstokkink,项目名称:TriblerProtobufSerialization,代码行数:104,代码来源:test_serialize.py


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