Fred Drake | 2ec80fa | 2000-10-23 16:59:35 +0000 | [diff] [blame] | 1 | import os |
| 2 | |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame] | 3 | from test_support import verify, TESTFN |
Marc-André Lemburg | fa44d79 | 2000-08-25 22:37:31 +0000 | [diff] [blame] | 4 | from UserList import UserList |
| 5 | |
| 6 | # verify writelines with instance sequence |
| 7 | l = UserList(['1', '2']) |
| 8 | f = open(TESTFN, 'wb') |
| 9 | f.writelines(l) |
| 10 | f.close() |
| 11 | f = open(TESTFN, 'rb') |
| 12 | buf = f.read() |
| 13 | f.close() |
Marc-André Lemburg | 3661908 | 2001-01-17 19:11:13 +0000 | [diff] [blame] | 14 | verify(buf == '12') |
Marc-André Lemburg | fa44d79 | 2000-08-25 22:37:31 +0000 | [diff] [blame] | 15 | |
| 16 | # verify writelines with integers |
| 17 | f = open(TESTFN, 'wb') |
| 18 | try: |
| 19 | f.writelines([1, 2, 3]) |
| 20 | except TypeError: |
| 21 | pass |
| 22 | else: |
| 23 | print "writelines accepted sequence of integers" |
| 24 | f.close() |
| 25 | |
| 26 | # verify writelines with integers in UserList |
| 27 | f = open(TESTFN, 'wb') |
| 28 | l = UserList([1,2,3]) |
| 29 | try: |
| 30 | f.writelines(l) |
| 31 | except TypeError: |
| 32 | pass |
| 33 | else: |
| 34 | print "writelines accepted sequence of integers" |
| 35 | f.close() |
| 36 | |
| 37 | # verify writelines with non-string object |
| 38 | class NonString: pass |
| 39 | |
| 40 | f = open(TESTFN, 'wb') |
| 41 | try: |
| 42 | f.writelines([NonString(), NonString()]) |
| 43 | except TypeError: |
| 44 | pass |
| 45 | else: |
| 46 | print "writelines accepted sequence of non-string objects" |
| 47 | f.close() |
Fred Drake | 2ec80fa | 2000-10-23 16:59:35 +0000 | [diff] [blame] | 48 | |
| 49 | os.unlink(TESTFN) |