From: Mark Wooding Date: Sun, 17 Nov 2019 23:46:49 +0000 (+0000) Subject: t/t-*.py: Use the `WriteBuffer.contents' property. X-Git-Url: https://git.distorted.org.uk/~mdw/catacomb-python/commitdiff_plain/d0cc556a1bbecb0bc2973c79e386150fb733dd8b t/t-*.py: Use the `WriteBuffer.contents' property. --- diff --git a/t/t-buffer.py b/t/t-buffer.py index 24823c6..096e35b 100644 --- a/t/t-buffer.py +++ b/t/t-buffer.py @@ -180,11 +180,10 @@ class TestWriteBuffer (U.TestCase): buf.putu8(0x00) putfn(buf, T.bytes_as_int(w, bigendp)) buf.putu8(w + 1) - me.assertEqual(C.ByteString(buf), T.span(w + 2)) - me.assertEqual(C.ByteString(putfn(C.WriteBuffer(), (1 << 8*w) - 1)), + me.assertEqual(buf.contents, T.span(w + 2)) + me.assertEqual(putfn(C.WriteBuffer(), (1 << 8*w) - 1).contents, w*C.bytes("ff")) - me.assertEqual(C.ByteString(putfn(C.WriteBuffer(), C.MP(0))), - w*C.bytes("00")) + me.assertEqual(putfn(C.WriteBuffer(), C.MP(0)).contents, w*C.bytes("00")) ## Check overflow detection. me.assertRaises((OverflowError, ValueError), @@ -196,8 +195,8 @@ class TestWriteBuffer (U.TestCase): ## Go through a number of different sizes. for n in [0, 1, 7, 8, 19, 255, 12345, 65535, 123456]: if n >= 1 << 8*w: continue - me.assertEqual(C.ByteString(putfn(C.WriteBuffer().putu8(0x00), - T.span(n)).putu8(0xff)), + me.assertEqual(putfn(C.WriteBuffer().putu8(0x00), + T.span(n)).putu8(0xff).contents, T.prep_lenseq(w, n, bigendp, True)) ## Check blocks which are too large for the length prefix. @@ -244,7 +243,7 @@ class TestWriteBuffer (U.TestCase): buf.zero(17) buf.put(T.span(23)) me.assertEqual(buf.size, 40) - me.assertEqual(C.ByteString(buf), C.ByteString.zero(17) + T.span(23)) + me.assertEqual(buf.contents, C.ByteString.zero(17) + T.span(23)) ###----- That's all, folks -------------------------------------------------- diff --git a/t/t-ec.py b/t/t-ec.py index ef80b90..870297e 100644 --- a/t/t-ec.py +++ b/t/t-ec.py @@ -194,21 +194,23 @@ class TestCurves (T.GenericTestMixin): Z1 = C.ByteString.zero(1) me.assertEqual(O.ec2osp(), Z1) me.assertEqual(E.os2ecp(Z1), (O, Z0)) - t = C.ByteString(C.WriteBuffer() - .putu8(0x04) - .put(P.ix.storeb(k.noctets)) - .put(P.iy.storeb(k.noctets))) + t = C.WriteBuffer() \ + .putu8(0x04) \ + .put(P.ix.storeb(k.noctets)) \ + .put(P.iy.storeb(k.noctets)) \ + .contents me.assertEqual(P.ec2osp(), t) - me.assertEqual(C.ByteString(C.WriteBuffer().putecptraw(P)), t) + me.assertEqual(C.WriteBuffer().putecptraw(P).contents, t) me.assertEqual(E.os2ecp(t), (P, Z0)) me.assertEqual(C.ReadBuffer(t).getecptraw(E), P) if isinstance(k, C.PrimeField): ybit = int(P.iy&1) else: try: ybit = int((P.y/P.x).value&C.GF(1)) except ZeroDivisionError: ybit = 0 - t = C.ByteString(C.WriteBuffer() - .putu8(0x02 | ybit) - .put(P.ix.storeb(k.noctets))) + t = C.WriteBuffer() \ + .putu8(0x02 | ybit) \ + .put(P.ix.storeb(k.noctets)) \ + .contents me.assertEqual(P.ec2osp(C.EC_LSB), t) me.assertEqual(E.os2ecp(t, C.EC_LSB), (P, Z0)) diff --git a/t/t-group.py b/t/t-group.py index 203ca16..e91de94 100644 --- a/t/t-group.py +++ b/t/t-group.py @@ -111,14 +111,14 @@ class TestGroups (T.GenericTestMixin): ## Encoding. t = y.tobuf() - me.assertEqual(t, C.ByteString(C.WriteBuffer().putmp(i))) + me.assertEqual(t, C.WriteBuffer().putmp(i).contents) me.assertEqual(G.frombuf(t)[0], y) me.assertEqual(id.tobuf(), C.bytes("000101")) t = y.toraw() me.assertEqual(t, i.storeb(G.noctets)) me.assertEqual(G.fromraw(t)[0], y) me.assertEqual(id.toraw(), - C.ByteString(C.WriteBuffer().zero(G.noctets - 1).putu8(1))) + C.WriteBuffer().zero(G.noctets - 1).putu8(1).contents) ## String conversion. ystr = str(y)