~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to pypy/module/mmap/test/test_mmap.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from pypy.conftest import gettestobjspace
 
2
from pypy.tool.udir import udir
 
3
import os
 
4
 
 
5
class AppTestMMap:
 
6
    def setup_class(cls):
 
7
        space = gettestobjspace(usemodules=('mmap',))
 
8
        cls.space = space
 
9
        cls.w_tmpname = space.wrap(str(udir.join('mmap-')))
 
10
    
 
11
    def test_page_size(self):
 
12
        import mmap
 
13
        assert mmap.PAGESIZE > 0
 
14
        assert isinstance(mmap.PAGESIZE, int)
 
15
        
 
16
    def test_attributes(self):
 
17
        import mmap
 
18
        import os
 
19
        assert isinstance(mmap.ACCESS_READ, int)
 
20
        assert isinstance(mmap.ACCESS_WRITE, int)
 
21
        assert isinstance(mmap.ACCESS_COPY, int)
 
22
        if os.name == "posix":
 
23
            assert isinstance(mmap.MAP_ANON, int)
 
24
            assert isinstance(mmap.MAP_ANONYMOUS, int)
 
25
            assert isinstance(mmap.MAP_PRIVATE, int)
 
26
            assert isinstance(mmap.MAP_SHARED, int)
 
27
            assert isinstance(mmap.PROT_EXEC, int)
 
28
            assert isinstance(mmap.PROT_READ, int)
 
29
            assert isinstance(mmap.PROT_WRITE, int)
 
30
        
 
31
        assert mmap.error is EnvironmentError
 
32
            
 
33
    def test_args(self):
 
34
        from mmap import mmap
 
35
        import os
 
36
        import sys
 
37
        
 
38
        raises(TypeError, mmap, "foo")
 
39
        raises(TypeError, mmap, 0, "foo")
 
40
             
 
41
        if os.name == "posix":
 
42
            raises(TypeError, mmap, 0, 1, 2, 3, 4, 5)
 
43
            raises(TypeError, mmap, 0, 1, 2, 3, "foo", 5)
 
44
            raises(TypeError, mmap, 0, 1, foo="foo")
 
45
            raises(TypeError, mmap, 0, -1)
 
46
            raises(OverflowError, mmap, 0, sys.maxint ** 3)
 
47
            raises(ValueError, mmap, 0, 1, flags=2, access=3)
 
48
            raises(ValueError, mmap, 0, 1, access=123)
 
49
        elif os.name == "nt":
 
50
            raises(TypeError, mmap, 0, 1, 2, 3, 4)
 
51
            raises(TypeError, mmap, 0, 1, tagname=123)
 
52
            raises(TypeError, mmap, 0, 1, access="foo")
 
53
            raises(ValueError, mmap, 0, 1, access=-1)
 
54
 
 
55
    def test_file_size(self):
 
56
        import os
 
57
        if os.name == "nt":
 
58
            skip("Only Unix checks file size")
 
59
 
 
60
        from mmap import mmap
 
61
        f = open(self.tmpname + "a", "w+")
 
62
        
 
63
        f.write("c")
 
64
        f.flush()
 
65
        raises(ValueError, mmap, f.fileno(), 123)
 
66
        f.close()
 
67
 
 
68
    def test_create(self):
 
69
        from mmap import mmap
 
70
        f = open(self.tmpname + "b", "w+")
 
71
        
 
72
        f.write("c")
 
73
        f.flush()
 
74
        m = mmap(f.fileno(), 1)
 
75
        assert m.read(99) == "c"
 
76
        
 
77
        f.close()
 
78
 
 
79
    def test_close(self):
 
80
        from mmap import mmap
 
81
        f = open(self.tmpname + "c", "w+")
 
82
        
 
83
        f.write("c")
 
84
        f.flush()
 
85
        m = mmap(f.fileno(), 1)
 
86
        m.close()
 
87
        raises(ValueError, m.read, 1)
 
88
 
 
89
    def test_read_byte(self):
 
90
        from mmap import mmap
 
91
        f = open(self.tmpname + "d", "w+")
 
92
 
 
93
        f.write("c")
 
94
        f.flush()
 
95
        m = mmap(f.fileno(), 1)
 
