diff --git a/contrib/pyln-proto/pyln/proto/message/array_types.py b/contrib/pyln-proto/pyln/proto/message/array_types.py index 5e59709c8..8aeebec45 100644 --- a/contrib/pyln-proto/pyln/proto/message/array_types.py +++ b/contrib/pyln-proto/pyln/proto/message/array_types.py @@ -1,11 +1,11 @@ -#! /usr/bin/python3 from .fundamental_types import FieldType, IntegerType, split_field class ArrayType(FieldType): - """Abstract class for the different kinds of arrays: these are not in -the namespace, but generated when a message says it wants an array of -some type. + """Abstract class for the different kinds of arrays. + +These are not in the namespace, but generated when a message says it +wants an array of some type. """ def __init__(self, outer, name, elemtype): diff --git a/contrib/pyln-proto/pyln/proto/message/fundamental_types.py b/contrib/pyln-proto/pyln/proto/message/fundamental_types.py index 7fee6cae9..e4cd53d40 100644 --- a/contrib/pyln-proto/pyln/proto/message/fundamental_types.py +++ b/contrib/pyln-proto/pyln/proto/message/fundamental_types.py @@ -1,4 +1,3 @@ -#! /usr/bin/python3 import struct @@ -42,7 +41,7 @@ These are further specialized. return self.name def __repr__(self): - return self.name + return 'FieldType({})'.format(self.name) class IntegerType(FieldType): diff --git a/contrib/pyln-proto/pyln/proto/message/message.py b/contrib/pyln-proto/pyln/proto/message/message.py index 7d9c512c7..0f7a00f9a 100644 --- a/contrib/pyln-proto/pyln/proto/message/message.py +++ b/contrib/pyln-proto/pyln/proto/message/message.py @@ -1,4 +1,3 @@ -#! /usr/bin/python3 import struct from .fundamental_types import fundamental_types, BigSizeType, split_field from .array_types import ( diff --git a/contrib/pyln-proto/tests/test_array_types.py b/contrib/pyln-proto/tests/test_array_types.py index e2c9247ed..6ec80c4f2 100644 --- a/contrib/pyln-proto/tests/test_array_types.py +++ b/contrib/pyln-proto/tests/test_array_types.py @@ -18,23 +18,23 @@ def test_sized_array(): def __init__(self, name): self.name = name - for test in [[SizedArrayType(dummy("test1"), "test_arr", byte, 4), - "00010203", - bytes([0, 1, 2, 3])], - [SizedArrayType(dummy("test2"), "test_arr", u16, 4), - "[0,1,2,256]", - bytes([0, 0, 0, 1, 0, 2, 1, 0])], - [SizedArrayType(dummy("test3"), "test_arr", scid, 4), - "[1x2x3,4x5x6,7x8x9,10x11x12]", - bytes([0, 0, 1, 0, 0, 2, 0, 3] - + [0, 0, 4, 0, 0, 5, 0, 6] - + [0, 0, 7, 0, 0, 8, 0, 9] - + [0, 0, 10, 0, 0, 11, 0, 12])]]: - v, _ = test[0].val_from_str(test[1]) - assert test[0].val_to_str(v, None) == test[1] - v2, _ = test[0].val_from_bin(test[2], None) + for arrtype, s, b in [[SizedArrayType(dummy("test1"), "test_arr", byte, 4), + "00010203", + bytes([0, 1, 2, 3])], + [SizedArrayType(dummy("test2"), "test_arr", u16, 4), + "[0,1,2,256]", + bytes([0, 0, 0, 1, 0, 2, 1, 0])], + [SizedArrayType(dummy("test3"), "test_arr", scid, 4), + "[1x2x3,4x5x6,7x8x9,10x11x12]", + bytes([0, 0, 1, 0, 0, 2, 0, 3] + + [0, 0, 4, 0, 0, 5, 0, 6] + + [0, 0, 7, 0, 0, 8, 0, 9] + + [0, 0, 10, 0, 0, 11, 0, 12])]]: + v, _ = arrtype.val_from_str(s) + assert arrtype.val_to_str(v, None) == s + v2, _ = arrtype.val_from_bin(b, None) assert v2 == v - assert test[0].val_to_bin(v, None) == test[2] + assert arrtype.val_to_bin(v, None) == b def test_ellipsis_array():