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