96
        assert m.read_byte() == "c"
 
97
        raises(ValueError, m.read_byte)
 
98
        m.close()
 
99
        f.close()
 
100
 
 
101
    def test_readline(self):
 
102
        from mmap import mmap
 
103
        import os
 
104
        f = open(self.tmpname + "e", "w+")
 
105
 
 
106
        f.write("foo\n")
 
107
        f.flush()
 
108
        m = mmap(f.fileno(), 4)
 
109
        if os.name == "nt":
 
110
            # windows replaces \n with \r. it's time to change to \n only MS!
 
111
            assert m.readline() == "foo\r"
 
112
        elif os.name == "posix":
 
113
            assert m.readline() == "foo\n"
 
114
        assert m.readline() == ""
 
115
        m.close()
 
116
        f.close()
 
117
 
 
118
    def test_read(self):
 
119
        from mmap import mmap
 
120
        f = open(self.tmpname + "f", "w+")
 
121
        
 
122
        f.write("foobar")
 
123
        f.flush()
 
124
        m = mmap(f.fileno(), 6)
 
125
        raises(TypeError, m.read, "foo")
 
126
        assert m.read(1) == "f"
 
127
        assert m.read(6) == "oobar"
 
128
        assert m.read(1) == ""
 
129
        m.close()
 
130
        f.close()
 
131
 
 
132
    def test_find(self):
 
133
        from mmap import mmap
 
134
        f = open(self.tmpname + "g", "w+")
 
135
 
 
136
        f.write("foobar\0")
 
137
        f.flush()
 
138
        m = mmap(f.fileno(), 7)
 
139
        raises(TypeError, m.find, 123)
 
140
        raises(TypeError, m.find, "foo", "baz")
 
141
        assert m.find("b") == 3
 
142
        assert m.find("z") == -1
 
143
        assert m.find("o", 5) == -1
 
144
        assert m.find("ob") == 2
 
145
        assert m.find("\0") == 6
 
146
        m.close()
 
147
        f.close()
 
148
 
 
149
    def test_is_modifiable(self):
 
150
        import mmap
 
151
        f = open(self.tmpname + "h", "w+")
 
152
        
 
153
        f.write("foobar")
 
154
        f.flush()
 
155
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_READ)
 
156
        raises(TypeError, m.write, 'x')
 
157
        raises(TypeError, m.resize, 7)
 
158
        m.close()
 
159
        f.close()
 
160
 
 
161
    def test_seek(self):
 
162
        from mmap import mmap
 
163
        f = open(self.tmpname + "i", "w+")
 
164
        
 
165
        f.write("foobar")
 
166
        f.flush()
 
167
        m = mmap(f.fileno(), 6)
 
168
        raises(TypeError, m.seek, "foo")
 
169
        raises(TypeError, m.seek, 0, "foo")
 
170
        raises(ValueError, m.seek, -1, 0)
 
171
        raises(ValueError, m.seek, -1, 1)
 
172
        raises(ValueError, m.seek, -7, 2)
 
173
        raises(ValueError, m.seek, 1, 3)
 
174
        raises(ValueError, m.seek, 10)
 
175
        m.seek(0)
 
176
        assert m.tell() == 0
 
177
        m.read(1)
 
178
        m.seek(1, 1)
 
179
        assert m.tell() == 2
 
180
        m.seek(0)
 
181
        m.seek(-1, 2)
 
182
        assert m.tell() == 5
 
183
        m.close()
 
184
        f.close()
 
185
 
 
186
    def test_write(self):
 
187
        import mmap
 
188
        f = open(self.tmpname + "j", "w+")
 
189
 
 
190
        f.write("foobar")
 
191
        f.flush()
 
192
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_READ)
 
193
        raises(TypeError, m.write, "foo")
 
194
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_WRITE)
 
195
        raises(TypeError, m.write, 123)
 
196
        raises(ValueError, m.write, "c"*10)
 
197
        m.write("ciao\n")
 
198
        m.seek(0)
 
199
        assert m.read(6) == "ciao\nr"
 
200
        m.close()
 
201
 
 
202
    def test_write_byte(self):
 
203
        import mmap
 
204
        f = open(self.tmpname + "k", "w+")
 
