Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a44361cc
Commit
a44361cc
authored
Mar 30, 2000
by
Andrew M. Kuchling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added simple test case for mmap on Unix; someone needs to write a
Win32 test case
parent
2b789106
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
0 deletions
+69
-0
Lib/test/test_mmap.py
Lib/test/test_mmap.py
+69
-0
No files found.
Lib/test/test_mmap.py
0 → 100644
View file @
a44361cc
import
mmap
import
string
,
os
,
re
,
sys
PAGESIZE
=
mmap
.
PAGESIZE
def
test_unix
():
"Test mmap module on Unix systems"
# Create an mmap'ed file
f
=
open
(
'foo'
,
'w+'
)
# Write 2 pages worth of data to the file
f
.
write
(
'
\
0
'
*
PAGESIZE
)
f
.
write
(
'foo'
)
f
.
write
(
'
\
0
'
*
(
PAGESIZE
-
3
)
)
m
=
mmap
.
mmap
(
f
.
fileno
(),
2
*
PAGESIZE
)
f
.
close
()
# Simple sanity checks
print
' Position of foo:'
,
string
.
find
(
m
,
'foo'
)
/
float
(
PAGESIZE
),
'pages'
assert
string
.
find
(
m
,
'foo'
)
==
PAGESIZE
print
' Length of file:'
,
len
(
m
)
/
float
(
PAGESIZE
),
'pages'
assert
len
(
m
)
==
2
*
PAGESIZE
print
' Contents of byte 0:'
,
repr
(
m
[
0
])
assert
m
[
0
]
==
'
\
0
'
print
' Contents of first 3 bytes:'
,
repr
(
m
[
0
:
3
])
assert
m
[
0
:
3
]
==
'
\
0
\
0
\
0
'
# Modify the file's content
print
"
\
n
Modifying file's content..."
m
[
0
]
=
'3'
m
[
PAGESIZE
+
3
:
PAGESIZE
+
3
+
3
]
=
'bar'
# Check that the modification worked
print
' Contents of byte 0:'
,
repr
(
m
[
0
])
assert
m
[
0
]
==
'3'
print
' Contents of first 3 bytes:'
,
repr
(
m
[
0
:
3
])
assert
m
[
0
:
3
]
==
'3
\
0
\
0
'
print
' Contents of second page:'
,
m
[
PAGESIZE
-
1
:
PAGESIZE
+
7
]
assert
m
[
PAGESIZE
-
1
:
PAGESIZE
+
7
]
==
'
\
0
foobar
\
0
'
m
.
flush
()
# Test doing a regular expression match in an mmap'ed file
match
=
re
.
search
(
'[A-Za-z]+'
,
m
)
if
match
==
None
:
print
' ERROR: regex match on mmap failed!'
else
:
start
,
end
=
match
.
span
(
0
)
length
=
end
-
start
print
' Regex match on mmap (page start, length of match):'
,
print
start
/
float
(
PAGESIZE
),
length
assert
start
==
PAGESIZE
assert
end
==
PAGESIZE
+
6
print
' Test passed'
# XXX need to write a test suite for Windows
if
sys
.
platform
==
'win32'
:
pass
else
:
test_unix
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment