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