205
        
 
206
        f.write("foobar")
 
207
        f.flush()
 
208
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_READ)
 
209
        raises(TypeError, m.write_byte, "f")
 
210
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_WRITE)
 
211
        raises(TypeError, m.write_byte, 123)
 
212
        raises(TypeError, m.write_byte, "ab")
 
213
        m.write_byte("x")
 
214
        m.seek(0)
 
215
        assert m.read(6) == "xoobar"
 
216
        m.close()
 
217
 
 
218
    def test_size(self):
 
219
        from mmap import mmap
 
220
        f = open(self.tmpname + "l", "w+")
 
221
        
 
222
        f.write("foobar")
 
223
        f.flush()
 
224
        m = mmap(f.fileno(), 5)
 
225
        assert m.size() == 6 # size of the underline file, not the mmap
 
226
        m.close()
 
227
        f.close()
 
228
 
 
229
    def test_tell(self):
 
230
        from mmap import mmap
 
231
        f = open(self.tmpname + "m", "w+")
 
232
        
 
233
        f.write("c")
 
234
        f.flush()
 
235
        m = mmap(f.fileno(), 1)
 
236
        assert m.tell() >= 0
 
237
        m.close()
 
238
        f.close()
 
239
 
 
240
    def test_flush(self):
 
241
        from mmap import mmap
 
242
        f = open(self.tmpname + "n", "w+")
 
243
        
 
244
        f.write("foobar")
 
245
        f.flush()
 
246
        m = mmap(f.fileno(), 6)
 
247
        raises(TypeError, m.flush, 1, 2, 3)
 
248
        raises(TypeError, m.flush, 1, "a")
 
249
        raises(ValueError, m.flush, 0, 99)
 
250
        m.flush()    # return value is a bit meaningless, platform-dependent
 
251
        m.close()
 
252
        f.close()
 
253
 
 
254
    def test_move(self):
 
255
        import mmap
 
256
        f = open(self.tmpname + "o", "w+")
 
257
        
 
258
        f.write("foobar")
 
259
        f.flush()
 
260
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_READ)
 
261
        raises(TypeError, m.move, 1)
 
262
        raises(TypeError, m.move, 1, "foo", 2)
 
263
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_WRITE)
 
264
        raises(ValueError, m.move, 7, 1, 2)
 
265
        raises(ValueError, m.move, 1, 7, 2)
 
266
        m.move(1, 3, 3)
 
267
        assert m.read(6) == "fbarar"
 
268
        m.seek(0)
 
269
        m.move(1, 3, 2)
 
270
        a = m.read(6)
 
271
        assert a == "frarar"
 
272
        m.close()
 
273
        f.close()
 
274
    
 
275
    def test_resize(self):
 
276
        import sys
 
277
        if ("darwin" in sys.platform) or ("freebsd" in sys.platform):
 
278
            skip("resize does not work under OSX or FreeBSD")
 
279
        
 
280
        import mmap
 
281
        import os
 
282
        
 
283
        f = open(self.tmpname + "p", "w+")
 
284
        f.write("foobar")
 
285
        f.flush()
 
286
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_READ)
 
287
        raises(TypeError, m.resize, 1)
 
288
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_COPY)
 
289
        raises(TypeError, m.resize, 1)
 
290
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_WRITE)
 
291
        f_size = os.fstat(f.fileno()).st_size
 
292
        assert m.size() == f_size == 6
 
293
        m.resize(10)
 
294
        f_size = os.fstat(f.fileno()).st_size
 
295
        assert m.size() == f_size == 10
 
296
        m.close()
 
297
        f.close()
 
298
 
 
299
    def test_len(self):
 
300
        from mmap import mmap
 
301
        
 
302
        f = open(self.tmpname + "q", "w+")
 
303
        f.write("foobar")
 
304
        f.flush()
 
305
 
 
306
        m = mmap(f.fileno(), 6)
 
307
        assert len(m) == 6
 
308
        m.close()
 
309
        f.close()
 
310
     
 
311
    def test_get_item(self):
 
312
        from mmap import mmap
 
313
        
 
314
        f = open(self.tmpname + "r", "w+")
 
315
        f.write("foobar")
 
