Exemplo n.º 1
0
        class V:
            other_typ = T.Int16.transform(lambda _, v: v + 5, lambda _, v: v - 5)

            two_typ = T.String(20 * 8).allow_callable()

            thing_typ = T.Reserved(lambda p: p.other * 8)

            @hp.memoized_property
            def G1(s):
                class G1(dictobj.PacketSpec):
                    fields = [("other", s.other_typ), ("thing", s.thing_typ)]

                return G1

            @hp.memoized_property
            def P(s):
                class P(dictobj.PacketSpec):
                    fields = [("one", T.Bool), ("two", s.two_typ), ("g1", s.G1)]

                return P
Exemplo n.º 2
0
        group = mock.Mock(name="group")

        info = FieldInfo(name, typ, val, size_bits, group)

        assert info.name is name
        assert info.typ is typ
        assert info.val is val
        assert info.size_bits is size_bits
        assert info.group is group

    describe "value":
        it "returns value as is", info, val:
            assert info.value is val

        it "returns value as 0 bits if our typ is Reserved and val is NotSpecified", info:
            info.typ = T.Reserved(8)
            info.size_bits = 8
            info.val = sb.NotSpecified
            assert info.value == bitarray("0" * 8)

        it "returns value as is if typ is Reserved but value is not NotSpecified", info, val:
            info.typ = T.Reserved(8)
            assert info.value == val

    describe "to_sized_bitarray":
        it "removes from the right if no left_cut", info:
            info.typ.left_cut = False
            info.size_bits = 3

            to_bitarray = mock.Mock(name="to_bitarray")
            to_bitarray.return_value = bitarray("110000", endian="little")