1 from ctypescrypto.bio import Membio
9 class TestRead(unittest.TestCase):
10 def test_readshortstr(self):
11 s=b"A quick brown fox jumps over a lazy dog"
14 self.assertEqual(data,s)
16 self.assertEqual(data2,b"")
18 def test_readwithlen(self):
19 s=b"A quick brown fox jumps over a lazy dog"
22 self.assertEqual(data,s)
24 self.assertEqual(data2,b"")
25 def test_readwrongtype(self):
26 s=b"A quick brown fox jumps over a lazy dog"
28 with self.assertRaises(TypeError):
31 s=b"A quick brown fox jumps over a lazy dog"
37 self.assertEqual(data,data2)
38 self.assertEqual(data,s)
39 def test_readlongstr(self):
40 poem=b'''Eyes of grey--a sodden quay,
41 Driving rain and falling tears,
42 As the steamer wears to sea
43 In a parting storm of cheers.
45 Sing, for Faith and Hope are high--
46 None so true as you and I--
47 Sing the Lovers' Litany:
48 "Love like ours can never die!"
50 Eyes of black--a throbbing keel,
51 Milky foam to left and right;
52 Whispered converse near the wheel
53 In the brilliant tropic night.
55 Cross that rules the Southern Sky!
56 Stars that sweep and wheel and fly,
57 Hear the Lovers' Litany:
58 Love like ours can never die!"
60 Eyes of brown--a dusty plain
61 Split and parched with heat of June,
62 Flying hoof and tightened rein,
63 Hearts that beat the old, old tune.
65 Side by side the horses fly,
66 Frame we now the old reply
67 Of the Lovers' Litany:
68 "Love like ours can never die!"
70 Eyes of blue--the Simla Hills
71 Silvered with the moonlight hoar;
72 Pleading of the waltz that thrills,
73 Dies and echoes round Benmore.
75 "Mabel," "Officers," "Goodbye,"
76 Glamour, wine, and witchery--
77 On my soul's sincerity,
78 "Love like ours can never die!"
80 Maidens of your charity,
81 Pity my most luckless state.
82 Four times Cupid's debtor I--
83 Bankrupt in quadruplicate.
85 Yet, despite this evil case,
86 And a maiden showed me grace,
87 Four-and-forty times would I
88 Sing the Lovers' Litany:
89 "Love like ours can never die!"'''
92 self.assertEqual(data,poem)
94 def test_readparts(self):
95 s=b"A quick brown fox jumps over the lazy dog"
98 self.assertEqual(a,s[0:10])
100 self.assertEqual(b,s[10:19])
102 self.assertEqual(c,s[19:])
104 self.assertEqual(d,b"")
106 class TestWrite(unittest.TestCase):
107 def test_write(self):
109 b.write(b"A quick brown ")
110 b.write(b"fox jumps over ")
111 b.write(b"the lazy dog.")
112 self.assertEqual(str(b),"A quick brown fox jumps over the lazy dog.")
114 def test_unicode(self):
116 s=b'\xd0\xba\xd0\xb0\xd0\xba \xd1\x8d\xd1\x82\xd0\xbe \xd0\xbf\xd0\xbe-\xd1\x80\xd1\x83\xd1\x81\xd1\x81\xd0\xba\xd0\xb8'
118 self.assertEqual(unicode(b),u'\u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438')
119 def test_unicode2(self):
121 u=u'\u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438'
123 self.assertEqual(unicode(b),u)
124 if __name__ == '__main__':