316
        f.flush()
 
317
        
 
318
        m = mmap(f.fileno(), 6)
 
319
        fn = lambda: m["foo"]
 
320
        raises(TypeError, fn)
 
321
        fn = lambda: m[-7]
 
322
        raises(IndexError, fn)
 
323
        assert m[0] == 'f'
 
324
        assert m[-1] == 'r'
 
325
        # sl = slice(1, 2)
 
326
        # assert m.get_item(sl) == 'o'
 
327
        m.close()
 
328
        f.close()
 
329
    
 
330
    def test_set_item(self):
 
331
        import mmap
 
332
        
 
333
        f = open(self.tmpname + "s", "w+")
 
334
        f.write("foobar")
 
335
        f.flush()
 
336
 
 
337
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_READ)
 
338
        def fn(): m[1] = 'a'
 
339
        raises(TypeError, fn)
 
340
        m = mmap.mmap(f.fileno(), 6, access=mmap.ACCESS_WRITE)
 
341
        def fn(): m["foo"] = 'a'
 
342
        raises(TypeError, fn)
 
343
        def fn(): m[-7] = 'a'
 
344
        raises(IndexError, fn)
 
345
        def fn(): m[0] = 'ab'
 
346
        raises((IndexError, ValueError), fn)     # IndexError is in CPython,
 
347
                                                 # but doesn't make much sense
 
348
        # def f(m): m[1:3] = u'xx'
 
349
        # py.test.raises(IndexError, f, m)
 
350
        # def f(m): m[1:4] = "zz"
 
351
        # py.test.raises(IndexError, f, m)
 
352
        # def f(m): m[1:6] = "z" * 6
 
353
        # py.test.raises(IndexError, f, m)
 
354
        # def f(m): m[:2] = "z" * 5
 
355
        # m[1:3] = 'xx'
 
356
        # assert m.read(6) == "fxxbar"
 
357
        # m.seek(0)
 
358
        m[0] = 'x'
 
359
        assert m[0] == 'x'
 
360
        m[-6] = 'y'
 
361
        data = m.read(6)
 
362
        assert data == "yoobar" # yxxbar with slice's stuff
 
363
        m.close()
 
364
        f.close()
 
365
    
 
366
    def test_del_item(self):
 
367
        from mmap import mmap
 
368
        
 
369
        f = open(self.tmpname + "t", "w+")
 
370
        f.write("foobar")
 
371
        f.flush()
 
372
        
 
373
        m = mmap(f.fileno(), 6)
 
374
        def fn(): del m["foo"]
 
375
        raises(TypeError, fn)
 
376
        # def f(m): del m[1:3]
 
377
        # py.test.raises(TypeError, f, m)
 
378
        def fn(): del m[1]
 
379
        raises(TypeError, fn)
 
380
        m.close()
 
381
        f.close()
 
382
 
 
383
    def test_concatenation(self):
 
384
        from mmap import mmap
 
385
        
 
386
        f = open(self.tmpname + "u", "w+")
 
387
        f.write("foobar")
 
388
        f.flush()
 
389
        
 
390
        m = mmap(f.fileno(), 6)
 
391
        def fn(): m + 1
 
392
        raises((SystemError, TypeError), fn)     # SystemError is in CPython,
 
393
        def fn(m): m += 1                        # but it doesn't make much
 
394
        raises((SystemError, TypeError), fn, m)  # sense
 
395
        def fn(): 1 + m
 
396
        raises(TypeError, fn)
 
397
        m.close()
 
398
        f.close()
 
399
 
 
400
    def test_repeatition(self):
 
401
        from mmap import mmap
 
402
        
 
403
        f = open(self.tmpname + "v", "w+")
 
404
        f.write("foobar")
 
405
        f.flush()
 
406
        
 
407
        m = mmap(f.fileno(), 6)
 
408
        def fn(): m * 1
 
409
        raises((SystemError, TypeError), fn)      # SystemError is in CPython,
 
410
        def fn(m): m *= 1                         # but it
 
411
        raises((SystemError, TypeError), fn, m)   # doesn't
 
412
        def fn(): 1 * m                           # make much sense
 
413
        raises(TypeError, fn)
 
414
        m.close()
 
415
        f.close()
 
