#(c):Benja Fallenstein """ Tests for verbatim impls of HeaderLines822: those implementations which are initialized to empty and which add the lines exactly as specified, in that order. """ import java, gzz Bos = java.io.ByteArrayOutputStream def mkString(s): return str(java.lang.String(s)) def testVerbatimHeaderLines(): h = Class() assert h.getLines().isEmpty() bos = Bos() h.writeTo(bos); bos.close() #print mkString(bos.toByteArray()) assert mkString(bos.toByteArray()) == "\r\n" h.add("foo", "bar") h.add("FroB-", "blazE") assert list(h.getLines()) == ['foo: bar', 'FroB-: blazE'] bos = Bos() h.writeTo(bos); bos.close() assert mkString(bos.toByteArray()) == ( "foo: bar\r\n" "FroB-: blazE\r\n" "\r\n") h.add("blE-h", "BaRR") h2 = Class(h) h2.add("Beh", "Bieh") assert list(h.getLines()) == ['foo: bar', 'FroB-: blazE', 'blE-h: BaRR'] assert list(h2.getLines()) == ['foo: bar', 'FroB-: blazE', 'blE-h: BaRR', 'Beh: Bieh'] bos = Bos() h.writeTo(bos); bos.close() assert mkString(bos.toByteArray()) == ( "foo: bar\r\n" "FroB-: blazE\r\n" "blE-h: BaRR\r\n" "\r\n") bos = Bos() h2.writeTo(bos); bos.close() assert mkString(bos.toByteArray()) == ( "foo: bar\r\n" "FroB-: blazE\r\n" "blE-h: BaRR\r\n" "Beh: Bieh\r\n" "\r\n")