]> www.wagner.pp.ru Git - oss/ctypescrypto.git/blob - tests/testbio.py
1bd2e1f1bf68b068e04b3f4fd8450c12e70741e7
[oss/ctypescrypto.git] / tests / testbio.py
1 from ctypescrypto.bio import Membio
2 import unittest
3
4 class TestRead(unittest.TestCase):
5         def test_readshortstr(self):
6                 s="A quick brown fox jumps over a lazy dog"
7                 bio=Membio(s)
8                 data=bio.read()
9                 del bio
10                 self.assertEqual(data,s)
11         def test_reset(self):
12                 s="A quick brown fox jumps over a lazy dog"
13                 bio=Membio(s)
14                 data=bio.read()
15                 bio.reset()
16                 data2=bio.read()
17                 del bio
18                 self.assertEqual(data,data2)
19                 self.assertEqual(data,s)
20         def test_readlongstr(self):
21                 poem='''Eyes of grey--a sodden quay,
22 Driving rain and falling tears,
23 As the steamer wears to sea
24 In a parting storm of cheers.
25
26 Sing, for Faith and Hope are high--
27 None so true as you and I--
28 Sing the Lovers' Litany:
29 "Love like ours can never die!"
30
31 Eyes of black--a throbbing keel,
32 Milky foam to left and right;
33 Whispered converse near the wheel
34 In the brilliant tropic night.
35
36 Cross that rules the Southern Sky!
37 Stars that sweep and wheel and fly,
38 Hear the Lovers' Litany:
39 Love like ours can never die!"
40
41 Eyes of brown--a dusty plain
42 Split and parched with heat of June,
43 Flying hoof and tightened rein,
44 Hearts that beat the old, old tune.
45
46 Side by side the horses fly,
47 Frame we now the old reply
48 Of the Lovers' Litany:
49 "Love like ours can never die!"
50
51 Eyes of blue--the Simla Hills
52 Silvered with the moonlight hoar;
53 Pleading of the waltz that thrills,
54 Dies and echoes round Benmore.
55
56 "Mabel," "Officers," "Goodbye,"
57 Glamour, wine, and witchery--
58 On my soul's sincerity,
59 "Love like ours can never die!"
60
61 Maidens of your charity,
62 Pity my most luckless state.
63 Four times Cupid's debtor I--
64 Bankrupt in quadruplicate.
65
66 Yet, despite this evil case,
67 And a maiden showed me grace,
68 Four-and-forty times would I
69 Sing the Lovers' Litany:
70 "Love like ours can never die!"'''
71                 bio=Membio(poem)
72                 data=bio.read()
73                 self.assertEqual(data,poem)
74                 del bio
75         def test_readparts(self):
76                 s="A quick brown fox jumps over the lazy dog"
77                 bio=Membio(s)
78                 a=bio.read(10)
79                 self.assertEqual(a,s[0:10])
80                 b=bio.read(9)
81                 self.assertEqual(b,s[10:19])
82                 c=bio.read()
83                 self.assertEqual(c,s[19:])
84                 d=bio.read()
85                 self.assertEqual(d,"")
86
87 class TestWrite(unittest.TestCase):
88         def test_write(self):
89                 b=Membio()
90                 b.write("A quick brown ")
91                 b.write("fox jumps over ")
92                 b.write("the lazy dog.")
93                 self.assertEqual(str(b),"A quick brown fox jumps over the lazy dog.")
94
95         def test_unicode(self):
96                 b=Membio()
97                 s='\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'
98                 b.write(s)
99                 self.assertEqual(unicode(b),u'\u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438')
100         def test_unicode2(self):
101                 b=Membio()
102                 u=u'\u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e-\u0440\u0443\u0441\u0441\u043a\u0438'
103                 b.write(u)
104                 self.assertEqual(unicode(b),u)
105 if __name__ == '__main__':
106         unittest.main()