416
#         
 
417
#     def test_slicing(self):
 
418
#         self.f.seek(0)
 
419
#         m = mmap(self.f.fileno(), 6)
 
420
#         assert m[-3:7] == "bar"
 
421
 
422
 
 
423
    def test_sequence_type(self):
 
424
        from mmap import mmap
 
425
        f = open(self.tmpname + "x", "w+")
 
426
        f.write("foobar")
 
427
        f.flush()
 
428
        m = mmap(f.fileno(), 6)
 
429
        import operator
 
430
        assert operator.isSequenceType(m)
 
431
        assert not operator.isMappingType(m)
 
432
 
 
433
    def test_all(self):
 
434
        # this is a global test, ported from test_mmap.py
 
435
        import mmap
 
436
        from mmap import PAGESIZE
 
437
        import sys
 
438
        import os
 
439
        
 
440
        filename = self.tmpname + "w"
 
441
    
 
442
        f = open(filename, "w+")
 
443
    
 
444
        # write 2 pages worth of data to the file
 
445
        f.write('\0' * PAGESIZE)
 
446
        f.write('foo')
 
447
        f.write('\0' * (PAGESIZE - 3))
 
448
        f.flush()
 
449
        m = mmap.mmap(f.fileno(), 2 * PAGESIZE)
 
450
        f.close()
 
451
    
 
452
        # sanity checks
 
453
        assert m.find("foo") == PAGESIZE
 
454
        assert len(m) == 2 * PAGESIZE
 
455
        assert m[0] == '\0'
 
456
        # assert m[0:3] == '\0\0\0'
 
457
    
 
458
        # modify the file's content
 
459
        m[0] = '3'
 
460
        # m[PAGESIZE+3:PAGESIZE+3+3] = 'bar'
 
461
    
 
462
        # check that the modification worked
 
463
        assert m[0] == '3'
 
464
        # assert m[0:3] == '3\0\0'
 
465
        # assert m[PAGESIZE-1:PAGESIZE+7] == '\0foobar\0'
 
466
 
 
467
        m.flush()
 
468
    
 
469
        # test seeking around
 
470
        m.seek(0,0)
 
471
        assert m.tell() == 0
 
472
        m.seek(42, 1)
 
473
        assert m.tell() == 42
 
474
        m.seek(0, 2)
 
475
        assert m.tell() == len(m)
 
476
        
 
477
        raises(ValueError, m.seek, -1)
 
478
        raises(ValueError, m.seek, 1, 2)
 
479
        raises(ValueError, m.seek, -len(m) - 1, 2)
 
480
        
 
481
        # try resizing map
 
482
        if not (("darwin" in sys.platform) or ("freebsd" in sys.platform)):
 
483
            m.resize(512)
 
484
        
 
485
            assert len(m) == 512
 
486
            raises(ValueError, m.seek, 513, 0)
 
487
            
 
488
            # check that the underlying file is truncated too
 
489
            f = open(filename)
 
490
            f.seek(0, 2)
 
491
            assert f.tell() == 512
 
492
            f.close()
 
493
            assert m.size() == 512
 
494
        
 
495
        m.close()
 
496
        f.close()
 
497
        
 
498
        # test access=ACCESS_READ
 
499
        mapsize = 10
 
500
        f = open(filename, "wb")
 
501
        f.write("a" * mapsize)
 
502
        f.close()
 
503
        f = open(filename, "rb")
 
504
        m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_READ)
 
505
        # assert m[:] == 'a' * mapsize
 
506
        # def f(m): m[:] = 'b' * mapsize
 
507
        # py.test.raises(TypeError, f, m)
 
508
        def fn(): m[0] = 'b'
 
509
        raises(TypeError, fn)
 
510
        def fn(m): m.seek(0, 0); m.write("abc")
 
511
        raises(TypeError, fn, m)
 
512
        def fn(m): m.seek(0, 0); m.write_byte("d")
 
513
        raises(TypeError, fn, m)
 
514
        if not (("darwin" in sys.platform) or ("freebsd" in sys.platform)):
 
515
            raises(TypeError, m.resize, 2 * mapsize)
 
516
            assert open(filename, "rb").read() == 'a' * mapsize
 
