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


Python attr.astuple方法代码示例

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


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

示例1: test_simple_example

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_simple_example(self):
        t = tskit.NodeTable()
        t.add_row(flags=0, time=1, population=2, individual=0, metadata=b"123")
        t.add_row(flags=1, time=2, population=3, individual=1, metadata=b"\xf0")
        s = str(t)
        self.assertGreater(len(s), 0)
        self.assertEqual(len(t), 2)
        self.assertEqual(attr.astuple(t[0]), (0, 1, 2, 0, b"123"))
        self.assertEqual(attr.astuple(t[1]), (1, 2, 3, 1, b"\xf0"))
        self.assertEqual(t[0].flags, 0)
        self.assertEqual(t[0].time, 1)
        self.assertEqual(t[0].population, 2)
        self.assertEqual(t[0].individual, 0)
        self.assertEqual(t[0].metadata, b"123")
        self.assertEqual(t[0], t[-2])
        self.assertEqual(t[1], t[-1])
        self.assertRaises(IndexError, t.__getitem__, -3) 
开发者ID:tskit-dev,项目名称:tskit,代码行数:19,代码来源:test_tables.py

示例2: test_recurse_property

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_recurse_property(self, cls, tuple_class):
        """
        Property tests for recursive astuple.
        """
        obj = cls()
        obj_tuple = astuple(obj, tuple_factory=tuple_class)

        def assert_proper_tuple_class(obj, obj_tuple):
            assert isinstance(obj_tuple, tuple_class)
            for index, field in enumerate(fields(obj.__class__)):
                field_val = getattr(obj, field.name)
                if has(field_val.__class__):
                    # This field holds a class, recurse the assertions.
                    assert_proper_tuple_class(field_val, obj_tuple[index])

        assert_proper_tuple_class(obj, obj_tuple) 
开发者ID:python-attrs,项目名称:attrs,代码行数:18,代码来源:test_funcs.py

示例3: decode_mnemonic

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def decode_mnemonic(mnemonic):
    return list(attr.astuple(Share.from_mnemonic(mnemonic))) 
开发者ID:trezor,项目名称:python-shamir-mnemonic,代码行数:4,代码来源:generate_vectors.py

示例4: pattern2loc

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def pattern2loc(pattern_list):
    results = []
    dupset = set()
    proc = lambda decl: lsp.Location(uri=path2uri(decl.path), range=decl.range)
    for x in pattern_list:
        x = proc(x)
        key = attr.astuple(x)
        if key not in dupset:
            dupset.add(key)
            results.append(attr.asdict(x))
    return results 
开发者ID:tqchen,项目名称:ffi-navigator,代码行数:13,代码来源:langserver.py

示例5: test_constructor_with_state_only

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_constructor_with_state_only(self):
    ip = measured_process.MeasuredProcess(
        _build_initialize_comp(0), count_int32)

    state = ip.initialize()
    iterations = 10
    for _ in range(iterations):
      state, result, measurements = attr.astuple(ip.next(state))
      self.assertLen(result, 0)
      self.assertLen(measurements, 0)
    self.assertEqual(state, iterations) 
开发者ID:tensorflow,项目名称:federated,代码行数:13,代码来源:measured_process_test.py

示例6: to_jsonable

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def to_jsonable(self):
    return attr.astuple(self)

  # Allow HistoryItems to act like tuples for unpacking. 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:6,代码来源:core.py

示例7: __iter__

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def __iter__(self):
    return iter(attr.astuple(self, recurse=False)) 
开发者ID:google,项目名称:ml-fairness-gym,代码行数:4,代码来源:core.py

示例8: __eq__

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def __eq__(self, other: "BaseSignedData") -> bool:
        if isinstance(other, type(self)):
            return attr.astuple(self).__eq__(attr.astuple(other))
        return NotImplemented 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:6,代码来源:base.py

示例9: __eq__

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def __eq__(self, other: object) -> bool:
        if isinstance(other, int):
            return self.start.__eq__(other)
        if isinstance(other, Chunk):
            return attr.astuple(self).__eq__(attr.astuple(other))
        raise TypeError

    # Properties 
开发者ID:Scille,项目名称:parsec-cloud,代码行数:10,代码来源:manifest.py

示例10: test_shallow

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_shallow(self, C, tuple_factory):
        """
        Shallow astuple returns correct dict.
        """
        assert tuple_factory([1, 2]) == astuple(
            C(x=1, y=2), False, tuple_factory=tuple_factory
        ) 
开发者ID:python-attrs,项目名称:attrs,代码行数:9,代码来源:test_funcs.py

示例11: test_recurse

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_recurse(self, C, tuple_factory):
        """
        Deep astuple returns correct tuple.
        """
        assert tuple_factory(
            [tuple_factory([1, 2]), tuple_factory([3, 4])]
        ) == astuple(C(C(1, 2), C(3, 4)), tuple_factory=tuple_factory) 
开发者ID:python-attrs,项目名称:attrs,代码行数:9,代码来源:test_funcs.py

示例12: test_recurse_retain

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_recurse_retain(self, cls, tuple_class):
        """
        Property tests for asserting collection types are retained.
        """
        obj = cls()
        obj_tuple = astuple(
            obj, tuple_factory=tuple_class, retain_collection_types=True
        )

        def assert_proper_col_class(obj, obj_tuple):
            # Iterate over all attributes, and if they are lists or mappings
            # in the original, assert they are the same class in the dumped.
            for index, field in enumerate(fields(obj.__class__)):
                field_val = getattr(obj, field.name)
                if has(field_val.__class__):
                    # This field holds a class, recurse the assertions.
                    assert_proper_col_class(field_val, obj_tuple[index])
                elif isinstance(field_val, (list, tuple)):
                    # This field holds a sequence of something.
                    expected_type = type(obj_tuple[index])
                    assert type(field_val) is expected_type
                    for obj_e, obj_tuple_e in zip(field_val, obj_tuple[index]):
                        if has(obj_e.__class__):
                            assert_proper_col_class(obj_e, obj_tuple_e)
                elif isinstance(field_val, dict):
                    orig = field_val
                    tupled = obj_tuple[index]
                    assert type(orig) is type(tupled)
                    for obj_e, obj_tuple_e in zip(
                        orig.items(), tupled.items()
                    ):
                        if has(obj_e[0].__class__):  # Dict key
                            assert_proper_col_class(obj_e[0], obj_tuple_e[0])
                        if has(obj_e[1].__class__):  # Dict value
                            assert_proper_col_class(obj_e[1], obj_tuple_e[1])

        assert_proper_col_class(obj, obj_tuple) 
开发者ID:python-attrs,项目名称:attrs,代码行数:39,代码来源:test_funcs.py

示例13: test_filter

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_filter(self, C, tuple_factory):
        """
        Attributes that are supposed to be skipped are skipped.
        """
        assert tuple_factory([tuple_factory([1])]) == astuple(
            C(C(1, 2), C(3, 4)),
            filter=lambda a, v: a.name != "y",
            tuple_factory=tuple_factory,
        ) 
开发者ID:python-attrs,项目名称:attrs,代码行数:11,代码来源:test_funcs.py

示例14: test_dicts

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_dicts(self, C, tuple_factory):
        """
        If recurse is True, also recurse into dicts.
        """
        res = astuple(C(1, {"a": C(4, 5)}), tuple_factory=tuple_factory)
        assert tuple_factory([1, {"a": tuple_factory([4, 5])}]) == res
        assert isinstance(res, tuple_factory) 
开发者ID:python-attrs,项目名称:attrs,代码行数:9,代码来源:test_funcs.py

示例15: test_lists_tuples_retain_type

# 需要导入模块: import attr [as 别名]
# 或者: from attr import astuple [as 别名]
def test_lists_tuples_retain_type(self, container, C):
        """
        If recurse and retain_collection_types are True, also recurse
        into lists and do not convert them into list.
        """
        assert (1, container([(2, 3), (4, 5), "a"])) == astuple(
            C(1, container([C(2, 3), C(4, 5), "a"])),
            retain_collection_types=True,
        ) 
开发者ID:python-attrs,项目名称:attrs,代码行数:11,代码来源:test_funcs.py


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