t/t-*.py: Use the `WriteBuffer.contents' property.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 17 Nov 2019 23:46:49 +0000 (23:46 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 27 Nov 2019 15:11:29 +0000 (15:11 +0000)
t/t-buffer.py
t/t-ec.py
t/t-group.py

index 24823c6..096e35b 100644 (file)
@@ -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 --------------------------------------------------
 
index ef80b90..870297e 100644 (file)
--- 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))
 
index 203ca16..e91de94 100644 (file)
@@ -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)