517
        
 
518
        # opening with size too big
 
519
        f = open(filename, "r+b")
 
520
        if not os.name == "nt":
 
521
            # this should work under windows
 
522
            raises(ValueError, mmap.mmap, f.fileno(), mapsize + 1)
 
523
        f.close()
 
524
        
 
525
        # if _MS_WINDOWS:
 
526
        #     # repair damage from the resizing test.
 
527
        #     f = open(filename, 'r+b')
 
528
        #     f.truncate(mapsize)
 
529
        #     f.close()
 
530
        m.close()
 
531
        
 
532
        # test access=ACCESS_WRITE"
 
533
        f = open(filename, "r+b")
 
534
        m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_WRITE)
 
535
        m.write('c' * mapsize)
 
536
        m.seek(0)
 
537
        data = m.read(mapsize)
 
538
        assert data == 'c' * mapsize
 
539
        m.flush()
 
540
        m.close()
 
541
        f.close()
 
542
        f = open(filename, 'rb')
 
543
        stuff = f.read()
 
544
        f.close()
 
545
        assert stuff == 'c' * mapsize
 
546
        
 
547
        # test access=ACCESS_COPY
 
548
        f = open(filename, "r+b")
 
549
        m = mmap.mmap(f.fileno(), mapsize, access=mmap.ACCESS_COPY)
 
550
        m.write('d' * mapsize)
 
551
        m.seek(0)
 
552
        data = m.read(mapsize)
 
553
        assert data == 'd' * mapsize
 
554
        m.flush()
 
555
        assert open(filename, "rb").read() == 'c' * mapsize
 
556
        if not (("darwin" in sys.platform) or ("freebsd" in sys.platform)):
 
557
            raises(TypeError, m.resize, 2 * mapsize)
 
558
        m.close()
 
559
        f.close()
 
560
        
 
561
        # test invalid access
 
562
        f = open(filename, "r+b")
 
563
        raises(ValueError, mmap.mmap, f.fileno(), mapsize, access=4)
 
564
        f.close()
 
565
        
 
566
        # test incompatible parameters
 
567
        if os.name == "posix":
 
568
            f = open(filename, "r+b")
 
569
            raises(ValueError, mmap.mmap, f.fileno(), mapsize, flags=mmap.MAP_PRIVATE,
 
570
                prot=mmap.PROT_READ, access=mmap.ACCESS_WRITE)
 
571
            f.close()
 
572
 
 
573
        
 
574
        # bad file descriptor
 
575
        raises(EnvironmentError, mmap.mmap, -2, 4096)
 
576
        
 
577
        # do a tougher .find() test.  SF bug 515943 pointed out that, in 2.2,
 
578
        # searching for data with embedded \0 bytes didn't work.
 
579
        f = open(filename, 'w+')
 
580
        data = 'aabaac\x00deef\x00\x00aa\x00'
 
581
        n = len(data)
 
582
        f.write(data)
 
583
        f.flush()
 
584
        m = mmap.mmap(f.fileno(), n)
 
585
        f.close()
 
586
        
 
587
        for start in range(n + 1):
 
588
            for finish in range(start, n + 1):
 
589
                sl = data[start:finish]
 
590
                assert m.find(sl) == data.find(sl)
 
591
                assert m.find(sl + 'x') ==  -1
 
592
        m.close()
 
593
        
 
594
        # test mapping of entire file by passing 0 for map length
 
595
        f = open(filename, "w+")
 
596
        f.write(2**16 * 'm')
 
597
        f.close()
 
598
        f = open(filename, "rb+")
 
599
        m = mmap.mmap(f.fileno(), 0)
 
600
        assert len(m) == 2**16
 
601
        assert m.read(2**16) == 2**16 * "m"
 
602
        m.close()
 
603
        f.close()
 
604
        
 
605
        # make move works everywhere (64-bit format problem earlier)
 
606
        f = open(filename, 'w+')
 
607
        f.write("ABCDEabcde")
 
608
        f.flush()
 
609
        m = mmap.mmap(f.fileno(), 10)
 
610
        m.move(5, 0, 5)
 
611
        assert m.read(10) == "ABCDEABCDE"
 
612
        m.close()
 
613
        f.close()